@@ -279,16 +279,6 @@ func _on_ExportSlabsetClmDialog_file_selected(filePath):
279
279
else :
280
280
oMessage.big(" Error" , " Couldn't save file, maybe try saving to another directory." )
281
281
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
-
292
282
func get_variation_objects(variation):
293
283
if variation >= Slabset.tng.size():
294
284
Slabset.tng.resize(variation+ 1 )
@@ -301,34 +291,23 @@ func get_current_variation():
301
291
302
292
func update_slabthings():
303
293
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
309
298
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 )
312
301
313
- go_to_object (oObjObjectIndexSpinBox.value)
302
+ update_object_fields (oObjObjectIndexSpinBox.value)
314
303
315
- func _on_ObjObjectIndexSpinBox_value_changed(value):
316
- var listOfObjectsOnThisVariation = get_variation_objects(get_current_variation())
317
- var maxIndex = listOfObjectsOnThisVariation.size() - 1
318
304
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):
329
306
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
332
311
oObjThingTypeSpinBox.value = obj[ 6 ]
333
312
oObjSubtypeSpinBox.value = obj[ 7 ]
334
313
oObjIsLightCheckBox.pressed = bool(obj[ 0 ] )
@@ -338,6 +317,20 @@ func go_to_object(index):
338
317
oObjRelativeYSpinBox.value = obj[ 4 ]
339
318
oObjRelativeZSpinBox.value = obj[ 5 ]
340
319
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
+
341
334
func update_obj_name():
342
335
if oObjIsLightCheckBox.pressed == true :
343
336
oObjNameLabel.text = " Light"
@@ -350,29 +343,19 @@ func update_obj_name():
350
343
oObjNameLabel.text = newName
351
344
else :
352
345
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")
355
346
356
347
func _on_ObjAddButton_pressed():
357
348
var variation = get_current_variation()
358
349
add_new_object_to_variation(variation)
359
350
update_slabthings()
360
351
361
352
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)
371
354
var new_object = [ 0 ,variation,4 , 0 ,0 ,0 , 1 ,1 ,0 ]
372
355
get_variation_objects(variation).append(new_object)
373
356
var lastEntryIndex = Slabset.tng[ variation] .size()- 1
374
357
oObjObjectIndexSpinBox.value = lastEntryIndex
375
- go_to_object (lastEntryIndex)
358
+ update_object_fields (lastEntryIndex)
376
359
update_obj_name()
377
360
378
361
func _on_ObjDeleteButton_pressed():
@@ -392,10 +375,12 @@ func _on_ObjThingTypeSpinBox_value_changed(value):
392
375
oObjThingTypeSpinBox.hint_tooltip = Things.data_structure_name(value)
393
376
# yield(get_tree(),'idle_frame')
394
377
update_obj_name()
378
+ update_object_property(Slabset.obj.THING_TYPE, value)
395
379
396
380
func _on_ObjSubtypeSpinBox_value_changed(value):
397
381
# yield(get_tree(),'idle_frame')
398
382
update_obj_name()
383
+ update_object_property(Slabset.obj.THING_SUBTYPE, value)
399
384
400
385
func _on_ObjIsLightCheckBox_toggled(button_pressed):
401
386
if button_pressed == true :
@@ -407,14 +392,25 @@ func _on_ObjIsLightCheckBox_toggled(button_pressed):
407
392
oObjThingTypeLabel.modulate.a = 1
408
393
oObjThingTypeSpinBox.modulate.a = 1
409
394
update_obj_name()
395
+ update_object_property(Slabset.obj.IS_LIGHT, int(button_pressed))
396
+
410
397
411
398
func _on_ObjEffectRangeSpinBox_value_changed(value):
412
- pass # Replace with function body.
399
+ update_object_property(Slabset.obj.EFFECT_RANGE, value)
413
400
func _on_ObjSubtileSpinBox_value_changed(value):
414
- pass # Replace with function body.
401
+ update_object_property(Slabset.obj.SUBTILE, value)
415
402
func _on_ObjRelativeXSpinBox_value_changed(value):
416
- pass # Replace with function body.
403
+ update_object_property(Slabset.obj.RELATIVE_X, value)
417
404
func _on_ObjRelativeYSpinBox_value_changed(value):
418
- pass # Replace with function body.
405
+ update_object_property(Slabset.obj.RELATIVE_Y, value)
419
406
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