Skip to content

Commit 9b69417

Browse files
committed
slabset objects editable
1 parent f963283 commit 9b69417

File tree

3 files changed

+84
-59
lines changed

3 files changed

+84
-59
lines changed

Autoload/Slabset.gd

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
extends Node
22

3+
4+
35
var tng = []
46
var numberOfThings = 0
57

@@ -8,6 +10,18 @@ var dat = []
810
var blank_dat_entry = []
911
var CODETIME_START
1012

13+
enum obj {
14+
IS_LIGHT, # [0] IsLight [0-1]
15+
VARIATION, # [1] Variation
16+
SUBTILE, # [2] Subtile [0-9]
17+
RELATIVE_X, # [3] RelativeX
18+
RELATIVE_Y, # [4] RelativeY
19+
RELATIVE_Z, # [5] RelativeZ
20+
THING_TYPE, # [6] Thing type
21+
THING_SUBTYPE,# [7] Thing subtype
22+
EFFECT_RANGE # [8] Effect range
23+
}
24+
1125
enum dir {
1226
s = 0
1327
w = 1

Scenes/Instances.gd

+24-9
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,23 @@ func place_new_thing(newThingType, newSubtype, newPosition, newOwnership): # Pla
348348
id.locationY = locY
349349
return id
350350

351+
#Slabset.obj.IS_LIGHT, # [0] IsLight [0-1]
352+
#Slabset.obj.VARIATION, # [1] Variation
353+
#Slabset.obj.SUBTILE, # [2] Subtile [0-9]
354+
#Slabset.obj.RELATIVE_X, # [3] RelativeX
355+
#Slabset.obj.RELATIVE_Y, # [4] RelativeY
356+
#Slabset.obj.RELATIVE_Z, # [5] RelativeZ
357+
#Slabset.obj.THING_TYPE, # [6] Thing type
358+
#Slabset.obj.THING_SUBTYPE,# [7] Thing subtype
359+
#Slabset.obj.EFFECT_RANGE # [8] Effect range
360+
351361
func spawn(xSlab, ySlab, slabID, ownership, subtile, tngObj): # Spawns from tng file
352-
var id = thingScn.instance()
362+
var id
363+
if tngObj[Slabset.obj.IS_LIGHT] == 1:
364+
id = lightScn.instance()
365+
else:
366+
id = thingScn.instance()
367+
353368
id.data9 = 0
354369
id.data10 = 0
355370
id.data11_12 = 0
@@ -364,19 +379,19 @@ func spawn(xSlab, ySlab, slabID, ownership, subtile, tngObj): # Spawns from tng
364379

365380
var subtileY = subtile/3
366381
var subtileX = subtile-(subtileY*3)
367-
id.locationX = ((xSlab*3) + subtileX) + tngObj[3]
368-
id.locationY = ((ySlab*3) + subtileY) + tngObj[4]
369-
id.locationZ = tngObj[5]
382+
id.locationX = ((xSlab*3) + subtileX) + tngObj[Slabset.obj.RELATIVE_X]
383+
id.locationY = ((ySlab*3) + subtileY) + tngObj[Slabset.obj.RELATIVE_Y]
384+
id.locationZ = tngObj[Slabset.obj.RELATIVE_Z]
370385
id.sensitiveTile = (ySlab * M.xSize) + xSlab # Should this be M.ySize ???
371-
id.thingType = tngObj[6]
372-
id.subtype = tngObj[7]
386+
id.thingType = tngObj[Slabset.obj.THING_TYPE]
387+
id.subtype = tngObj[Slabset.obj.THING_SUBTYPE]
373388
id.ownership = ownership
374389

375390
if id.thingType == Things.TYPE.EFFECTGEN:
376-
id.effectRange = tngObj[8]
391+
id.effectRange = tngObj[Slabset.obj.EFFECT_RANGE]
377392

378393
if slabID == Slabs.GUARD_POST:
379-
if tngObj[7] == 115: # Guard Flag (Red)
394+
if tngObj[Slabset.obj.THING_SUBTYPE] == 115: # Guard Flag (Red)
380395
match ownership:
381396
0: pass # Red
382397
1: id.subtype = 116 # Blue
@@ -385,7 +400,7 @@ func spawn(xSlab, ySlab, slabID, ownership, subtile, tngObj): # Spawns from tng
385400
4: id.queue_free() # White
386401
5: id.subtype = 119 # None
387402
elif slabID == Slabs.DUNGEON_HEART:
388-
if tngObj[7] == 111: # Heart Flame (Red)
403+
if tngObj[Slabset.obj.THING_SUBTYPE] == 111: # Heart Flame (Red)
389404
match ownership:
390405
0: pass # Red
391406
1: id.subtype = 120 # Blue

Scenes/SlabsetWindow.gd

+46-50
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,6 @@ func _on_ExportSlabsetClmDialog_file_selected(filePath):
279279
else:
280280
oMessage.big("Error", "Couldn't save file, maybe try saving to another directory.")
281281

282-
# [0] IsLight [0-1]
283-
# [1] Variation
284-
# [2] Subtile [0-9]
285-
# [3] RelativeX
286-
# [4] RelativeY
287-
# [5] RelativeZ
288-
# [6] Thing type
289-
# [7] Thing subtype
290-
# [8] Effect range
291-
292282
func get_variation_objects(variation):
293283
if variation >= Slabset.tng.size():
294284
Slabset.tng.resize(variation+1)
@@ -301,34 +291,23 @@ func get_current_variation():
301291

302292
func update_slabthings():
303293
var variation = get_current_variation()
304-
var listOfObjectsOnThisVariation = get_variation_objects(variation)
305-
var hasObjects = listOfObjectsOnThisVariation.size() > 0
306-
oSlabsetObjectSection.visible = hasObjects
307-
if not hasObjects: return
308-
oObjObjectIndexSpinBox.visible = listOfObjectsOnThisVariation.size() > 1 # Hide ability to switch object index if there's only one object on this variation
294+
var listOfObjects = get_variation_objects(variation)
295+
oSlabsetObjectSection.visible = !listOfObjects.empty()
296+
297+
if listOfObjects.empty(): return
309298

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

313-
go_to_object(oObjObjectIndexSpinBox.value)
302+
update_object_fields(oObjObjectIndexSpinBox.value)
314303

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

319-
if value < 0 and listOfObjectsOnThisVariation.size() > 0:
320-
oObjObjectIndexSpinBox.value = maxIndex
321-
go_to_object(maxIndex)
322-
elif value > maxIndex:
323-
oObjObjectIndexSpinBox.value = 0
324-
go_to_object(0)
325-
else:
326-
go_to_object(value)
327-
328-
func go_to_object(index):
305+
func update_object_fields(index):
329306
var variation = get_current_variation()
330-
var listOfObjectsOnThisVariation = get_variation_objects(variation)
331-
var obj = listOfObjectsOnThisVariation[index] # Get first object on variation
307+
var listOfObjects = get_variation_objects(variation)
308+
if index >= listOfObjects.size(): return
309+
310+
var obj = listOfObjects[index] # Get first object on variation
332311
oObjThingTypeSpinBox.value = obj[6]
333312
oObjSubtypeSpinBox.value = obj[7]
334313
oObjIsLightCheckBox.pressed = bool(obj[0])
@@ -338,6 +317,20 @@ func go_to_object(index):
338317
oObjRelativeYSpinBox.value = obj[4]
339318
oObjRelativeZSpinBox.value = obj[5]
340319

320+
func _on_ObjObjectIndexSpinBox_value_changed(value):
321+
var listOfObjects = get_variation_objects(get_current_variation())
322+
var maxIndex = listOfObjects.size() - 1
323+
324+
if value < 0 and listOfObjects.size() > 0:
325+
oObjObjectIndexSpinBox.value = maxIndex
326+
update_object_fields(maxIndex)
327+
elif value > maxIndex:
328+
oObjObjectIndexSpinBox.value = 0
329+
update_object_fields(0)
330+
else:
331+
update_object_fields(value)
332+
333+
341334
func update_obj_name():
342335
if oObjIsLightCheckBox.pressed == true:
343336
oObjNameLabel.text = "Light"
@@ -350,29 +343,19 @@ func update_obj_name():
350343
oObjNameLabel.text = newName
351344
else:
352345
oObjNameLabel.text = "Name not found"
353-
#print("Error: Somehow subtype is missing from thing structure")
354-
#oMessage.quick("Error: Somehow subtype is missing from thing structure")
355346

356347
func _on_ObjAddButton_pressed():
357348
var variation = get_current_variation()
358349
add_new_object_to_variation(variation)
359350
update_slabthings()
360351

361352
func add_new_object_to_variation(variation):
362-
# IsLight [0-1]
363-
# Variation
364-
# Subtile [0-9]
365-
# RelativeX
366-
# RelativeY
367-
# RelativeZ
368-
# Thing type
369-
# Thing subtype
370-
# Effect range
353+
#update_object_property(Slabset.obj.VARIATION, variation)
371354
var new_object = [0,variation,4, 0,0,0, 1,1,0]
372355
get_variation_objects(variation).append(new_object)
373356
var lastEntryIndex = Slabset.tng[variation].size()-1
374357
oObjObjectIndexSpinBox.value = lastEntryIndex
375-
go_to_object(lastEntryIndex)
358+
update_object_fields(lastEntryIndex)
376359
update_obj_name()
377360

378361
func _on_ObjDeleteButton_pressed():
@@ -392,10 +375,12 @@ func _on_ObjThingTypeSpinBox_value_changed(value):
392375
oObjThingTypeSpinBox.hint_tooltip = Things.data_structure_name(value)
393376
#yield(get_tree(),'idle_frame')
394377
update_obj_name()
378+
update_object_property(Slabset.obj.THING_TYPE, value)
395379

396380
func _on_ObjSubtypeSpinBox_value_changed(value):
397381
#yield(get_tree(),'idle_frame')
398382
update_obj_name()
383+
update_object_property(Slabset.obj.THING_SUBTYPE, value)
399384

400385
func _on_ObjIsLightCheckBox_toggled(button_pressed):
401386
if button_pressed == true:
@@ -407,14 +392,25 @@ func _on_ObjIsLightCheckBox_toggled(button_pressed):
407392
oObjThingTypeLabel.modulate.a = 1
408393
oObjThingTypeSpinBox.modulate.a = 1
409394
update_obj_name()
395+
update_object_property(Slabset.obj.IS_LIGHT, int(button_pressed))
396+
410397

411398
func _on_ObjEffectRangeSpinBox_value_changed(value):
412-
pass # Replace with function body.
399+
update_object_property(Slabset.obj.EFFECT_RANGE, value)
413400
func _on_ObjSubtileSpinBox_value_changed(value):
414-
pass # Replace with function body.
401+
update_object_property(Slabset.obj.SUBTILE, value)
415402
func _on_ObjRelativeXSpinBox_value_changed(value):
416-
pass # Replace with function body.
403+
update_object_property(Slabset.obj.RELATIVE_X, value)
417404
func _on_ObjRelativeYSpinBox_value_changed(value):
418-
pass # Replace with function body.
405+
update_object_property(Slabset.obj.RELATIVE_Y, value)
419406
func _on_ObjRelativeZSpinBox_value_changed(value):
420-
pass # Replace with function body.
407+
update_object_property(Slabset.obj.RELATIVE_Z, value)
408+
409+
# Helper method to update the object in Slabset.tng
410+
func update_object_property(the_property, new_value):
411+
var variation = get_current_variation()
412+
var listOfObjects = get_variation_objects(variation)
413+
var object_index = oObjObjectIndexSpinBox.value
414+
if object_index < 0 or object_index >= listOfObjects.size():
415+
return # Invalid index, nothing to update
416+
listOfObjects[object_index][the_property] = new_value

0 commit comments

Comments
 (0)