Skip to content

Commit

Permalink
Custom doors
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Dec 2, 2023
1 parent 7ab310d commit a7e187a
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 123 deletions.
16 changes: 16 additions & 0 deletions Autoload/Slabs.gd
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ enum {
FAKE_RECOGNIZED_AS,
FAKE_WIBBLE_EDGES,
}
enum {
DOORSLAB_THING = 0,
DOORSLAB_ORIENTATION = 1,
}
#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],
}
var fake_extra_data = {
# 1000: [cube_data, floor_data, recognized_as, wibble_edges]
}
Expand Down
3 changes: 1 addition & 2 deletions Autoload/Things.gd
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ var DATA_EXTRA = {
1 : ["Action Point", null, null, preload("res://Art/ActionPoint.png"), null, TAB_ACTION],
2 : ["Light", null, null, preload("res://edited_images/GUIEDIT-1/PIC26.png"), null, TAB_EFFECTGEN],
}

var DATA_DOOR = {
var DATA_DOOR = { #
0 : [null, null, null, null, null, null],
1 : ["Wooden Door", null, null, preload("res://dk_images/trapdoor_64/door_pers_wood_std.png"), null, TAB_MISC],
2 : ["Braced Door", null, null, preload("res://dk_images/trapdoor_64/door_pers_braced_std.png"), null, TAB_MISC],
Expand Down
49 changes: 45 additions & 4 deletions Scenes/AddCustomSlabWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ onready var oFakeCustomColumnsPanelContainer = Nodelist.list["oFakeCustomColumns
onready var oSlabBitmaskOptionButton = Nodelist.list["oSlabBitmaskOptionButton"]
onready var oSlabIsSolidOptionButton = Nodelist.list["oSlabIsSolidOptionButton"]
onready var oSlabOwnableOptionButton = Nodelist.list["oSlabOwnableOptionButton"]
onready var oPassageLabel = Nodelist.list["oPassageLabel"]

onready var oCustomDoorThingLabel = Nodelist.list["oCustomDoorThingLabel"]
onready var oCustomDoorThing = Nodelist.list["oCustomDoorThing"]
onready var oCustomDoorThingEmptySpace = Nodelist.list["oCustomDoorThingEmptySpace"]
onready var oCustomDoorThingIDNameLabel = Nodelist.list["oCustomDoorThingIDNameLabel"]

var scnColumnSetter = preload('res://Scenes/ColumnSetter.tscn')
var customSlabArrayOfSpinbox = []
Expand All @@ -41,7 +46,7 @@ func _ready():
oGridContainerCustomColumns3x3.add_child(id)

_on_CustomSlabID_value_changed(oCustomSlabID.value)

_on_SlabBitmaskOptionButton_item_selected(0)

func _on_AddCustomSlabWindow_visibility_changed():
if visible == true:
Expand Down Expand Up @@ -106,15 +111,22 @@ func _on_AddCustomSlabButton_pressed():
"is_solid": bool(oSlabIsSolidOptionButton.get_selected_id()),
"ownable": bool(oSlabOwnableOptionButton.get_selected_id()),
}
if oSlabBitmaskOptionButton.get_selected_id() == Slabs.BITMASK_DOOR1:
slab_dict["door_thing"] = int(oCustomDoorThing.value)
slab_dict["door_orientation"] = 1

oCustomSlabSystem.add_custom_slab(slab_dict)

# Add DOOR 2 automatically
if oSlabBitmaskOptionButton.get_selected_id() == Slabs.BITMASK_DOOR1:
var second_slab_dict = slab_dict.duplicate(true)
var IdOfDoor2 = int(oCustomSlabID.value+1)
second_slab_dict.header_id = newID+1
second_slab_dict.recognized_as = IdOfDoor2
second_slab_dict["header_id"] = newID+1
second_slab_dict["recognized_as"] = IdOfDoor2
second_slab_dict["door_orientation"] = 0
second_slab_dict["bitmask"] = Slabs.BITMASK_DOOR2
oCustomSlabSystem.add_custom_slab(second_slab_dict)
oMessage.big("Note", "ID: " + str(IdOfDoor2) + " was also added, it's assumed to be the other door direction.")
oMessage.big("Note", "Slab ID: " + str(IdOfDoor2) + " was also added, it's assumed to be the other door direction.")

oPickSlabWindow.add_slabs()
oSlabTabs.current_tab = Slabs.TAB_CUSTOM
Expand Down Expand Up @@ -182,3 +194,32 @@ func _on_HelpCustomSlabsButton_pressed():
var helptext = ""
helptext += "After adding a custom slab, right click on its portrait within the slab selection window to remove it from the editor."
oMessage.big("Help",helptext)



func _on_SlabBitmaskOptionButton_item_selected(index):
if index == Slabs.BITMASK_DOOR1:
oSlabIsSolidOptionButton.selected = 0 # Empty

oSlabIsSolidOptionButton.visible = false
oPassageLabel.visible = false

oCustomDoorThingLabel.visible = true
oCustomDoorThing.visible = true
oCustomDoorThingEmptySpace.visible = true
oCustomDoorThingIDNameLabel.visible = true
else:
oSlabIsSolidOptionButton.visible = true
oPassageLabel.visible = true

oCustomDoorThingLabel.visible = false
oCustomDoorThing.visible = false
oCustomDoorThingEmptySpace.visible = false
oCustomDoorThingIDNameLabel.visible = false

func _on_CustomDoorThing_value_changed(value):
var doorIDName = "Unknown"
value = int(value)
if Things.DATA_DOOR.has(value):
doorIDName = Things.DATA_DOOR[value][Slabs.NAME]
oCustomDoorThingIDNameLabel.text = doorIDName
73 changes: 43 additions & 30 deletions Scenes/CustomSlabSystem.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,52 +45,65 @@ func load_file():
"floor_data": slabFloorData,
"bitmask": cfg.get_value(section, "bitmask", Slabs.BITMASK_FLOOR),
"is_solid": cfg.get_value(section, "is_solid", Slabs.FLOOR_SLAB),
"ownable": cfg.get_value(section, "ownable", Slabs.OWNABLE)
"ownable": cfg.get_value(section, "ownable", Slabs.OWNABLE),
}

var retrieve_value
retrieve_value = cfg.get_value(section, "door_thing", null) # Default = null
if retrieve_value != null: slab_dict["door_thing"] = retrieve_value
retrieve_value = cfg.get_value(section, "door_orientation", null)
if retrieve_value != null: slab_dict["door_orientation"] = retrieve_value

add_custom_slab(slab_dict)


func add_custom_slab(slab_dict):
#var newID = slab_dict.id
#var section = 'slab'+str(newID)
Slabs.data[slab_dict.header_id] = [
slab_dict.name,
slab_dict.is_solid,
slab_dict.bitmask,
var head_id = slab_dict["header_id"]
var section = 'slab'+str(head_id)
if head_id >= 1000:
Slabs.fake_extra_data[head_id] = [
slab_dict["cube_data"],
slab_dict["floor_data"],
slab_dict["recognized_as"],
slab_dict["wibble_edges"],
]
Slabs.data[head_id] = [
slab_dict["name"],
slab_dict["is_solid"],
slab_dict["bitmask"],
Slabs.PANEL_TOP_VIEW,
0, # SIDE_VIEW_Z_OFFSET
Slabs.TAB_CUSTOM,
slab_dict.wibble_type,
slab_dict.liquid_type,
slab_dict.ownable,
slab_dict["wibble_type"],
slab_dict["liquid_type"],
slab_dict["ownable"],
]
if slab_dict.header_id >= 1000:
Slabs.fake_extra_data[slab_dict.header_id] = [
slab_dict.cube_data,
slab_dict.floor_data,
slab_dict.recognized_as,
slab_dict.wibble_edges,
]
cfg.set_value(section,"name", slab_dict["name"])
cfg.set_value(section,"recognized_as", slab_dict["recognized_as"])
cfg.set_value(section,"liquid_type", slab_dict["liquid_type"])
cfg.set_value(section,"wibble_type", slab_dict["wibble_type"])
cfg.set_value(section,"wibble_edges", slab_dict["wibble_edges"])
cfg.set_value(section,"bitmask", slab_dict["bitmask"])
cfg.set_value(section,"is_solid", slab_dict["is_solid"])
cfg.set_value(section,"ownable", slab_dict["ownable"])

var section = 'slab'+str(slab_dict.header_id)
cfg.set_value(section,"name", slab_dict.name)
cfg.set_value(section,"recognized_as", slab_dict.recognized_as)
cfg.set_value(section,"liquid_type", slab_dict.liquid_type)
cfg.set_value(section,"wibble_type", slab_dict.wibble_type)
cfg.set_value(section,"wibble_edges", slab_dict.wibble_edges)
cfg.set_value(section,"bitmask", slab_dict.bitmask)
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"],
]

for i in 9:
if slab_dict.cube_data.size() > 0:
cfg.set_value(section,"cubes"+str(i),slab_dict.cube_data[i])
if slab_dict.floor_data.size() > 0:
cfg.set_value(section,"floor"+str(i),slab_dict.floor_data[i])
if slab_dict["cube_data"].size() > 0:
cfg.set_value(section,"cubes"+str(i),slab_dict["cube_data"][i])
if slab_dict["floor_data"].size() > 0:
cfg.set_value(section,"floor"+str(i),slab_dict["floor_data"][i])

cfg.save(Settings.unearthdata.plus_file("custom_slabs.cfg"))


func remove_custom_slab(header_id):
oPickSlabWindow.set_selection(null)
var statusOfRemoval = Slabs.data.erase(header_id)
Expand Down
31 changes: 5 additions & 26 deletions Scenes/Instances.gd
Original file line number Diff line number Diff line change
Expand Up @@ -294,32 +294,11 @@ func place_new_thing(newThingType, newSubtype, newPosition, newOwnership): # Pla
Things.TYPE.DOOR:
id.index = get_free_index_number()
id.doorLocked = oPlacingSettings.doorLocked
if newSubtype == 0: id.subtype = 1 #Depending on whether it was placed via autoslab or a hand placed Thing object.
match slabID:
Slabs.WOODEN_DOOR_1:
id.subtype = 1
id.doorOrientation = 1
Slabs.WOODEN_DOOR_2:
id.subtype = 1
id.doorOrientation = 0
Slabs.BRACED_DOOR_1:
id.subtype = 2
id.doorOrientation = 1
Slabs.BRACED_DOOR_2:
id.subtype = 2
id.doorOrientation = 0
Slabs.IRON_DOOR_1:
id.subtype = 3
id.doorOrientation = 1
Slabs.IRON_DOOR_2:
id.subtype = 3
id.doorOrientation = 0
Slabs.MAGIC_DOOR_1:
id.subtype = 4
id.doorOrientation = 1
Slabs.MAGIC_DOOR_2:
id.subtype = 4
id.doorOrientation = 0
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]

add_child(id)
#print('Thing placed in : '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')
Expand Down
Loading

0 comments on commit a7e187a

Please sign in to comment.