Skip to content

Commit 1455093

Browse files
committed
cfg refactor wip 11
1 parent 99897e6 commit 1455093

File tree

4 files changed

+69
-82
lines changed

4 files changed

+69
-82
lines changed

Autoload/Things.gd

+17-17
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func _init():
3838
default_data["DATA_EFFECTGEN"] = DATA_EFFECTGEN.duplicate(true)
3939
default_data["DATA_CREATURE"] = DATA_CREATURE.duplicate(true)
4040
default_data["DATA_OBJECT"] = DATA_OBJECT.duplicate(true)
41+
default_data["LIST_OF_BOXES"] = LIST_OF_BOXES.duplicate(true)
4142

4243
func reset_thing_data_to_default(): # Reset data. Takes 1ms.
4344
DATA_EXTRA = default_data["DATA_EXTRA"].duplicate(true)
@@ -46,6 +47,7 @@ func reset_thing_data_to_default(): # Reset data. Takes 1ms.
4647
DATA_EFFECTGEN = default_data["DATA_EFFECTGEN"].duplicate(true)
4748
DATA_CREATURE = default_data["DATA_CREATURE"].duplicate(true)
4849
DATA_OBJECT = default_data["DATA_OBJECT"].duplicate(true)
50+
LIST_OF_BOXES = default_data["LIST_OF_BOXES"].duplicate(true)
4951

5052
func fetch_sprite(thing_type, sub_type):
5153
var sub_type_data = data_structure(thing_type).get(sub_type)
@@ -76,7 +78,11 @@ func fetch_name(thing_type, sub_type):
7678
var sub_type_data = data_structure.get(sub_type)
7779
if sub_type_data:
7880
var nameId = sub_type_data[NAME_ID]
79-
return dictionary_of_names.get(nameId, nameId.capitalize())
81+
if nameId is String:
82+
return dictionary_of_names.get(nameId, nameId.capitalize())
83+
elif nameId is Array: # This is to take into considersation someone accidentally using two words with spaces as an object name. (otherwise we get a crash)
84+
return dictionary_of_names.get(nameId[0], nameId[0].capitalize())
85+
return "Error1337"
8086
else:
8187
return "Unknown " + data_structure_name[thing_type] + " Subtype: " + str(sub_type)
8288
else:
@@ -165,22 +171,16 @@ func data_structure(thingType):
165171

166172

167173
var LIST_OF_BOXES = {
168-
094 : [TYPE.TRAP, 1], # Boulder Trap
169-
095 : [TYPE.TRAP, 2], # Alarm Trap
170-
096 : [TYPE.TRAP, 3], # Poison Gas Trap
171-
097 : [TYPE.TRAP, 4], # Lightning Trap
172-
098 : [TYPE.TRAP, 5], # Word of Power Trap
173-
099 : [TYPE.TRAP, 6], # Lava Trap
174-
100 : [TYPE.TRAP, 7], # Dummy Trap 2
175-
101 : [TYPE.TRAP, 8], # Dummy Trap 3
176-
102 : [TYPE.TRAP, 9], # Dummy Trap 4
177-
103 : [TYPE.TRAP, 10], # Dummy Trap 5
178-
104 : [TYPE.TRAP, 11], # Dummy Trap 6
179-
105 : [TYPE.TRAP, 12], # Dummy Trap 7
180-
106 : [TYPE.DOOR, 1], # Wooden Door
181-
107 : [TYPE.DOOR, 2], # Braced Door
182-
108 : [TYPE.DOOR, 3], # Iron Door
183-
109 : [TYPE.DOOR, 4], # Magic Door
174+
"WRKBOX_BOULDER" : [TYPE.TRAP, 1],
175+
"WRKBOX_ALARM" : [TYPE.TRAP, 2],
176+
"WRKBOX_POISONG" : [TYPE.TRAP, 3],
177+
"WRKBOX_LIGHTNG" : [TYPE.TRAP, 4],
178+
"WRKBOX_WRDOFPW" : [TYPE.TRAP, 5],
179+
"WRKBOX_LAVA" : [TYPE.TRAP, 6],
180+
"WRKBOX_WOOD" : [TYPE.DOOR, 1],
181+
"WRKBOX_BRACE" : [TYPE.DOOR, 2],
182+
"WRKBOX_STEEL" : [TYPE.DOOR, 3],
183+
"WRKBOX_MAGIC" : [TYPE.DOOR, 4],
184184
}
185185

186186

Scenes/CfgLoader.gd

+18-25
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ enum {
1919
LOAD_CFG_CAMPAIGN,
2020
LOAD_CFG_CURRENT_MAP,
2121
}
22+
2223
func start(mapPath):
23-
if Cube.tex.empty() == true:
24+
if Cube.tex.empty():
2425
Cube.read_cubes_cfg()
2526

2627
var CODETIME_LOADCFG_START = OS.get_ticks_msec()
@@ -29,30 +30,24 @@ func start(mapPath):
2930
var campaign_cfg = load_campaign_data(mapPath)
3031

3132
var config_dirs = {
32-
LOAD_CFG_FXDATA : oGame.DK_FXDATA_DIRECTORY,
33-
LOAD_CFG_CAMPAIGN : oGame.GAME_DIRECTORY.plus_file(campaign_cfg.get("common", {}).get("CONFIGS_LOCATION", "")),
34-
LOAD_CFG_CURRENT_MAP : "" # Add the directory for LOAD_CFG_CURRENT_MAP if needed
33+
LOAD_CFG_FXDATA: oGame.DK_FXDATA_DIRECTORY,
34+
LOAD_CFG_CAMPAIGN: oGame.GAME_DIRECTORY.plus_file(campaign_cfg.get("common", {}).get("CONFIGS_LOCATION", "")),
35+
LOAD_CFG_CURRENT_MAP: mapPath.get_basename()
3536
}
36-
37-
# Load data from each directory in the specified order
38-
for i in [LOAD_CFG_FXDATA, LOAD_CFG_CAMPAIGN, LOAD_CFG_CURRENT_MAP]:
39-
var cfg_dir = config_dirs[i]
40-
if cfg_dir == "": continue
41-
42-
match i:
43-
LOAD_CFG_FXDATA: oMessage.quick("Step 1: Data loaded from /fxdata/")
44-
LOAD_CFG_CAMPAIGN: oMessage.quick("Step 2: Data loaded from campaign configs directory")
45-
LOAD_CFG_CURRENT_MAP: oMessage.quick("Step 3?")
46-
47-
load_objects_data(cfg_dir.plus_file("objects.cfg"))
48-
load_creatures_data(cfg_dir.plus_file("creature.cfg"))
49-
load_trapdoor_data(cfg_dir.plus_file("trapdoor.cfg"))
50-
load_terrain_data(cfg_dir.plus_file("terrain.cfg"))
37+
for cfg_type in [LOAD_CFG_FXDATA, LOAD_CFG_CAMPAIGN, LOAD_CFG_CURRENT_MAP]:
38+
var cfg_dir = config_dirs[cfg_type]
39+
for file_name in ["objects.cfg", "creature.cfg", "trapdoor.cfg", "terrain.cfg"]:
40+
var file_path = cfg_dir.plus_file(file_name)
41+
if cfg_type == LOAD_CFG_CURRENT_MAP:
42+
file_path = cfg_dir + "." + file_name
43+
match file_name:
44+
"objects.cfg": load_objects_data(file_path)
45+
"creature.cfg": load_creatures_data(file_path)
46+
"trapdoor.cfg": load_trapdoor_data(file_path)
47+
"terrain.cfg": load_terrain_data(file_path)
5148

5249
print('Loaded things from cfg files: ' + str(OS.get_ticks_msec() - CODETIME_LOADCFG_START) + 'ms')
5350

54-
55-
5651
func load_objects_data(path):
5752
var objects_cfg = Utils.read_dkcfg_file(path)
5853
for section in objects_cfg:
@@ -84,6 +79,7 @@ func load_trapdoor_data(path):
8479
var trapdoor_cfg = Utils.read_dkcfg_file(path)
8580
for section in trapdoor_cfg:
8681
var id = int(section)
82+
if id == 0: continue
8783
var trapOrDoor = -1
8884
if section.begins_with("door"):
8985
trapOrDoor = Things.TYPE.DOOR
@@ -101,10 +97,7 @@ func load_trapdoor_data(path):
10197
Things.DATA_DOOR[id] = [newName, newSprite, Things.TAB_MISC]
10298
elif trapOrDoor == Things.TYPE.TRAP:
10399
Things.DATA_TRAP[id] = [newName, newSprite, Things.TAB_TRAP]
104-
105-
var crate_id_number = Things.find_subtype_by_name(Things.TYPE.OBJECT, crateName)
106-
Things.LIST_OF_BOXES[crate_id_number] = [trapOrDoor, id]
107-
100+
Things.LIST_OF_BOXES[crateName] = [trapOrDoor, id]
108101

109102
func load_terrain_data(path):
110103
var terrain_cfg = Utils.read_dkcfg_file(path)

Scenes/PickThingWindow.gd

+32-38
Original file line numberDiff line numberDiff line change
@@ -197,47 +197,41 @@ func add_item_to_grid(tabID, id, set_text):
197197
id.connect("pressed",self,"pressed",[id])
198198
id.rect_min_size = Vector2(grid_item_size.x * grid_window_scale, grid_item_size.y * grid_window_scale)
199199

200-
#yield(get_tree(),'idle_frame')
201200
if is_instance_valid(id) == true:
202-
var subtype = id.get_meta("thingSubtype")
203-
if Things.LIST_OF_BOXES.has(subtype):
204-
add_workshop_item_sprite_overlay(id, subtype)
201+
add_workshop_item_sprite_overlay(id, id.get_meta("thingSubtype"))
205202

206203
func add_workshop_item_sprite_overlay(textureParent, subtype):
207-
var itemType = Things.LIST_OF_BOXES[subtype][0]
208-
var itemSubtype = Things.LIST_OF_BOXES[subtype][1]
209-
210-
var workshopItemInTheBox = TextureRect.new()
211-
212-
match itemType:
213-
Things.TYPE.TRAP: workshopItemInTheBox.texture = Things.fetch_sprite(itemType, itemSubtype)
214-
Things.TYPE.DOOR: workshopItemInTheBox.texture = Things.fetch_sprite(itemType, itemSubtype)
215-
216-
workshopItemInTheBox.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
217-
#workshopItemInTheBox.size_flags_vertical = Control.SIZE_EXPAND_FILL
218-
#workshopItemInTheBox.size_flags_horizontal = Control.SIZE_EXPAND_FILL
219-
workshopItemInTheBox.expand = true
220-
221-
# It was tricky to get them consistent with each other (in ThingPickerWindow and on map), so just did it manually.
222-
if textureParent is TextureButton:
223-
workshopItemInTheBox.anchor_left = 0.25
224-
workshopItemInTheBox.anchor_top = 0.25
225-
workshopItemInTheBox.anchor_right = 0.75
226-
workshopItemInTheBox.anchor_bottom = 0.75
227-
else:
228-
workshopItemInTheBox.anchor_left = 0.15
229-
workshopItemInTheBox.anchor_top = 0.15
230-
workshopItemInTheBox.anchor_right = 0.85
231-
workshopItemInTheBox.anchor_bottom = 0.85
232-
233-
workshopItemInTheBox.rect_position.x += 2
234-
workshopItemInTheBox.rect_position.y -= 1
235-
236-
workshopItemInTheBox.modulate = Color(1,1,1,0.5)
237-
workshopItemInTheBox.mouse_filter = Control.MOUSE_FILTER_IGNORE
238-
239-
textureParent.add_child(workshopItemInTheBox)
240-
204+
if Things.DATA_OBJECT.has(subtype):
205+
var nameID = Things.DATA_OBJECT[subtype][Things.NAME_ID]
206+
if Things.LIST_OF_BOXES.has(nameID):
207+
var itemData = Things.LIST_OF_BOXES[nameID]
208+
var itemType = itemData[0]
209+
var itemSubtype = itemData[1]
210+
211+
var workshopItemInTheBox = TextureRect.new()
212+
workshopItemInTheBox.texture = Things.fetch_sprite(itemType, itemSubtype)
213+
workshopItemInTheBox.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
214+
workshopItemInTheBox.expand = true
215+
216+
if textureParent is TextureButton:
217+
workshopItemInTheBox.anchor_left = 0.25
218+
workshopItemInTheBox.anchor_top = 0.25
219+
workshopItemInTheBox.anchor_right = 0.75
220+
workshopItemInTheBox.anchor_bottom = 0.75
221+
else:
222+
workshopItemInTheBox.anchor_left = 0.15
223+
workshopItemInTheBox.anchor_top = 0.15
224+
workshopItemInTheBox.anchor_right = 0.85
225+
workshopItemInTheBox.anchor_bottom = 0.85
226+
227+
workshopItemInTheBox.rect_position = Vector2(2, -1)
228+
workshopItemInTheBox.modulate = Color(1, 1, 1, 0.5)
229+
workshopItemInTheBox.mouse_filter = Control.MOUSE_FILTER_IGNORE
230+
231+
textureParent.add_child(workshopItemInTheBox)
232+
return true
233+
234+
return false
241235

242236
func current_grid_container():
243237
return get_grid_container_node(oThingTabs.get_current_tab_control())

Scenes/ThingInstance.gd

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ func set_texture_based_on_thingtype():
218218
Things.TYPE.OBJECT:
219219
if subtype in [49, 111,120,121,122]: # Heart Flame and Gate
220220
$ThingTexture.self_modulate = "a0ffffff"
221-
elif Things.LIST_OF_BOXES.has(subtype):
221+
var successOrFailure = Nodelist.list["oPickThingWindow"].add_workshop_item_sprite_overlay($ThingTexture, subtype)
222+
if successOrFailure == true:
222223
$ThingTexture.rect_position += Vector2(-1,9)
223-
Nodelist.list["oPickThingWindow"].add_workshop_item_sprite_overlay($ThingTexture, subtype)
224224
Things.TYPE.CREATURE:
225225
if tex != null:
226226
#$ThingTexture.rect_position.y -= 12

0 commit comments

Comments
 (0)