Skip to content

Commit

Permalink
Load slabset.toml and columnset.toml in automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed May 26, 2024
1 parent a8459d7 commit 006a41d
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 289 deletions.
67 changes: 27 additions & 40 deletions Autoload/Columnset.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,31 @@ var columnsContainingRngCubes = {}
# map0000x.clm : 49,160 bytes. first 4 bytes contains 2048, second 4 bytes are ???, then comes the column data.
# slabs.clm : 49,156 bytes. first 4 bytes contains 2048, then comes the column data.

func load_default_columnset():
clear_all_column_data() # This goes here and not inside import_toml_columnset, because that function is also used for merging columnsets

func import_toml_columnset(filePath):
var oMessage = Nodelist.list["oMessage"]
var cfg = ConfigFile.new()
var err = cfg.load(filePath)

var CODETIME_START = OS.get_ticks_msec()
# Decide which one to load
var filePath = oGame.get_precise_filepath(oGame.DK_FXDATA_DIRECTORY, "COLUMNSET.TOML")
if filePath != "":
# Load /fxdata/ columnset.toml file
import_toml_columnset(filePath, true, false)
else:
# Load slabs.clm file
load_default_original_columnset()
if err != OK:
return

store_default_data()
print('Created Columnset : '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')
update_list_of_columns_that_contain_owned_cubes()
update_list_of_columns_that_contain_rng_cubes()
for section in cfg.get_sections():
if section.begins_with("column"):
var columnIndex = int(section)
utilized[columnIndex] = 0 #cfg.get_value(section, "Utilized", 0)
permanent[columnIndex] = 1 #cfg.get_value(section, "Permanent", 0)
lintel[columnIndex] = cfg.get_value(section, "Lintel", 0)
height[columnIndex] = cfg.get_value(section, "Height", 0)
solidMask[columnIndex] = cfg.get_value(section, "SolidMask", 0)
floorTexture[columnIndex] = cfg.get_value(section, "FloorTexture", 0)
orientation[columnIndex] = cfg.get_value(section, "Orientation", 0)
cubes[columnIndex] = cfg.get_value(section, "Cubes", [0,0,0,0, 0,0,0,0])

if "fxdata" in filePath:
store_default_data()
update_list_of_columns_that_contain_owned_cubes()
update_list_of_columns_that_contain_rng_cubes()

func load_default_original_columnset():
var filePath = oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.CLM")
Expand Down Expand Up @@ -64,6 +72,10 @@ func load_default_original_columnset():

for cubeNumber in 8:
cubes[entry][cubeNumber] = buffer.get_u16() # 8-23

store_default_data()
update_list_of_columns_that_contain_owned_cubes()
update_list_of_columns_that_contain_rng_cubes()

func store_default_data():
default_data["utilized"] = utilized.duplicate(true)
Expand All @@ -76,31 +88,6 @@ func store_default_data():
default_data["floorTexture"] = floorTexture.duplicate(true)


func import_toml_columnset(filePath, fullExport, showMessages):
var oMessage = Nodelist.list["oMessage"]
var cfg = ConfigFile.new()
var err = cfg.load(filePath)

if err != OK:
if showMessages == true: oMessage.quick("Failed to load config file: " + str(filePath))
return

for section in cfg.get_sections():
if section.begins_with("column"):
var columnIndex = int(section)
utilized[columnIndex] = 0 #cfg.get_value(section, "Utilized", 0)
permanent[columnIndex] = 1 #cfg.get_value(section, "Permanent", 0)
lintel[columnIndex] = cfg.get_value(section, "Lintel", 0)
height[columnIndex] = cfg.get_value(section, "Height", 0)
solidMask[columnIndex] = cfg.get_value(section, "SolidMask", 0)
floorTexture[columnIndex] = cfg.get_value(section, "FloorTexture", 0)
orientation[columnIndex] = cfg.get_value(section, "Orientation", 0)
cubes[columnIndex] = cfg.get_value(section, "Cubes", [0,0,0,0, 0,0,0,0])

if showMessages == true: oMessage.quick("Merged: " + str(filePath))



func export_toml_columnset(filePath, fullExport): #"res://columnset.toml"
var oMessage = Nodelist.list["oMessage"]

Expand Down
114 changes: 48 additions & 66 deletions Autoload/Slabset.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,80 +32,17 @@ enum dir {
center = 27
}

#func _ready():
# yield(get_tree(),'idle_frame') # Needed for this test, so that default_data is established first
# var CODETIME_START = OS.get_ticks_msec()
# import_toml_slabset("D:/AI/slabset.toml", true)
# print('Import Codetime: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms')

func load_default_slabset():
var CODETIME_START = OS.get_ticks_msec()
func clear_all_slabset_data():
tng = []
dat = []

# Decide which one to load
var filePath = oGame.get_precise_filepath(oGame.DK_FXDATA_DIRECTORY, "SLABSET.TOML")
if filePath != "":
# Load slabset.toml file
import_toml_slabset(filePath, true, false)
else:
# Load slabs.dat and slabs.tng files
load_default_original_slabset()

print('Created Slabset : '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')
store_default_data()


func load_default_original_slabset():

var dat_buffer = oBuffers.file_path_to_buffer(oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.DAT"))
var tng_buffer = oBuffers.file_path_to_buffer(oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.TNG"))

var object_info = create_object_list(tng_buffer)
if object_info.size() == 0:
oMessage.quick("Failed to load objects")
return

var totalSlabs = 42 + 16
var totalVariations = totalSlabs * 28
tng.resize(totalVariations)
dat.resize(totalVariations)
tng_buffer.seek(2)
dat_buffer.seek(2)

for variation in dat.size():
tng[variation] = []
dat[variation] = [0,0,0, 0,0,0, 0,0,0]
if variation < 42*28 or (variation % 28) < 8: # Handle the longslabs and the shortslabs

for subtile in 9:
dat[variation][subtile] = 65536 - dat_buffer.get_u16()

var getObjectIndex = tng_buffer.get_u16()

while getObjectIndex < object_info.size(): # Continue until "break"
var objectStuff = object_info[getObjectIndex]
if objectStuff[1] != variation:
break
tng[variation].append(objectStuff)
getObjectIndex += 1



func store_default_data():
default_data["dat"] = dat.duplicate(true)
default_data["tng"] = tng.duplicate(true)


func import_toml_slabset(filePath, fullImport, showMessages):
func import_toml_slabset(filePath):
var processed_string = preprocess_toml_file(filePath)
if processed_string == null:
if showMessages == true: oMessage.quick("Failed to open file: " + str(filePath))
return
var cfg = ConfigFile.new()
var err = cfg.parse(processed_string)
if err != OK:
if showMessages == true: oMessage.quick("Failed to parse config file")
return

resize_dat_and_tng_based_on_file(cfg)
Expand Down Expand Up @@ -147,7 +84,52 @@ func import_toml_slabset(filePath, fullImport, showMessages):
"ThingType": getObject[obj.THING_TYPE] = int(value) #int(Things.reverse_data_structure_name.get(value, 0))
"Subtype": getObject[obj.THING_SUBTYPE] = int(value)
"EffectRange": getObject[obj.EFFECT_RANGE] = int(value)
if showMessages == true: oMessage.quick("Merged: " + str(filePath))

if "fxdata" in filePath:
store_default_data()


func load_default_original_slabset():

var dat_buffer = oBuffers.file_path_to_buffer(oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.DAT"))
var tng_buffer = oBuffers.file_path_to_buffer(oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.TNG"))

var object_info = create_object_list(tng_buffer)
if object_info.size() == 0:
oMessage.quick("Failed to load objects")
return

var totalSlabs = 42 + 16
var totalVariations = totalSlabs * 28
tng.resize(totalVariations)
dat.resize(totalVariations)
tng_buffer.seek(2)
dat_buffer.seek(2)

for variation in dat.size():
tng[variation] = []
dat[variation] = [0,0,0, 0,0,0, 0,0,0]
if variation < 42*28 or (variation % 28) < 8: # Handle the longslabs and the shortslabs

for subtile in 9:
dat[variation][subtile] = 65536 - dat_buffer.get_u16()

var getObjectIndex = tng_buffer.get_u16()

while getObjectIndex < object_info.size(): # Continue until "break"
var objectStuff = object_info[getObjectIndex]
if objectStuff[1] != variation:
break
tng[variation].append(objectStuff)
getObjectIndex += 1

store_default_data()


func store_default_data():
default_data["dat"] = dat.duplicate(true)
default_data["tng"] = tng.duplicate(true)


func resize_dat_and_tng_based_on_file(cfg):
# Determine maximum needed size for dat and tng arrays
Expand Down
4 changes: 2 additions & 2 deletions Autoload/Things.gd
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func fetch_name(thing_type, sub_type):
return dictionary_of_names.get(nameId[0], nameId[0].capitalize())
return "Error1337"
else:
return "Unknown " + data_structure_name[thing_type] + " Subtype: " + str(sub_type)
return "Unknown " + data_structure_name[thing_type] + ": " + str(sub_type)
else:
return "Unknown Thingtype " + str(thing_type) + ", Subtype: " + str(sub_type)

Expand All @@ -99,7 +99,7 @@ func fetch_id_string(thing_type, sub_type):
return nameId[0].capitalize()
return "Error1337"
else:
return "Unknown " + data_structure_name[thing_type] + " Subtype: " + str(sub_type)
return "Unknown " + data_structure_name[thing_type] + ": " + str(sub_type)


var data_structure_name = {
Expand Down
28 changes: 21 additions & 7 deletions Scenes/CfgLoader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ enum {
}

func start(mapPath):

if Cube.tex.empty():
Cube.read_cubes_cfg()

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

var campaign_cfg = load_campaign_data(mapPath)

Expand All @@ -39,7 +44,7 @@ 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"]:
for file_name in ["objects.cfg", "creature.cfg", "trapdoor.cfg", "terrain.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
Expand All @@ -48,9 +53,18 @@ func start(mapPath):
"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)

print('Loaded things from cfg files: ' + str(OS.get_ticks_msec() - CODETIME_LOADCFG_START) + 'ms')
print(Slabs.doorslab_data)
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):
var objects_cfg = Utils.read_dkcfg_file(path)
Expand Down
Loading

0 comments on commit 006a41d

Please sign in to comment.