|
| 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 |
0 commit comments