Skip to content

Commit

Permalink
add is_slab_edited function
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Jun 2, 2024
1 parent fad71d5 commit 74b5f85
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 109 deletions.
178 changes: 78 additions & 100 deletions Autoload/Slabset.gd
Original file line number Diff line number Diff line change
Expand Up @@ -230,125 +230,88 @@ enum { # BitFlags
SKIP_COLUMNS = 1,
SKIP_OBJECTS = 2,
}

func export_toml_slabset(filePath):
var CODETIME_START = OS.get_ticks_msec()

# Find differences if not a full export
var dat_diffs = []
var tng_diffs = []
dat_diffs = find_all_dat_differences()
tng_diffs = find_all_tng_differences()
if tng_diffs.size() == 0 and dat_diffs.size() == 0:

var list_of_modified_slabs = get_all_modified_slabs()

if list_of_modified_slabs.empty():
oMessage.big("File wasn't saved", "You've made zero changes, so the file wasn't saved.")
return



# # Print differences for debugging
for i in tng_diffs:
print("---------TNG differences---------")
print("Current: ", tng[i])
if i < default_data["tng"].size():
print("Default: ", default_data["tng"][i])
else:
print("Default: Beyond array size")
#
# # Print differences for debugging
# for i in dat_diffs:
# print("---------DAT differences---------")
# print("Current: ", dat[i])
# if i < default_data["dat"].size():
# print("Default: ", default_data["dat"][i])
# else:
# print("Default: Beyond array size")

var list_of_modified_slabs = []


var lines = PoolStringArray()
var totalSlabs = max(dat.size(), tng.size()) / 28
for slabID in totalSlabs:
var hasChanges = false

# Check if there are any changes within the 28 variations
for slabID in list_of_modified_slabs:
lines.append("[slab" + str(slabID) + "]")

for variationNumber in 28:
var variation = slabID * 28 + variationNumber
if dat_diffs.has(variation) or tng_diffs.has(variation):
hasChanges = true
break

if hasChanges == true:
list_of_modified_slabs.append(slabID)
lines.append("[slab" + str(slabID) + "]")

for variationNumber in 28:
var variation = slabID * 28 + variationNumber
var dirText = dir_texts[variationNumber]

lines.append("[slab" + str(slabID) + "." + dirText + "]")

lines.append("Columns = " + str(dat[variation]))

for object in tng[variation]:
lines.append("")
lines.append("[[slab" + str(slabID) + "." + dirText + "_objects" + "]]")
for z in 9:
var propertyName
var value
match z:
0:
propertyName = "IsLight"
value = object[z]
2:
propertyName = "Subtile"
value = object[z]
3:
propertyName = "RelativePosition"
value = [ object[3], object[4], object[5] ]
6:
propertyName = "ThingType"
value = object[z]
7:
propertyName = "Subtype"
value = object[z]
8:
propertyName = "EffectRange"
value = object[z]
if propertyName:
lines.append(propertyName + " = " + str(value))
if tng[variation].size() == 0:
lines.append("Objects = []")

var dirText = dir_texts[variationNumber]

lines.append("[slab" + str(slabID) + "." + dirText + "]")

lines.append("Columns = " + str(dat[variation]))

for object in tng[variation]:
lines.append("")
lines.append("[[slab" + str(slabID) + "." + dirText + "_objects" + "]]")
for z in 9:
var propertyName
var value
match z:
0:
propertyName = "IsLight"
value = object[z]
2:
propertyName = "Subtile"
value = object[z]
3:
propertyName = "RelativePosition"
value = [ object[3], object[4], object[5] ]
6:
propertyName = "ThingType"
value = object[z]
7:
propertyName = "Subtype"
value = object[z]
8:
propertyName = "EffectRange"
value = object[z]
if propertyName:
lines.append(propertyName + " = " + str(value))
if tng[variation].size() == 0:
lines.append("Objects = []")

lines.append("")

lines.append("")

var textFile = File.new()
if textFile.open(filePath, File.WRITE) != OK:
oMessage.big("Error", "Couldn't save file, maybe try saving to another directory.")
return

textFile.store_string("\n".join(lines))
textFile.close()

oMessage.quick("Saved: " + filePath)
oMessage.quick("Saved Slab IDs: " + str(list_of_modified_slabs).replace("[","").replace("]",""))

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


func find_all_dat_differences():
var diff_indices = []
for variation in dat.size():
if is_dat_variation_different(variation) == true:
diff_indices.append(variation)
return diff_indices

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

func find_all_tng_differences():
var diff_indices = []
for variation in tng.size():
if is_tng_variation_different(variation) == true:
diff_indices.append(variation)
return diff_indices
func get_all_modified_slabs():
var modified_slabs = []
var totalSlabs = max(dat.size(), tng.size()) / 28
for slabID in totalSlabs:
if is_slab_edited(slabID):
modified_slabs.append(slabID)
return modified_slabs

func is_slab_edited(slabID):
for variationNumber in 28:
var variation = slabID * 28 + variationNumber
if is_dat_variation_different(variation) or is_tng_variation_different(variation):
return true
return false


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


#func find_all_dat_differences():
# var diff_indices = []
# for variation in dat.size():
# if is_dat_variation_different(variation) == true:
# diff_indices.append(variation)
# return diff_indices
#
#func find_all_tng_differences():
# var diff_indices = []
# for variation in tng.size():
# if is_tng_variation_different(variation) == true:
# diff_indices.append(variation)
# return diff_indices


var dir_texts = {
0: 'S',
1: 'W',
Expand Down
21 changes: 12 additions & 9 deletions Scenes/SlabsetWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ func _on_SlabsetIDSpinBox_value_changed(value):
if Slabs.data.has(value):
slabName = Slabs.data[value][Slabs.NAME]
oSlabsetIDLabel.text = slabName
update_columns_ui()
update_column_spinboxes()

func _on_VariationNumberSpinBox_value_changed(value):
update_columns_ui()
update_column_spinboxes()

func update_columns_ui():
func update_column_spinboxes():
var variation = get_current_variation()

for subtile in columnSettersArray.size():
Expand Down Expand Up @@ -271,7 +271,7 @@ func _on_ExportColumnsetTomlDialog_file_selected(filePath):
#func _on_ImportSlabsetTomlDialog_file_selected(filePath):
# var fullImport = false
# Slabset.import_toml_slabset(filePath, fullImport, true)
# update_columns_ui()
# update_column_spinboxes()
# update_objects_ui()
#
#func _on_ImportColumnsetTomlDialog_file_selected(filePath):
Expand Down Expand Up @@ -516,6 +516,7 @@ func _on_ObjThingTypeSpinBox_value_changed(value:int):
#oObjThingTypeSpinBox.hint_tooltip = Things.data_structure_name.get(value, "?")
#yield(get_tree(),'idle_frame')

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

# Update the UI after pasting
update_columns_ui()
update_column_spinboxes()
update_objects_ui()
oDkSlabsetVoxelView._on_SlabsetIDSpinBox_value_changed(oSlabsetIDSpinBox.value)

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

# Update the UI
update_columns_ui()
update_column_spinboxes()
update_objects_ui()
oMessage.quick("Rotated variation")

Expand Down Expand Up @@ -747,9 +748,11 @@ func revert(howMany):
else:
if variation < Slabset.tng.size():
Slabset.tng.remove(variation)

update_columns_ui() # Update UI for columns
update_column_spinboxes() # Update UI for columns
update_objects_ui() # Update UI for objects

yield(get_tree(),'idle_frame')
oDkSlabsetVoxelView.refresh_entire_view()



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

0 comments on commit 74b5f85

Please sign in to comment.