From 782a1508faab77b8263f69ccd61d0355ad2d1423 Mon Sep 17 00:00:00 2001 From: rainlizard <15337628+rainlizard@users.noreply.github.com> Date: Mon, 27 May 2024 18:41:41 +1000 Subject: [PATCH] load cubes.cfg from all directories --- Autoload/Columnset.gd | 2 - Autoload/Cube.gd | 86 ++++++++++++++++------------------ Scenes/CfgLoader.gd | 66 +++++++++++++------------- Scenes/CompareCreatureStats.gd | 5 ++ 4 files changed, 78 insertions(+), 81 deletions(-) diff --git a/Autoload/Columnset.gd b/Autoload/Columnset.gd index 3fb2b931..10701bef 100644 --- a/Autoload/Columnset.gd +++ b/Autoload/Columnset.gd @@ -22,10 +22,8 @@ var columnsContainingRngCubes = {} func import_toml_columnset(filePath): - var oMessage = Nodelist.list["oMessage"] var cfg = ConfigFile.new() var err = cfg.load(filePath) - if err != OK: return diff --git a/Autoload/Cube.gd b/Autoload/Cube.gd index 52e73519..7ced15ba 100644 --- a/Autoload/Cube.gd +++ b/Autoload/Cube.gd @@ -46,57 +46,18 @@ enum { SIDE_TOP = 4, SIDE_BOTTOM = 5, } +func clear_all_cube_data(): + tex.clear() + names.clear() - - -func get_cubescfg_modified_time(): - var oGame = Nodelist.list["oGame"] - var path = oGame.get_precise_filepath(oGame.DK_FXDATA_DIRECTORY, "CUBES.CFG") - var getModifiedTime = File.new().get_modified_time(path) - return getModifiedTime - -func _notification(what: int): - if what == MainLoop.NOTIFICATION_WM_FOCUS_IN: - var oDataClm = Nodelist.list["oDataClm"] - if oDataClm.cubes.empty() == false: # fixes a crash when you've got no map loaded - if cubesCfgLastModifiedTime != get_cubescfg_modified_time(): - var oMessage = Nodelist.list["oMessage"] - var oOverheadGraphics = Nodelist.list["oOverheadGraphics"] - var oPickSlabWindow = Nodelist.list["oPickSlabWindow"] - var oColumnEditor = Nodelist.list["oColumnEditor"] - var oSlabsetWindow = Nodelist.list["oSlabsetWindow"] - var oEditor = Nodelist.list["oEditor"] - var oGenerateTerrain = Nodelist.list["oGenerateTerrain"] - - read_cubes_cfg() - # Refresh the display of anything that handles cubes - - oOverheadGraphics.update_full_overhead_map(oOverheadGraphics.SINGLE_THREADED) - oPickSlabWindow.add_slabs() - oColumnEditor._on_ColumnEditor_visibility_changed() - oSlabsetWindow._on_SlabsetWindow_visibility_changed() - if oEditor.currentView == oEditor.VIEW_3D: - oGenerateTerrain.start() - - oMessage.quick("Reloaded cubes.cfg") - -func read_cubes_cfg(): - - var oGame = Nodelist.list["oGame"] - var path = oGame.get_precise_filepath(oGame.DK_FXDATA_DIRECTORY, "CUBES.CFG") - if path == "": - load_dk_original_cubes() - return - +func read_cubes_cfg(path): var CODETIME_START = OS.get_ticks_msec() var file = File.new() if file.open(path, File.READ) != OK: - load_dk_original_cubes() return # Important to clear these because they get reloaded - tex.clear() - names.clear() + clear_all_cube_data() cubesCfgLastModifiedTime = get_cubescfg_modified_time() @@ -122,9 +83,10 @@ func read_cubes_cfg(): int(componentsOfLine[7]), ]) - print('Cube names read in: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms') - set_max_cubes() # Run for both read_cubes_cfg() and at the bottom of load_dk_original_cubes() + print('Cube names read in: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms') + + func load_dk_original_cubes(): tex = [ @@ -650,3 +612,35 @@ func set_max_cubes(): oColumnEditorControls.establish_maximum_cube_field_values() oColumnsetControls.establish_maximum_cube_field_values() + + +func get_cubescfg_modified_time(): + var oGame = Nodelist.list["oGame"] + var path = oGame.get_precise_filepath(oGame.DK_FXDATA_DIRECTORY, "CUBES.CFG") + var getModifiedTime = File.new().get_modified_time(path) + return getModifiedTime + +#func _notification(what: int): +# if what == MainLoop.NOTIFICATION_WM_FOCUS_IN: +# var oDataClm = Nodelist.list["oDataClm"] +# if oDataClm.cubes.empty() == false: # fixes a crash when you've got no map loaded +# if cubesCfgLastModifiedTime != get_cubescfg_modified_time(): +# var oMessage = Nodelist.list["oMessage"] +# var oOverheadGraphics = Nodelist.list["oOverheadGraphics"] +# var oPickSlabWindow = Nodelist.list["oPickSlabWindow"] +# var oColumnEditor = Nodelist.list["oColumnEditor"] +# var oSlabsetWindow = Nodelist.list["oSlabsetWindow"] +# var oEditor = Nodelist.list["oEditor"] +# var oGenerateTerrain = Nodelist.list["oGenerateTerrain"] +# +# read_cubes_cfg() +# # Refresh the display of anything that handles cubes +# +# oOverheadGraphics.update_full_overhead_map(oOverheadGraphics.SINGLE_THREADED) +# oPickSlabWindow.add_slabs() +# oColumnEditor._on_ColumnEditor_visibility_changed() +# oSlabsetWindow._on_SlabsetWindow_visibility_changed() +# if oEditor.currentView == oEditor.VIEW_3D: +# oGenerateTerrain.start() +# +# oMessage.quick("Reloaded cubes.cfg") diff --git a/Scenes/CfgLoader.gd b/Scenes/CfgLoader.gd index a70350cc..67798610 100644 --- a/Scenes/CfgLoader.gd +++ b/Scenes/CfgLoader.gd @@ -21,19 +21,13 @@ enum { } func start(mapPath): - if Cube.tex.empty() == true: Cube.read_cubes_cfg() var CODETIME_LOADCFG_START = OS.get_ticks_msec() Things.reset_thing_data_to_default() Slabs.reset_slab_data_to_default() Slabset.clear_all_slabset_data() Columnset.clear_all_column_data() - - # If the .toml files can't be found, then load the slabs.clm/slabs.dat/slabs.tng files - if oGame.get_precise_filepath(oGame.DK_FXDATA_DIRECTORY, "COLUMNSET.TOML") == "": - Columnset.load_default_original_columnset() # Load slabs.clm file - if oGame.get_precise_filepath(oGame.DK_FXDATA_DIRECTORY, "SLABSET.TOML") == "": - Slabset.load_default_original_slabset() # Load slabs.dat and slabs.tng files + Cube.clear_all_cube_data() var campaign_cfg = load_campaign_data(mapPath) @@ -44,29 +38,30 @@ func start(mapPath): } for cfg_type in [LOAD_CFG_FXDATA, LOAD_CFG_CAMPAIGN, LOAD_CFG_CURRENT_MAP]: var cfg_dir = config_dirs[cfg_type] - for file_name in ["objects.cfg", "creature.cfg", "trapdoor.cfg", "terrain.cfg", "slabset.toml", "columnset.toml"]: + for file_name in ["objects.cfg", "creature.cfg", "trapdoor.cfg", "terrain.cfg", "cubes.cfg", "slabset.toml", "columnset.toml"]: var file_path = cfg_dir.plus_file(file_name) if cfg_type == LOAD_CFG_CURRENT_MAP: file_path = cfg_dir + "." + file_name - match file_name: - "objects.cfg": load_objects_data(file_path) - "creature.cfg": load_creatures_data(file_path) - "trapdoor.cfg": load_trapdoor_data(file_path) - "terrain.cfg": load_terrain_data(file_path) - "slabset.toml": load_slabset_data(file_path) - "columnset.toml": load_columnset_data(file_path) + + if File.new().file_exists(file_path): + match file_name: + "objects.cfg": load_objects_data(file_path) + "creature.cfg": load_creatures_data(file_path) + "trapdoor.cfg": load_trapdoor_data(file_path) + "terrain.cfg": load_terrain_data(file_path) + "cubes.cfg": load_cubes_data(file_path) + "slabset.toml": load_slabset_data(file_path) + "columnset.toml": load_columnset_data(file_path) + else: + if cfg_type == LOAD_CFG_FXDATA: + match file_name: + "cubes.cfg": Cube.load_dk_original_cubes() + "slabset.toml": Slabset.load_default_original_slabset() # Load slabs.dat and slabs.tng files + "columnset.toml": Columnset.load_default_original_columnset() # Load slabs.clm file print('Loaded all .cfg and .toml files: ' + str(OS.get_ticks_msec() - CODETIME_LOADCFG_START) + 'ms') - -func load_slabset_data(file_path): - Slabset.import_toml_slabset(file_path) - -func load_columnset_data(file_path): - Columnset.import_toml_columnset(file_path) - - -func load_objects_data(path): +func load_objects_data(path): # 10ms var objects_cfg = Utils.read_dkcfg_file(path) for section in objects_cfg: if section.begins_with("object"): @@ -81,9 +76,8 @@ func load_objects_data(path): var newEditorTab = Things.GENRE_TO_TAB[newGenre] Things.DATA_OBJECT[id] = [newName, newSprite, newEditorTab] -const keeperfx_edited_slabs = [Slabs.GEMS] # This is to help with backwards compatibility for previous keeperfx versions that don't have these edits. - -func load_terrain_data(path): +var keeperfx_edited_slabs = [Slabs.GEMS] # This is to help with backwards compatibility for previous keeperfx versions that don't have these edits. +func load_terrain_data(path): # 4ms var terrain_cfg = Utils.read_dkcfg_file(path) for section in terrain_cfg: if section.begins_with("slab"): @@ -142,7 +136,7 @@ func load_terrain_data(path): ] -func load_creatures_data(path): +func load_creatures_data(path): # 3ms var creature_cfg = Utils.read_dkcfg_file(path) var creatures = creature_cfg.get("common", {}).get("Creatures", []) for id_number in creatures.size(): @@ -152,8 +146,7 @@ func load_creatures_data(path): var newSprite = get_sprite(newName, null) Things.DATA_CREATURE[creature_id] = [newName, newSprite, Things.TAB_CREATURE] - -func load_trapdoor_data(path): +func load_trapdoor_data(path): # 1ms var trapdoor_cfg = Utils.read_dkcfg_file(path) for section in trapdoor_cfg: var id = int(section) @@ -183,9 +176,6 @@ func load_trapdoor_data(path): Things.DATA_TRAP[id] = [newName, newSprite, Things.TAB_TRAP] Things.LIST_OF_BOXES[crateName] = [trapOrDoor, id] - - - func get_sprite(first_priority, second_priority): if Graphics.sprite_id.has(first_priority): return first_priority if Graphics.sprite_id.has(second_priority): return second_priority @@ -205,3 +195,13 @@ func load_campaign_data(mapPath): #print(oGame.GAME_DIRECTORY.plus_file(levelsLocation).to_lower()) return cfgDictionary return {} + + +func load_cubes_data(file_path): # 6ms + Cube.read_cubes_cfg(file_path) + +func load_slabset_data(file_path): # 33ms + Slabset.import_toml_slabset(file_path) + +func load_columnset_data(file_path): # 29ms + Columnset.import_toml_columnset(file_path) diff --git a/Scenes/CompareCreatureStats.gd b/Scenes/CompareCreatureStats.gd index 0df000e2..2073a4ef 100644 --- a/Scenes/CompareCreatureStats.gd +++ b/Scenes/CompareCreatureStats.gd @@ -51,6 +51,11 @@ func update_list(optionButtonIndex): var label_text = str(i[0]) # Create a single string with a separator if label_text in selected_labels: col = Color(1.0,1.0,1.0) + + + if i[1] is Array: + i[1] = str(i[1]).replace("[", "").replace("]", "").replace(",", "").replace(" ", " ") + add_entry(i[0], i[1], col) func figure_out_name(NAME_ID, file):