Skip to content

Commit

Permalink
doorslab data, loading Secret Door
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed May 25, 2024
1 parent b8bbda6 commit 3435ed3
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 30 deletions.
1 change: 1 addition & 0 deletions Autoload/Names.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const things = {
"BRACED" : "Braced Door",
"STEEL" : "Iron Door",
"MAGIC" : "Magic Door",
"SECRET" : "Secret Door",
},
TYPE.TRAP : {
"BOULDER" : "Boulder Trap",
Expand Down
51 changes: 42 additions & 9 deletions Autoload/Slabs.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ extends Node

# DISPLAYS DECORATION STUFF ON THE SIDE


var default_data = {}
func _init():
# This only takes 1ms
default_data["data"] = data.duplicate(true)
default_data["doorslab_data"] = doorslab_data.duplicate(true)

func reset_slab_data_to_default(): # Reset data. Takes 1ms.
data = default_data["data"].duplicate(true)
doorslab_data = default_data["doorslab_data"].duplicate(true)


enum {
NAME
IS_SOLID # Whether units can walk there, and how fortified walls do their bitmask, AND for 3D generation optimization
Expand Down Expand Up @@ -134,18 +146,39 @@ enum {
DOORSLAB_THING = 0,
DOORSLAB_ORIENTATION = 1,
}
enum {
DOORTHING_WOOD = 1
DOORTHING_BRACED = 2
DOORTHING_STEEL = 3
DOORTHING_MAGIC = 4
}
#Slabs.door_data[slabID][DOORSLAB_THING]
#Slabs.door_data[slabID][DOORSLAB_ORIENTATION]
var door_data = { # Refer to Things.DATA_DOOR for door subtypes
WOODEN_DOOR_1 : [1, 1],
WOODEN_DOOR_2 : [1, 0],
BRACED_DOOR_1 : [2, 1],
BRACED_DOOR_2 : [2, 0],
IRON_DOOR_1 : [3, 1],
IRON_DOOR_2 : [3, 0],
MAGIC_DOOR_1 : [4, 1],
MAGIC_DOOR_2 : [4, 0],
enum { # These might be backwards
DOOR_ORIENT_NS = 0
DOOR_ORIENT_EW = 1
}

func fetch_doorslab_data(slabID):
var slabData = Slabs.data.get(slabID)
if slabData:
return doorslab_data.get(slabData[NAME])

var doorslab_data = { # Refer to Things.DATA_DOOR for door subtypes
"DOOR_WOODEN" : [DOORTHING_WOOD, DOOR_ORIENT_EW],
"DOOR_WOODEN2" : [DOORTHING_WOOD, DOOR_ORIENT_NS],
"DOOR_BRACE" : [DOORTHING_BRACED, DOOR_ORIENT_EW],
"DOOR_BRACE2" : [DOORTHING_BRACED, DOOR_ORIENT_NS],
"DOOR_STEEL" : [DOORTHING_STEEL, DOOR_ORIENT_EW],
"DOOR_STEEL2" : [DOORTHING_STEEL, DOOR_ORIENT_NS],
"DOOR_MAGIC" : [DOORTHING_MAGIC, DOOR_ORIENT_EW],
"DOOR_MAGIC2" : [DOORTHING_MAGIC, DOOR_ORIENT_NS],
}

#"DOOR_SECRET"
#"DOOR_SECRET2"


var fake_extra_data = {
# 1000: [cube_data, floor_data, recognized_as, wibble_edges]
}
Expand Down
10 changes: 9 additions & 1 deletion Scenes/CfgLoader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func start(mapPath):
var CODETIME_LOADCFG_START = OS.get_ticks_msec()

Things.reset_thing_data_to_default()
Slabs.reset_slab_data_to_default()

var campaign_cfg = load_campaign_data(mapPath)

Expand All @@ -49,6 +50,7 @@ func start(mapPath):
"terrain.cfg": load_terrain_data(file_path)

print('Loaded things from cfg files: ' + str(OS.get_ticks_msec() - CODETIME_LOADCFG_START) + 'ms')
print(Slabs.doorslab_data)

func load_objects_data(path):
var objects_cfg = Utils.read_dkcfg_file(path)
Expand All @@ -72,7 +74,7 @@ func load_terrain_data(path):
for section in terrain_cfg:
if section.begins_with("slab"):
var id = int(section)
if id >= 54 or id in keeperfx_edited_slabs:
if id >= 55 or id in keeperfx_edited_slabs:
var slabSection = terrain_cfg[section]

var setName = slabSection.get("Name", "UNKNOWN")
Expand Down Expand Up @@ -157,6 +159,12 @@ func load_trapdoor_data(path):

if trapOrDoor == Things.TYPE.DOOR:
Things.DATA_DOOR[id] = [newName, newSprite, Things.TAB_MISC]

var getSlabKind = data.get("SlabKind", null)
if getSlabKind is Array and getSlabKind.size() == 2:
Slabs.doorslab_data[getSlabKind[0]] = [id, Slabs.DOOR_ORIENT_EW]
Slabs.doorslab_data[getSlabKind[1]] = [id, Slabs.DOOR_ORIENT_NS]

elif trapOrDoor == Things.TYPE.TRAP:
Things.DATA_TRAP[id] = [newName, newSprite, Things.TAB_TRAP]
Things.LIST_OF_BOXES[crateName] = [trapOrDoor, id]
Expand Down
28 changes: 14 additions & 14 deletions Scenes/CustomSlabSystem.gd
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func add_custom_slab(slab_dict):
cfg.set_value(section,"is_solid", slab_dict["is_solid"])
cfg.set_value(section,"ownable", slab_dict["ownable"])

if slab_dict.has("door_thing") and slab_dict.has("door_orientation"):
cfg.set_value(section,"door_thing", slab_dict["door_thing"])
cfg.set_value(section,"door_orientation", slab_dict["door_orientation"])
Slabs.door_data[head_id] = [
slab_dict["door_thing"],
slab_dict["door_orientation"],
]
# if slab_dict.has("door_thing") and slab_dict.has("door_orientation"):
# cfg.set_value(section,"door_thing", slab_dict["door_thing"])
# cfg.set_value(section,"door_orientation", slab_dict["door_orientation"])
# Slabs.door_data[head_id] = [
# slab_dict["door_thing"],
# slab_dict["door_orientation"],
# ]

for i in 9:
if slab_dict["cube_data"].size() > 0:
Expand All @@ -108,13 +108,13 @@ func attempt_to_remove_custom_slab(header_id):
oPickSlabWindow.set_selection(null)

# If it's a door then it'll have "door_data", so remove the other one too
if Slabs.door_data.has(header_id) == true:
Slabs.door_data.erase(header_id)
var door2_id = header_id+1
if Slabs.door_data.has(door2_id) == true:
if Slabs.door_data[door2_id][Slabs.DOORSLAB_ORIENTATION] == 0: # Second direction always has orientation of 0
Slabs.door_data.erase(door2_id)
remove_custom_slab(door2_id)
# if Slabs.door_data.has(header_id) == true:
# Slabs.door_data.erase(header_id)
# var door2_id = header_id+1
# if Slabs.door_data.has(door2_id) == true:
# if Slabs.door_data[door2_id][Slabs.DOORSLAB_ORIENTATION] == 0: # Second direction always has orientation of 0
# Slabs.door_data.erase(door2_id)
# remove_custom_slab(door2_id)

remove_custom_slab(header_id)

Expand Down
10 changes: 6 additions & 4 deletions Scenes/Instances.gd
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,10 @@ func place_new_thing(newThingType, newSubtype, newPosition, newOwnership): # Pla
id.doorLocked = oPlacingSettings.doorLocked
if newSubtype == 0:
id.subtype = 1 #Depending on whether it was placed via autoslab or a hand placed Thing object.
if Slabs.door_data.has(slabID):
id.subtype = Slabs.door_data[slabID][Slabs.DOORSLAB_THING]
id.doorOrientation = Slabs.door_data[slabID][Slabs.DOORSLAB_ORIENTATION]
var doorSlabData = Slabs.fetch_doorslab_data(slabID)
if doorSlabData:
id.subtype = doorSlabData[Slabs.DOORSLAB_THING]
id.doorOrientation = doorSlabData[Slabs.DOORSLAB_ORIENTATION]

add_child(id)
#print('Thing placed in : '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')
Expand All @@ -332,7 +333,8 @@ func place_new_thing(newThingType, newSubtype, newPosition, newOwnership): # Pla
id.locationX = locX
id.locationY = locY
elif id.thingType == Things.TYPE.DOOR:
if Slabs.door_data.has(slabID) == false:
var doorSlabData = Slabs.fetch_doorslab_data(slabID)
if doorSlabData == null:
oMessage.big("Warning","You placed a Door Thing without a Door Slab. Switch to Slab Mode and place a Door Slab for proper functionality.")
return id

Expand Down
7 changes: 5 additions & 2 deletions Scenes/PickSlabWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ func add_slabs():
# The rest of them are added in any order (custom slabs)
for slabID in Slabs.data.keys():
if Slabs.slabOrder.has(slabID) == false:
if Slabs.door_data.has(slabID) == true:
if Slabs.door_data[slabID][Slabs.DOORSLAB_ORIENTATION] == 0:

var doorSlabData = Slabs.fetch_doorslab_data(slabID)
if doorSlabData:
if doorSlabData[Slabs.DOORSLAB_ORIENTATION] == 0:
continue

allSlabIDs.append(slabID)

for slabID in allSlabIDs:
Expand Down

0 comments on commit 3435ed3

Please sign in to comment.