Skip to content

Commit 74b5f85

Browse files
committed
add is_slab_edited function
1 parent fad71d5 commit 74b5f85

File tree

2 files changed

+90
-109
lines changed

2 files changed

+90
-109
lines changed

Autoload/Slabset.gd

+78-100
Original file line numberDiff line numberDiff line change
@@ -230,125 +230,88 @@ enum { # BitFlags
230230
SKIP_COLUMNS = 1,
231231
SKIP_OBJECTS = 2,
232232
}
233+
233234
func export_toml_slabset(filePath):
234235
var CODETIME_START = OS.get_ticks_msec()
235-
236-
# Find differences if not a full export
237-
var dat_diffs = []
238-
var tng_diffs = []
239-
dat_diffs = find_all_dat_differences()
240-
tng_diffs = find_all_tng_differences()
241-
if tng_diffs.size() == 0 and dat_diffs.size() == 0:
236+
237+
var list_of_modified_slabs = get_all_modified_slabs()
238+
239+
if list_of_modified_slabs.empty():
242240
oMessage.big("File wasn't saved", "You've made zero changes, so the file wasn't saved.")
243241
return
244-
245-
246-
247-
# # Print differences for debugging
248-
for i in tng_diffs:
249-
print("---------TNG differences---------")
250-
print("Current: ", tng[i])
251-
if i < default_data["tng"].size():
252-
print("Default: ", default_data["tng"][i])
253-
else:
254-
print("Default: Beyond array size")
255-
#
256-
# # Print differences for debugging
257-
# for i in dat_diffs:
258-
# print("---------DAT differences---------")
259-
# print("Current: ", dat[i])
260-
# if i < default_data["dat"].size():
261-
# print("Default: ", default_data["dat"][i])
262-
# else:
263-
# print("Default: Beyond array size")
264-
265-
var list_of_modified_slabs = []
266-
242+
267243
var lines = PoolStringArray()
268-
var totalSlabs = max(dat.size(), tng.size()) / 28
269-
for slabID in totalSlabs:
270-
var hasChanges = false
271-
272-
# Check if there are any changes within the 28 variations
244+
for slabID in list_of_modified_slabs:
245+
lines.append("[slab" + str(slabID) + "]")
246+
273247
for variationNumber in 28:
274248
var variation = slabID * 28 + variationNumber
275-
if dat_diffs.has(variation) or tng_diffs.has(variation):
276-
hasChanges = true
277-
break
278-
279-
if hasChanges == true:
280-
list_of_modified_slabs.append(slabID)
281-
lines.append("[slab" + str(slabID) + "]")
282-
283-
for variationNumber in 28:
284-
var variation = slabID * 28 + variationNumber
285-
var dirText = dir_texts[variationNumber]
286-
287-
lines.append("[slab" + str(slabID) + "." + dirText + "]")
288-
289-
lines.append("Columns = " + str(dat[variation]))
290-
291-
for object in tng[variation]:
292-
lines.append("")
293-
lines.append("[[slab" + str(slabID) + "." + dirText + "_objects" + "]]")
294-
for z in 9:
295-
var propertyName
296-
var value
297-
match z:
298-
0:
299-
propertyName = "IsLight"
300-
value = object[z]
301-
2:
302-
propertyName = "Subtile"
303-
value = object[z]
304-
3:
305-
propertyName = "RelativePosition"
306-
value = [ object[3], object[4], object[5] ]
307-
6:
308-
propertyName = "ThingType"
309-
value = object[z]
310-
7:
311-
propertyName = "Subtype"
312-
value = object[z]
313-
8:
314-
propertyName = "EffectRange"
315-
value = object[z]
316-
if propertyName:
317-
lines.append(propertyName + " = " + str(value))
318-
if tng[variation].size() == 0:
319-
lines.append("Objects = []")
320-
249+
var dirText = dir_texts[variationNumber]
250+
251+
lines.append("[slab" + str(slabID) + "." + dirText + "]")
252+
253+
lines.append("Columns = " + str(dat[variation]))
254+
255+
for object in tng[variation]:
321256
lines.append("")
257+
lines.append("[[slab" + str(slabID) + "." + dirText + "_objects" + "]]")
258+
for z in 9:
259+
var propertyName
260+
var value
261+
match z:
262+
0:
263+
propertyName = "IsLight"
264+
value = object[z]
265+
2:
266+
propertyName = "Subtile"
267+
value = object[z]
268+
3:
269+
propertyName = "RelativePosition"
270+
value = [ object[3], object[4], object[5] ]
271+
6:
272+
propertyName = "ThingType"
273+
value = object[z]
274+
7:
275+
propertyName = "Subtype"
276+
value = object[z]
277+
8:
278+
propertyName = "EffectRange"
279+
value = object[z]
280+
if propertyName:
281+
lines.append(propertyName + " = " + str(value))
282+
if tng[variation].size() == 0:
283+
lines.append("Objects = []")
284+
322285
lines.append("")
323-
286+
lines.append("")
287+
324288
var textFile = File.new()
325289
if textFile.open(filePath, File.WRITE) != OK:
326290
oMessage.big("Error", "Couldn't save file, maybe try saving to another directory.")
327291
return
328-
292+
329293
textFile.store_string("\n".join(lines))
330294
textFile.close()
331-
295+
332296
oMessage.quick("Saved: " + filePath)
333297
oMessage.quick("Saved Slab IDs: " + str(list_of_modified_slabs).replace("[","").replace("]",""))
334-
335-
print('Exported in: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms')
336-
337-
338-
func find_all_dat_differences():
339-
var diff_indices = []
340-
for variation in dat.size():
341-
if is_dat_variation_different(variation) == true:
342-
diff_indices.append(variation)
343-
return diff_indices
344298

299+
print('Exported in: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms')
345300

346-
func find_all_tng_differences():
347-
var diff_indices = []
348-
for variation in tng.size():
349-
if is_tng_variation_different(variation) == true:
350-
diff_indices.append(variation)
351-
return diff_indices
301+
func get_all_modified_slabs():
302+
var modified_slabs = []
303+
var totalSlabs = max(dat.size(), tng.size()) / 28
304+
for slabID in totalSlabs:
305+
if is_slab_edited(slabID):
306+
modified_slabs.append(slabID)
307+
return modified_slabs
308+
309+
func is_slab_edited(slabID):
310+
for variationNumber in 28:
311+
var variation = slabID * 28 + variationNumber
312+
if is_dat_variation_different(variation) or is_tng_variation_different(variation):
313+
return true
314+
return false
352315

353316

354317
func is_dat_variation_different(variation):
@@ -392,6 +355,21 @@ func is_tng_object_different(variation, objectIndex, objectProperty):
392355
return tng[variation][objectIndex][objectProperty] != default_data["tng"][variation][objectIndex][objectProperty]
393356

394357

358+
#func find_all_dat_differences():
359+
# var diff_indices = []
360+
# for variation in dat.size():
361+
# if is_dat_variation_different(variation) == true:
362+
# diff_indices.append(variation)
363+
# return diff_indices
364+
#
365+
#func find_all_tng_differences():
366+
# var diff_indices = []
367+
# for variation in tng.size():
368+
# if is_tng_variation_different(variation) == true:
369+
# diff_indices.append(variation)
370+
# return diff_indices
371+
372+
395373
var dir_texts = {
396374
0: 'S',
397375
1: 'W',

Scenes/SlabsetWindow.gd

+12-9
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ func _on_SlabsetIDSpinBox_value_changed(value):
185185
if Slabs.data.has(value):
186186
slabName = Slabs.data[value][Slabs.NAME]
187187
oSlabsetIDLabel.text = slabName
188-
update_columns_ui()
188+
update_column_spinboxes()
189189

190190
func _on_VariationNumberSpinBox_value_changed(value):
191-
update_columns_ui()
191+
update_column_spinboxes()
192192

193-
func update_columns_ui():
193+
func update_column_spinboxes():
194194
var variation = get_current_variation()
195195

196196
for subtile in columnSettersArray.size():
@@ -271,7 +271,7 @@ func _on_ExportColumnsetTomlDialog_file_selected(filePath):
271271
#func _on_ImportSlabsetTomlDialog_file_selected(filePath):
272272
# var fullImport = false
273273
# Slabset.import_toml_slabset(filePath, fullImport, true)
274-
# update_columns_ui()
274+
# update_column_spinboxes()
275275
# update_objects_ui()
276276
#
277277
#func _on_ImportColumnsetTomlDialog_file_selected(filePath):
@@ -516,6 +516,7 @@ func _on_ObjThingTypeSpinBox_value_changed(value:int):
516516
#oObjThingTypeSpinBox.hint_tooltip = Things.data_structure_name.get(value, "?")
517517
#yield(get_tree(),'idle_frame')
518518

519+
# Lock value to 1 or 7
519520
if value in [0, 2, 7]:
520521
value = 7
521522
else:
@@ -670,7 +671,7 @@ func paste(howMany):
670671
Slabset.tng[i] = clipboard["tng"][clipboard_index].duplicate(true)
671672

672673
# Update the UI after pasting
673-
update_columns_ui()
674+
update_column_spinboxes()
674675
update_objects_ui()
675676
oDkSlabsetVoxelView._on_SlabsetIDSpinBox_value_changed(oSlabsetIDSpinBox.value)
676677

@@ -707,7 +708,7 @@ func _on_VarRotateButton_pressed():
707708
obj[Slabset.obj.SUBTILE] = ROTATION_MAP[obj[Slabset.obj.SUBTILE]]
708709

709710
# Update the UI
710-
update_columns_ui()
711+
update_column_spinboxes()
711712
update_objects_ui()
712713
oMessage.quick("Rotated variation")
713714

@@ -747,9 +748,11 @@ func revert(howMany):
747748
else:
748749
if variation < Slabset.tng.size():
749750
Slabset.tng.remove(variation)
750-
751-
update_columns_ui() # Update UI for columns
751+
update_column_spinboxes() # Update UI for columns
752752
update_objects_ui() # Update UI for objects
753+
754+
yield(get_tree(),'idle_frame')
755+
oDkSlabsetVoxelView.refresh_entire_view()
753756

754757

755758

@@ -771,7 +774,7 @@ func revert(howMany):
771774
# Slabset.tng[next_free_variation] = Slabset.tng[current_variation].duplicate(true) # true for deep copy if needed
772775
#
773776
# # Update UI to reflect the new duplicated variation
774-
# update_columns_ui() # Assuming this updates the UI with new column data
777+
# update_column_spinboxes() # Assuming this updates the UI with new column data
775778
# update_objects_ui() # Assuming this updates the UI with new things/objects
776779
# oMessage.quick("Variation duplicated into SlabID: " + str(next_free_variation/28) + ", Variation: " + str(next_free_variation % 28))
777780
#

0 commit comments

Comments
 (0)