Skip to content

Commit

Permalink
cfg refactor wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed May 9, 2024
1 parent c061745 commit d5628f7
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 17 deletions.
32 changes: 16 additions & 16 deletions Autoload/Things.gd
Original file line number Diff line number Diff line change
Expand Up @@ -686,22 +686,22 @@ func file_to_upper_string(dir, fileName):
return massiveString


func get_zip_files_in_dir(path):
var array = []
var dir = Directory.new()
if dir.open(path) == OK:
dir.list_dir_begin()
var file_name = dir.get_next()
while file_name != "":
if dir.current_is_dir():
pass
else:
if file_name.get_extension().to_upper() == "ZIP":
array.append(path.plus_file(file_name))
file_name = dir.get_next()
else:
print("An error occurred when trying to access the path.")
return array
#func get_zip_files_in_dir(path):
# var array = []
# var dir = Directory.new()
# if dir.open(path) == OK:
# dir.list_dir_begin()
# var file_name = dir.get_next()
# while file_name != "":
# if dir.current_is_dir():
# pass
# else:
# if file_name.get_extension().to_upper() == "ZIP":
# array.append(path.plus_file(file_name))
# file_name = dir.get_next()
# else:
# print("An error occurred when trying to access the path.")
# return array

func look_for_images_to_load(DATA_ARRAY, objectID, thingCfgName):
if custom_images_list.empty() == true:
Expand Down
64 changes: 64 additions & 0 deletions Scenes/FxDataCache.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
extends Node
onready var oGame = Nodelist.list["oGame"]

# These are dictionaries containing dictionaries.
# objects_cfg["section_name"]["key"] will return the "value"
# If there's a space in the value string, then the value will be an array of strings or integers.

var terrain_cfg:Dictionary
var objects_cfg:Dictionary
var creature_cfg:Dictionary
var trapdoor_cfg:Dictionary


func start():
var CODETIME_START = OS.get_ticks_msec()
terrain_cfg = read_dkcfg_file(oGame.DK_FXDATA_DIRECTORY.plus_file("terrain.cfg"))
objects_cfg = read_dkcfg_file(oGame.DK_FXDATA_DIRECTORY.plus_file("objects.cfg"))
creature_cfg = read_dkcfg_file(oGame.DK_FXDATA_DIRECTORY.plus_file("creature.cfg"))
trapdoor_cfg = read_dkcfg_file(oGame.DK_FXDATA_DIRECTORY.plus_file("trapdoor.cfg"))
print('Parsed all dkcfg files: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms')


func read_dkcfg_file(file_path) -> Dictionary:
var config = {}
var current_section = ""

var file = File.new()
if not file.file_exists(file_path):
print("File not found: ", file_path)
return config

file.open(file_path, File.READ)
var lines = file.get_as_text().split("\n")
file.close()

for line in lines:
line = line.strip_edges()
if line.begins_with(";") or line.empty():
continue

if line.begins_with("[") and line.ends_with("]"):
current_section = line.substr(1, line.length() - 2)
config[current_section] = {}
else:
var delimiter_pos = line.find("=")
if delimiter_pos != -1:
var key = line.substr(0, delimiter_pos).strip_edges()
var value = line.substr(delimiter_pos + 1).strip_edges()

if " " in value:
var construct_new_value_array = []
for item in value.split(" "):
if item.is_valid_integer():
construct_new_value_array.append(int(item))
else:
construct_new_value_array.append(item)
config[current_section][key] = construct_new_value_array
else:
if value.is_valid_integer():
config[current_section][key] = int(value)
else:
config[current_section][key] = value

return config
6 changes: 5 additions & 1 deletion Scenes/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=189 format=2]
[gd_scene load_steps=190 format=2]

[ext_resource path="res://Scenes/SlabStyle.gd" type="Script" id=1]
[ext_resource path="res://Scenes/SlabPlacement.gd" type="Script" id=2]
Expand Down Expand Up @@ -168,6 +168,7 @@
[ext_resource path="res://Scenes/UndoStates.gd" type="Script" id=166]
[ext_resource path="res://Scenes/ThreadedSaveUndo.gd" type="Script" id=167]
[ext_resource path="res://Scenes/Guidelines.gd" type="Script" id=168]
[ext_resource path="res://Scenes/FxDataCache.gd" type="Script" id=169]

[sub_resource type="CubeMesh" id=2]
size = Vector3( 1, 1, 1 )
Expand Down Expand Up @@ -332,6 +333,9 @@ script = ExtResource( 37 )
[node name="Game" type="Node" parent="."]
script = ExtResource( 30 )
[node name="FxDataCache" type="Node" parent="."]
script = ExtResource( 169 )
[node name="TextureCache" type="Node" parent="."]
script = ExtResource( 46 )
Expand Down
3 changes: 3 additions & 0 deletions Scenes/OpenMap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ onready var oDataLevelStyle = Nodelist.list["oDataLevelStyle"]
onready var oCamera2D = Nodelist.list["oCamera2D"]
onready var oDataClm = Nodelist.list["oDataClm"]
onready var oTextureCache = Nodelist.list["oTextureCache"]
onready var oFxDataCache = Nodelist.list["oFxDataCache"]
onready var oUiTools = Nodelist.list["oUiTools"]
onready var oOverheadGraphics = Nodelist.list["oOverheadGraphics"]
onready var oPickSlabWindow = Nodelist.list["oPickSlabWindow"]
Expand Down Expand Up @@ -100,6 +101,8 @@ func open_map(filePath):
oMessage.quick("Error: Cannot open map because textures haven't been loaded")
return

oFxDataCache.start()

print("----------- Opening map ------------")
TOTAL_TIME_TO_OPEN_MAP = OS.get_ticks_msec()

Expand Down

0 comments on commit d5628f7

Please sign in to comment.