Skip to content

Commit

Permalink
slabset objects editable
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Nov 12, 2023
1 parent f963283 commit 9b69417
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 59 deletions.
14 changes: 14 additions & 0 deletions Autoload/Slabset.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extends Node



var tng = []
var numberOfThings = 0

Expand All @@ -8,6 +10,18 @@ var dat = []
var blank_dat_entry = []
var CODETIME_START

enum obj {
IS_LIGHT, # [0] IsLight [0-1]
VARIATION, # [1] Variation
SUBTILE, # [2] Subtile [0-9]
RELATIVE_X, # [3] RelativeX
RELATIVE_Y, # [4] RelativeY
RELATIVE_Z, # [5] RelativeZ
THING_TYPE, # [6] Thing type
THING_SUBTYPE,# [7] Thing subtype
EFFECT_RANGE # [8] Effect range
}

enum dir {
s = 0
w = 1
Expand Down
33 changes: 24 additions & 9 deletions Scenes/Instances.gd
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,23 @@ func place_new_thing(newThingType, newSubtype, newPosition, newOwnership): # Pla
id.locationY = locY
return id

#Slabset.obj.IS_LIGHT, # [0] IsLight [0-1]
#Slabset.obj.VARIATION, # [1] Variation
#Slabset.obj.SUBTILE, # [2] Subtile [0-9]
#Slabset.obj.RELATIVE_X, # [3] RelativeX
#Slabset.obj.RELATIVE_Y, # [4] RelativeY
#Slabset.obj.RELATIVE_Z, # [5] RelativeZ
#Slabset.obj.THING_TYPE, # [6] Thing type
#Slabset.obj.THING_SUBTYPE,# [7] Thing subtype
#Slabset.obj.EFFECT_RANGE # [8] Effect range

func spawn(xSlab, ySlab, slabID, ownership, subtile, tngObj): # Spawns from tng file
var id = thingScn.instance()
var id
if tngObj[Slabset.obj.IS_LIGHT] == 1:
id = lightScn.instance()
else:
id = thingScn.instance()

id.data9 = 0
id.data10 = 0
id.data11_12 = 0
Expand All @@ -364,19 +379,19 @@ func spawn(xSlab, ySlab, slabID, ownership, subtile, tngObj): # Spawns from tng

var subtileY = subtile/3
var subtileX = subtile-(subtileY*3)
id.locationX = ((xSlab*3) + subtileX) + tngObj[3]
id.locationY = ((ySlab*3) + subtileY) + tngObj[4]
id.locationZ = tngObj[5]
id.locationX = ((xSlab*3) + subtileX) + tngObj[Slabset.obj.RELATIVE_X]
id.locationY = ((ySlab*3) + subtileY) + tngObj[Slabset.obj.RELATIVE_Y]
id.locationZ = tngObj[Slabset.obj.RELATIVE_Z]
id.sensitiveTile = (ySlab * M.xSize) + xSlab # Should this be M.ySize ???
id.thingType = tngObj[6]
id.subtype = tngObj[7]
id.thingType = tngObj[Slabset.obj.THING_TYPE]
id.subtype = tngObj[Slabset.obj.THING_SUBTYPE]
id.ownership = ownership

if id.thingType == Things.TYPE.EFFECTGEN:
id.effectRange = tngObj[8]
id.effectRange = tngObj[Slabset.obj.EFFECT_RANGE]

if slabID == Slabs.GUARD_POST:
if tngObj[7] == 115: # Guard Flag (Red)
if tngObj[Slabset.obj.THING_SUBTYPE] == 115: # Guard Flag (Red)
match ownership:
0: pass # Red
1: id.subtype = 116 # Blue
Expand All @@ -385,7 +400,7 @@ func spawn(xSlab, ySlab, slabID, ownership, subtile, tngObj): # Spawns from tng
4: id.queue_free() # White
5: id.subtype = 119 # None
elif slabID == Slabs.DUNGEON_HEART:
if tngObj[7] == 111: # Heart Flame (Red)
if tngObj[Slabset.obj.THING_SUBTYPE] == 111: # Heart Flame (Red)
match ownership:
0: pass # Red
1: id.subtype = 120 # Blue
Expand Down
96 changes: 46 additions & 50 deletions Scenes/SlabsetWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,6 @@ func _on_ExportSlabsetClmDialog_file_selected(filePath):
else:
oMessage.big("Error", "Couldn't save file, maybe try saving to another directory.")

# [0] IsLight [0-1]
# [1] Variation
# [2] Subtile [0-9]
# [3] RelativeX
# [4] RelativeY
# [5] RelativeZ
# [6] Thing type
# [7] Thing subtype
# [8] Effect range

func get_variation_objects(variation):
if variation >= Slabset.tng.size():
Slabset.tng.resize(variation+1)
Expand All @@ -301,34 +291,23 @@ func get_current_variation():

func update_slabthings():
var variation = get_current_variation()
var listOfObjectsOnThisVariation = get_variation_objects(variation)
var hasObjects = listOfObjectsOnThisVariation.size() > 0
oSlabsetObjectSection.visible = hasObjects
if not hasObjects: return
oObjObjectIndexSpinBox.visible = listOfObjectsOnThisVariation.size() > 1 # Hide ability to switch object index if there's only one object on this variation
var listOfObjects = get_variation_objects(variation)
oSlabsetObjectSection.visible = !listOfObjects.empty()

if listOfObjects.empty(): return

if oObjObjectIndexSpinBox.value >= listOfObjectsOnThisVariation.size():
oObjObjectIndexSpinBox.value = max(0, listOfObjectsOnThisVariation.size() - 1)
oObjObjectIndexSpinBox.visible = listOfObjects.size() > 1 # Hide ability to switch object index if there's only one object on this variation
oObjObjectIndexSpinBox.value = clamp(oObjObjectIndexSpinBox.value, 0, listOfObjects.size() - 1)

go_to_object(oObjObjectIndexSpinBox.value)
update_object_fields(oObjObjectIndexSpinBox.value)

func _on_ObjObjectIndexSpinBox_value_changed(value):
var listOfObjectsOnThisVariation = get_variation_objects(get_current_variation())
var maxIndex = listOfObjectsOnThisVariation.size() - 1

if value < 0 and listOfObjectsOnThisVariation.size() > 0:
oObjObjectIndexSpinBox.value = maxIndex
go_to_object(maxIndex)
elif value > maxIndex:
oObjObjectIndexSpinBox.value = 0
go_to_object(0)
else:
go_to_object(value)

func go_to_object(index):
func update_object_fields(index):
var variation = get_current_variation()
var listOfObjectsOnThisVariation = get_variation_objects(variation)
var obj = listOfObjectsOnThisVariation[index] # Get first object on variation
var listOfObjects = get_variation_objects(variation)
if index >= listOfObjects.size(): return

var obj = listOfObjects[index] # Get first object on variation
oObjThingTypeSpinBox.value = obj[6]
oObjSubtypeSpinBox.value = obj[7]
oObjIsLightCheckBox.pressed = bool(obj[0])
Expand All @@ -338,6 +317,20 @@ func go_to_object(index):
oObjRelativeYSpinBox.value = obj[4]
oObjRelativeZSpinBox.value = obj[5]

func _on_ObjObjectIndexSpinBox_value_changed(value):
var listOfObjects = get_variation_objects(get_current_variation())
var maxIndex = listOfObjects.size() - 1

if value < 0 and listOfObjects.size() > 0:
oObjObjectIndexSpinBox.value = maxIndex
update_object_fields(maxIndex)
elif value > maxIndex:
oObjObjectIndexSpinBox.value = 0
update_object_fields(0)
else:
update_object_fields(value)


func update_obj_name():
if oObjIsLightCheckBox.pressed == true:
oObjNameLabel.text = "Light"
Expand All @@ -350,29 +343,19 @@ func update_obj_name():
oObjNameLabel.text = newName
else:
oObjNameLabel.text = "Name not found"
#print("Error: Somehow subtype is missing from thing structure")
#oMessage.quick("Error: Somehow subtype is missing from thing structure")

func _on_ObjAddButton_pressed():
var variation = get_current_variation()
add_new_object_to_variation(variation)
update_slabthings()

func add_new_object_to_variation(variation):
# IsLight [0-1]
# Variation
# Subtile [0-9]
# RelativeX
# RelativeY
# RelativeZ
# Thing type
# Thing subtype
# Effect range
#update_object_property(Slabset.obj.VARIATION, variation)
var new_object = [0,variation,4, 0,0,0, 1,1,0]
get_variation_objects(variation).append(new_object)
var lastEntryIndex = Slabset.tng[variation].size()-1
oObjObjectIndexSpinBox.value = lastEntryIndex
go_to_object(lastEntryIndex)
update_object_fields(lastEntryIndex)
update_obj_name()

func _on_ObjDeleteButton_pressed():
Expand All @@ -392,10 +375,12 @@ func _on_ObjThingTypeSpinBox_value_changed(value):
oObjThingTypeSpinBox.hint_tooltip = Things.data_structure_name(value)
#yield(get_tree(),'idle_frame')
update_obj_name()
update_object_property(Slabset.obj.THING_TYPE, value)

func _on_ObjSubtypeSpinBox_value_changed(value):
#yield(get_tree(),'idle_frame')
update_obj_name()
update_object_property(Slabset.obj.THING_SUBTYPE, value)

func _on_ObjIsLightCheckBox_toggled(button_pressed):
if button_pressed == true:
Expand All @@ -407,14 +392,25 @@ func _on_ObjIsLightCheckBox_toggled(button_pressed):
oObjThingTypeLabel.modulate.a = 1
oObjThingTypeSpinBox.modulate.a = 1
update_obj_name()
update_object_property(Slabset.obj.IS_LIGHT, int(button_pressed))


func _on_ObjEffectRangeSpinBox_value_changed(value):
pass # Replace with function body.
update_object_property(Slabset.obj.EFFECT_RANGE, value)
func _on_ObjSubtileSpinBox_value_changed(value):
pass # Replace with function body.
update_object_property(Slabset.obj.SUBTILE, value)
func _on_ObjRelativeXSpinBox_value_changed(value):
pass # Replace with function body.
update_object_property(Slabset.obj.RELATIVE_X, value)
func _on_ObjRelativeYSpinBox_value_changed(value):
pass # Replace with function body.
update_object_property(Slabset.obj.RELATIVE_Y, value)
func _on_ObjRelativeZSpinBox_value_changed(value):
pass # Replace with function body.
update_object_property(Slabset.obj.RELATIVE_Z, value)

# Helper method to update the object in Slabset.tng
func update_object_property(the_property, new_value):
var variation = get_current_variation()
var listOfObjects = get_variation_objects(variation)
var object_index = oObjObjectIndexSpinBox.value
if object_index < 0 or object_index >= listOfObjects.size():
return # Invalid index, nothing to update
listOfObjects[object_index][the_property] = new_value

0 comments on commit 9b69417

Please sign in to comment.