Skip to content

Commit d5628f7

Browse files
committed
cfg refactor wip
1 parent c061745 commit d5628f7

File tree

4 files changed

+88
-17
lines changed

4 files changed

+88
-17
lines changed

Autoload/Things.gd

+16-16
Original file line numberDiff line numberDiff line change
@@ -686,22 +686,22 @@ func file_to_upper_string(dir, fileName):
686686
return massiveString
687687

688688

689-
func get_zip_files_in_dir(path):
690-
var array = []
691-
var dir = Directory.new()
692-
if dir.open(path) == OK:
693-
dir.list_dir_begin()
694-
var file_name = dir.get_next()
695-
while file_name != "":
696-
if dir.current_is_dir():
697-
pass
698-
else:
699-
if file_name.get_extension().to_upper() == "ZIP":
700-
array.append(path.plus_file(file_name))
701-
file_name = dir.get_next()
702-
else:
703-
print("An error occurred when trying to access the path.")
704-
return array
689+
#func get_zip_files_in_dir(path):
690+
# var array = []
691+
# var dir = Directory.new()
692+
# if dir.open(path) == OK:
693+
# dir.list_dir_begin()
694+
# var file_name = dir.get_next()
695+
# while file_name != "":
696+
# if dir.current_is_dir():
697+
# pass
698+
# else:
699+
# if file_name.get_extension().to_upper() == "ZIP":
700+
# array.append(path.plus_file(file_name))
701+
# file_name = dir.get_next()
702+
# else:
703+
# print("An error occurred when trying to access the path.")
704+
# return array
705705

706706
func look_for_images_to_load(DATA_ARRAY, objectID, thingCfgName):
707707
if custom_images_list.empty() == true:

Scenes/FxDataCache.gd

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 start():
15+
var CODETIME_START = OS.get_ticks_msec()
16+
terrain_cfg = read_dkcfg_file(oGame.DK_FXDATA_DIRECTORY.plus_file("terrain.cfg"))
17+
objects_cfg = read_dkcfg_file(oGame.DK_FXDATA_DIRECTORY.plus_file("objects.cfg"))
18+
creature_cfg = read_dkcfg_file(oGame.DK_FXDATA_DIRECTORY.plus_file("creature.cfg"))
19+
trapdoor_cfg = read_dkcfg_file(oGame.DK_FXDATA_DIRECTORY.plus_file("trapdoor.cfg"))
20+
print('Parsed all dkcfg files: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms')
21+
22+
23+
func read_dkcfg_file(file_path) -> Dictionary:
24+
var config = {}
25+
var current_section = ""
26+
27+
var file = File.new()
28+
if not file.file_exists(file_path):
29+
print("File not found: ", file_path)
30+
return config
31+
32+
file.open(file_path, File.READ)
33+
var lines = file.get_as_text().split("\n")
34+
file.close()
35+
36+
for line in lines:
37+
line = line.strip_edges()
38+
if line.begins_with(";") or line.empty():
39+
continue
40+
41+
if line.begins_with("[") and line.ends_with("]"):
42+
current_section = line.substr(1, line.length() - 2)
43+
config[current_section] = {}
44+
else:
45+
var delimiter_pos = line.find("=")
46+
if delimiter_pos != -1:
47+
var key = line.substr(0, delimiter_pos).strip_edges()
48+
var value = line.substr(delimiter_pos + 1).strip_edges()
49+
50+
if " " in value:
51+
var construct_new_value_array = []
52+
for item in value.split(" "):
53+
if item.is_valid_integer():
54+
construct_new_value_array.append(int(item))
55+
else:
56+
construct_new_value_array.append(item)
57+
config[current_section][key] = construct_new_value_array
58+
else:
59+
if value.is_valid_integer():
60+
config[current_section][key] = int(value)
61+
else:
62+
config[current_section][key] = value
63+
64+
return config

Scenes/Main.tscn

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=189 format=2]
1+
[gd_scene load_steps=190 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,6 +168,7 @@
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]
171172

172173
[sub_resource type="CubeMesh" id=2]
173174
size = Vector3( 1, 1, 1 )
@@ -332,6 +333,9 @@ script = ExtResource( 37 )
332333
[node name="Game" type="Node" parent="."]
333334
script = ExtResource( 30 )
334335
336+
[node name="FxDataCache" type="Node" parent="."]
337+
script = ExtResource( 169 )
338+
335339
[node name="TextureCache" type="Node" parent="."]
336340
script = ExtResource( 46 )
337341

Scenes/OpenMap.gd

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ onready var oDataLevelStyle = Nodelist.list["oDataLevelStyle"]
1313
onready var oCamera2D = Nodelist.list["oCamera2D"]
1414
onready var oDataClm = Nodelist.list["oDataClm"]
1515
onready var oTextureCache = Nodelist.list["oTextureCache"]
16+
onready var oFxDataCache = Nodelist.list["oFxDataCache"]
1617
onready var oUiTools = Nodelist.list["oUiTools"]
1718
onready var oOverheadGraphics = Nodelist.list["oOverheadGraphics"]
1819
onready var oPickSlabWindow = Nodelist.list["oPickSlabWindow"]
@@ -100,6 +101,8 @@ func open_map(filePath):
100101
oMessage.quick("Error: Cannot open map because textures haven't been loaded")
101102
return
102103

104+
oFxDataCache.start()
105+
103106
print("----------- Opening map ------------")
104107
TOTAL_TIME_TO_OPEN_MAP = OS.get_ticks_msec()
105108

0 commit comments

Comments
 (0)