Skip to content

Commit 51933bc

Browse files
committed
cfg refactor wip 2
1 parent d5628f7 commit 51933bc

File tree

8 files changed

+1114
-836
lines changed

8 files changed

+1114
-836
lines changed

Autoload/Things.gd

+397-746
Large diffs are not rendered by default.

Scenes/CustomObjectSystem.gd

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func load_file():
3232

3333
var constructArray = [
3434
objName, # NAME
35-
null, # KEEPERFX_NAME
3635
null, # ANIMATION_ID
3736
null, # TEXTURE
3837
null, # PORTRAIT

Scenes/FxData.gd

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
extends Node
2+
onready var oGame = Nodelist.list["oGame"]
3+
4+
# These are dictionaries containing dictionaries.
5+
# objects_cfg["section_name"]["key"] will return the "value"
6+
# If there's a space in the value string, then the value will be an array of strings or integers.
7+
8+
var terrain_cfg : Dictionary
9+
var objects_cfg : Dictionary
10+
var creature_cfg : Dictionary
11+
var trapdoor_cfg : Dictionary
12+
13+
14+
#func _ready():
15+
# var directory = Directory.new()
16+
# var image_directory = "res://Art/"
17+
#
18+
# if directory.open(image_directory) == OK:
19+
# directory.list_dir_begin()
20+
# var file_name = directory.get_next()
21+
# while file_name != "":
22+
# if file_name.get_extension().to_lower() in ["png", "jpg", "jpeg", "webp"]:
23+
# var image_path = image_directory + file_name
24+
# print("Loaded image: ", image_path)
25+
#
26+
# file_name = directory.get_next()
27+
# else:
28+
# print("Failed to open the directory.")
29+
30+
# var newName
31+
# var checkName = objects_cfg[section]["Name"]
32+
# if Things.convert_name.has(checkName):
33+
# newName = Things.convert_name[checkName]
34+
# else:
35+
# newName = checkName.capitalize()
36+
37+
func start():
38+
if Cube.tex.empty() == true:
39+
Cube.read_cubes_cfg()
40+
var CODETIME_START = OS.get_ticks_msec()
41+
terrain_cfg = read_dkcfg_file(oGame.DK_FXDATA_DIRECTORY.plus_file("terrain.cfg"))
42+
objects_cfg = read_dkcfg_file(oGame.DK_FXDATA_DIRECTORY.plus_file("objects.cfg"))
43+
creature_cfg = read_dkcfg_file(oGame.DK_FXDATA_DIRECTORY.plus_file("creature.cfg"))
44+
trapdoor_cfg = read_dkcfg_file(oGame.DK_FXDATA_DIRECTORY.plus_file("trapdoor.cfg"))
45+
print('Parsed all dkcfg files: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms')
46+
var CODETIME_LOADCFG_START = OS.get_ticks_msec()
47+
48+
for key in objects_cfg.keys():
49+
if "object" in key:
50+
print(key)
51+
print(objects_cfg[key]["Name"])
52+
if Things.DATA_OBJECT.has(int(key)):
53+
print(Things.DATA_OBJECT[int(key)][Things.NAME])
54+
55+
var id = 0
56+
while true:
57+
id += 1
58+
if id >= 136 or id in [100,101,102,103,104,105]: # Dummy Boxes should be overwritten
59+
var section = "object"+str(id)
60+
if objects_cfg.has(section):
61+
var newName = objects_cfg[section]["Name"]
62+
var newGenre = objects_cfg[section]["Genre"]
63+
var newEditorTab = Things.GENRE_TO_TAB[newGenre]
64+
65+
var newTexture = null
66+
match newGenre:
67+
"SPECIALBOX": newTexture = preload("res://dk_images/trapdoor_64/bonus_box_std.png")
68+
"SPELLBOOK": newTexture = preload("res://edited_images/icon_book.png")
69+
"WORKSHOPBOX": newTexture = preload("res://dk_images/traps_doors/anim0116/AnimBox.tres")
70+
71+
Things.DATA_OBJECT[id] = [
72+
newName, # NAME
73+
null, # ANIMATION_ID
74+
newTexture, # TEXTURE
75+
null, # PORTRAIT
76+
newEditorTab, # EDITOR_TAB
77+
]
78+
else:
79+
break
80+
print('Loaded objects.cfg: ' + str(OS.get_ticks_msec() - CODETIME_LOADCFG_START) + 'ms')
81+
82+
func read_dkcfg_file(file_path) -> Dictionary: # Optimized
83+
var config = {}
84+
var current_section = ""
85+
86+
var file = File.new()
87+
if not file.file_exists(file_path):
88+
print("File not found: ", file_path)
89+
return config
90+
91+
file.open(file_path, File.READ)
92+
var lines = file.get_as_text().split("\n")
93+
file.close()
94+
95+
for line in lines:
96+
line = line.strip_edges()
97+
if line.begins_with(";") or line.empty():
98+
continue
99+
100+
if line.begins_with("[") and line.ends_with("]"):
101+
current_section = line.substr(1, line.length() - 2)
102+
config[current_section] = {}
103+
else:
104+
var delimiter_pos = line.find("=")
105+
if delimiter_pos != -1:
106+
var key = line.substr(0, delimiter_pos).strip_edges()
107+
var value = line.substr(delimiter_pos + 1).strip_edges()
108+
109+
if " " in value:
110+
var construct_new_value_array = []
111+
for item in value.split(" "):
112+
if item.is_valid_integer():
113+
construct_new_value_array.append(int(item))
114+
else:
115+
construct_new_value_array.append(item)
116+
config[current_section][key] = construct_new_value_array
117+
else:
118+
if value.is_valid_integer():
119+
config[current_section][key] = int(value)
120+
else:
121+
config[current_section][key] = value
122+
123+
return config

Scenes/FxDataCache.gd

-64
This file was deleted.

Scenes/Main.tscn

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=190 format=2]
1+
[gd_scene load_steps=191 format=2]
22

33
[ext_resource path="res://Scenes/SlabStyle.gd" type="Script" id=1]
44
[ext_resource path="res://Scenes/SlabPlacement.gd" type="Script" id=2]
@@ -168,7 +168,8 @@
168168
[ext_resource path="res://Scenes/UndoStates.gd" type="Script" id=166]
169169
[ext_resource path="res://Scenes/ThreadedSaveUndo.gd" type="Script" id=167]
170170
[ext_resource path="res://Scenes/Guidelines.gd" type="Script" id=168]
171-
[ext_resource path="res://Scenes/FxDataCache.gd" type="Script" id=169]
171+
[ext_resource path="res://Scenes/FxData.gd" type="Script" id=169]
172+
[ext_resource path="res://Scenes/OldCfgCode.gd" type="Script" id=170]
172173

173174
[sub_resource type="CubeMesh" id=2]
174175
size = Vector3( 1, 1, 1 )
@@ -333,9 +334,12 @@ script = ExtResource( 37 )
333334
[node name="Game" type="Node" parent="."]
334335
script = ExtResource( 30 )
335336
336-
[node name="FxDataCache" type="Node" parent="."]
337+
[node name="FxData" type="Node" parent="."]
337338
script = ExtResource( 169 )
338339
340+
[node name="OLD_UNUSED_CfgCode" type="Node" parent="FxData"]
341+
script = ExtResource( 170 )
342+
339343
[node name="TextureCache" type="Node" parent="."]
340344
script = ExtResource( 46 )
341345

0 commit comments

Comments
 (0)