Skip to content

Commit

Permalink
Custom slab window
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Nov 21, 2023
1 parent 1c7cc29 commit d94a81a
Show file tree
Hide file tree
Showing 9 changed files with 334 additions and 209 deletions.
16 changes: 8 additions & 8 deletions Autoload/Columnset.gd
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func import_cfg_columnset(filePath, fullExport):
for section in cfg.get_sections():
if section.begins_with("column"):
var columnIndex = int(section)
utilized[columnIndex] = cfg.get_value(section, "Utilized", 0)
permanent[columnIndex] = cfg.get_value(section, "Permanent", 0)
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)
Expand Down Expand Up @@ -113,8 +113,8 @@ func export_cfg_columnset(filePath, fullExport): #"res://columns.cfg"
continue

textFile.store_line('[column' + str(i) +']')
textFile.store_line('Utilized = ' + str(Columnset.utilized[i])) #(0-1)
textFile.store_line('Permanent = ' + str(Columnset.permanent[i])) #(2)
# textFile.store_line('Utilized = ' + str(Columnset.utilized[i])) #(0-1)
# textFile.store_line('Permanent = ' + str(Columnset.permanent[i])) #(2)
textFile.store_line('Lintel = ' + str(Columnset.lintel[i])) #(2)
textFile.store_line('Height = ' + str(Columnset.height[i])) #(2)
textFile.store_line('SolidMask = ' + str(Columnset.solidMask[i])) #(3-4)
Expand All @@ -134,10 +134,10 @@ func find_all_different_columns():
return diff_indices

func is_column_different(index):
if utilized[index] != default_data["utilized"][index]:
return true
if permanent[index] != default_data["permanent"][index]:
return true
# if utilized[index] != default_data["utilized"][index]:
# return true
# if permanent[index] != default_data["permanent"][index]:
# return true
if lintel[index] != default_data["lintel"][index]:
return true
if height[index] != default_data["height"][index]:
Expand Down
44 changes: 31 additions & 13 deletions Scenes/TabCustomSlabs.gd → Scenes/AddCustomSlabWindow.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extends HBoxContainer
onready var oGridContainerCustomColumns3x3 = Nodelist.list["oGridContainerCustomColumns3x3"]
extends WindowDialog
onready var oColumnEditorVoxelView = Nodelist.list["oColumnEditorVoxelView"]
onready var oCustomSlabVoxelView = Nodelist.list["oCustomSlabVoxelView"]
onready var oGridContainerCustomColumns3x3 = Nodelist.list["oGridContainerCustomColumns3x3"]
onready var oSlabRecognizedAs = Nodelist.list["oSlabRecognizedAs"]
onready var oSlabRecognizedAsName = Nodelist.list["oSlabRecognizedAsName"]
onready var oCustomSlabsTab = Nodelist.list["oCustomSlabsTab"]
onready var oPickSlabWindow = Nodelist.list["oPickSlabWindow"]
onready var oCustomSlabSystem = Nodelist.list["oCustomSlabSystem"]
onready var oNewSlabName = Nodelist.list["oNewSlabName"]
Expand All @@ -14,10 +14,10 @@ onready var oSlabWibbleOptionButton = Nodelist.list["oSlabWibbleOptionButton"]
onready var oSlabLiquidOptionButton = Nodelist.list["oSlabLiquidOptionButton"]
onready var oWibbleEdgesCheckBox = Nodelist.list["oWibbleEdgesCheckBox"]
onready var oWibbleEdgesSpacing = Nodelist.list["oWibbleEdgesSpacing"]
onready var oColumnEditorTabs = Nodelist.list["oColumnEditorTabs"]
onready var oColumnEditorControls = Nodelist.list["oColumnEditorControls"]
onready var oSlabsetWindow = Nodelist.list["oSlabsetWindow"]
onready var oDataClmPos = Nodelist.list["oDataClmPos"]
onready var oColumnEditor = Nodelist.list["oColumnEditor"]

var scnColumnSetter = preload('res://Scenes/ColumnSetter.tscn')
var customSlabArrayOfSpinbox = []
Expand All @@ -35,10 +35,15 @@ func _ready():

_on_SlabRecognizedAs_value_changed(oSlabRecognizedAs.value)

func _on_AddCustomSlabWindow_visibility_changed():
if visible == true:
oCustomSlabVoxelView.initialize()

func shortcut_pressed(id):
var spinbox = id.get_node("CustomSpinBox")
var clmIndex = spinbox.value
oColumnEditorTabs.set_current_tab(0)

Utils.popup_centered(oColumnEditor)
oColumnEditorControls.oColumnIndexSpinBox.value = clmIndex

func _on_SlabRecognizedAs_value_changed(value):
Expand Down Expand Up @@ -77,14 +82,6 @@ func _on_AddCustomSlabButton_pressed():
oSlabTabs.current_tab = Slabs.TAB_CUSTOM
oPickSlabWindow.set_selection(newID)

func _on_HelpCustomSlabsButton_pressed():
var helptext = ""
helptext += "With a few exceptions, most Fake Slabs will reset their appearance in-game when placing or claiming an adjacent slab. To avoid this, set 'Recognized as' to one of the following: Slab 50, Impenetrable Rock, Gold, Bridge, Gems, Guard post, Doors (without door object). Needs further testing."
helptext += "\n\n"
helptext += "After adding one, right click on its portrait within the slab selection window to remove Fake Slabs from the editor."
helptext += "\n\n"
helptext += "Right click on the map while the Fake Slab menu is open to copy column index numbers into the window."
oMessage.big("Help",helptext)


func _on_SlabWibbleOptionButton_item_selected(index):
Expand Down Expand Up @@ -112,3 +109,24 @@ func get_column_indexes_on_tile(cursorTile):
var i = (ySubtile*3) + xSubtile
customSlabArrayOfSpinbox[i].value = newIndex




func _on_FakeSlabHelpButton_pressed():
var helptext = ""
helptext += "Fake slabs will work in any solo map.\n"
helptext += "They typically reset their appearance when placing or claiming an adjacent slab.\n"
helptext += "Set 'Slab ID' to Slab 50 to prevent the appearance from changing.\n"
helptext += "There's a few other IDs you can use which may not reset: Impenetrable Rock, Gold, Bridge, Gems, Guard post. But this needs further testing.\n\n"
helptext += "Right click on the map while the Fake slab menu is open to copy column index numbers into the window."
oMessage.big("Help",helptext)

func _on_SlabsetSlabHelpButton_pressed():
var helptext = ""
helptext += "Slabset slabs will only work in a campaign/mappack. It requires the slabset.cfg and columnset.cfg files to be in the correct place."
oMessage.big("Help",helptext)

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)
80 changes: 48 additions & 32 deletions Scenes/CustomSlabSystem.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
extends Node
onready var oDataClm = Nodelist.list["oDataClm"]
onready var oPickSlabWindow = Nodelist.list["oPickSlabWindow"]
onready var oMessage = Nodelist.list["oMessage"]

var data = {}
var slabsFile = ConfigFile.new()
var cfg = ConfigFile.new()

enum {
RECOGNIZED_AS
Expand All @@ -15,7 +16,40 @@ enum {
func _ready():
load_file()


func load_file():
var filePath = Settings.unearthdata.plus_file("custom_slabs.cfg")

var file = File.new()
if file.open(filePath, File.READ) != OK:
# No custom_slabs.cfg file found
return

var fileText = file.get_as_text().to_lower()
var err = cfg.parse(fileText)
if err != OK:
oMessage.big("Error", "Failed to parse custom_slabs.cfg file")
return

for section in cfg.get_sections():
var newID = int(section.trim_prefix("slab"))
var slabName = cfg.get_value(section, "name")
var recognizedAs = cfg.get_value(section, "recognized_as")
var liquidType = cfg.get_value(section, "liquid_type")
var wibbleType = cfg.get_value(section, "wibble_type")
var wibbleEdges = cfg.get_value(section, "wibble_edges")

var slabCubeData = []
var slabFloorData = []
for i in 9:
slabCubeData.append( cfg.get_value(section, "cubes"+str(i)) )
slabFloorData.append( cfg.get_value(section, "floor"+str(i)) )

add_custom_slab(newID, slabName, recognizedAs, liquidType, wibbleType, wibbleEdges, slabCubeData, slabFloorData)


func add_custom_slab(newID, slabName, recognizedAs, liquidType, wibbleType, wibbleEdges, slabCubeData, slabFloorData):

Slabs.data[newID] = [
slabName,
Slabs.BLOCK_SLAB,
Expand All @@ -29,37 +63,19 @@ func add_custom_slab(newID, slabName, recognizedAs, liquidType, wibbleType, wibb
]

data[newID] = [recognizedAs, wibbleEdges, slabCubeData, slabFloorData]

slabsFile.set_value('SLAB'+str(newID),"NAME", slabName)
slabsFile.set_value('SLAB'+str(newID),"RECOGNIZED_AS",int(recognizedAs))
slabsFile.set_value('SLAB'+str(newID),"LIQUID_TYPE", liquidType)
slabsFile.set_value('SLAB'+str(newID),"WIBBLE_TYPE", wibbleType)
slabsFile.set_value('SLAB'+str(newID),"WIBBLE_EDGES", wibbleEdges)
var section = 'slab'+str(newID)
cfg.set_value(section,"name", slabName)
cfg.set_value(section,"recognized_as",int(recognizedAs))
cfg.set_value(section,"liquid_type", liquidType)
cfg.set_value(section,"wibble_type", wibbleType)
cfg.set_value(section,"wibble_edges", wibbleEdges)

for i in 9:
slabsFile.set_value('SLAB'+str(newID),"CUBES"+str(i),slabCubeData[i])
slabsFile.set_value('SLAB'+str(newID),"FLOOR"+str(i),slabFloorData[i])
cfg.set_value(section,"cubes"+str(i),slabCubeData[i])
cfg.set_value(section,"floor"+str(i),slabFloorData[i])

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

func load_file():
slabsFile.load(Settings.unearthdata.plus_file("custom_slabs.cfg"))

for sectionName in slabsFile.get_sections():
var newID = int(sectionName.trim_prefix("SLAB"))
var slabName = slabsFile.get_value(sectionName, "NAME")
var recognizedAs = slabsFile.get_value(sectionName, "RECOGNIZED_AS")
var liquidType = slabsFile.get_value(sectionName, "LIQUID_TYPE")
var wibbleType = slabsFile.get_value(sectionName, "WIBBLE_TYPE")
var wibbleEdges = slabsFile.get_value(sectionName, "WIBBLE_EDGES")

var slabCubeData = []
var slabFloorData = []
for i in 9:
slabCubeData.append( slabsFile.get_value(sectionName, "CUBES"+str(i)) )
slabFloorData.append( slabsFile.get_value(sectionName, "FLOOR"+str(i)) )

add_custom_slab(newID, slabName, recognizedAs, liquidType, wibbleType, wibbleEdges, slabCubeData, slabFloorData)

# The purpose of this function is so I don't have to index the columns into clm for simply displaying within the slab window. Only index when PLACING the Fake Slab.
func get_top_cube_face(indexIn3x3, slabID):
Expand All @@ -82,8 +98,8 @@ func remove_custom_slab(slabID):
if data.has(slabID):
data.erase(slabID)

var section = 'SLAB'+str(slabID)
if slabsFile.has_section(section):
slabsFile.erase_section(section)
var section = 'slab'+str(slabID)
if cfg.has_section(section):
cfg.erase_section(section)

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

0 comments on commit d94a81a

Please sign in to comment.