Skip to content

Commit

Permalink
re-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Nov 8, 2023
1 parent db6ba3d commit 0aad3c1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 44 deletions.
45 changes: 17 additions & 28 deletions Autoload/Slabset.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,19 @@ func load_slabset():
dat_buffer.seek(2)

var totalSlabs = 42 + 16
dat.resize(totalSlabs)
for slabID in totalSlabs:
dat[slabID] = []
dat[slabID].resize(28) # Ensure each slab has space for 28 variations
for variation in 28:
dat[slabID][variation] = []
dat[slabID][variation].resize(9)
if slabID < 42 or variation < 8: # Only fill the data for the first 42 slabs and the first 8 variations of the next 16 slabs
for subtile in 9:
var value = 65536 - dat_buffer.get_u16()
dat[slabID][variation][subtile] = value
else:
for subtile in 9:
dat[slabID][variation][subtile] = 0

blank_dat_entry = []
blank_dat_entry.resize(28)
for variation in 28:
blank_dat_entry[variation] = []
blank_dat_entry[variation].resize(9)
for subtile in 9:
blank_dat_entry[variation][subtile] = 0
dat = []
dat.resize(28*totalSlabs) # Ensure each slab has space for 28 variations
for variation in dat.size():
dat[variation] = []
dat[variation].resize(9)
if variation < 42*28 or (variation % 28) < 8: # Handle the longslabs and the shortslabs
#if variation < 42*28 or (variation >= 42*28 and (variation % 28) < 8):
for subtile in 9:
var value = 65536 - dat_buffer.get_u16()
dat[variation][subtile] = value
else: # Fill the extra space at the end of the shortslabs
for subtile in 9:
dat[variation][subtile] = 0

print('Created Slabset : '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')

Expand Down Expand Up @@ -107,13 +98,11 @@ func load_slabset_things():
print('slabtng_object_entry_asset : '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')




func fetch_column_index(slabID, variation, subtile):
if dat.size() > slabID:
return dat[slabID][variation][subtile]
func fetch_column_index(variation, subtile):
if variation < dat.size():
return dat[variation][subtile]
else:
return blank_dat_entry[variation][subtile]
return 0


#func create_cfg_slabset(filePath): #"res://slabset.cfg"
Expand Down
12 changes: 8 additions & 4 deletions Scenes/PickSlabWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,24 @@ func add_slabs():
if putIntoTab != Slabs.TAB_NONE:
var scene = load("res://Scenes/SlabDisplay.tscn")
var id = scene.instance()
var slabVariation = 0
var slabVariation

var columnArray = [0,0,0, 0,0,0, 0,0,0]
match slabID:
Slabs.PORTAL:
slabVariation = (Slabs.PORTAL*28) + 8
for i in 9:
columnArray[i] = Slabset.fetch_column_index(slabID, 8, i)
columnArray[i] = Slabset.fetch_column_index(slabVariation, i)
Slabs.WALL_AUTOMATIC:
slabVariation = Slabs.WALL_WITH_BANNER*28
for i in 9:
columnArray[i] = Slabset.fetch_column_index(Slabs.WALL_WITH_BANNER, slabVariation, i)
columnArray[i] = Slabset.fetch_column_index(slabVariation, i)
_:
if slabID < 1000:
# Normal slab
slabVariation = slabID*28
for i in 9:
columnArray[i] = Slabset.fetch_column_index(slabID, slabVariation, i)
columnArray[i] = Slabset.fetch_column_index(slabVariation, i)
else:
# Custom slab
pass
Expand Down
2 changes: 1 addition & 1 deletion Scenes/PlaceThingWithSlab.gd
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func determine_if_middle(slabID, ownership, bitmask, surrID, surrOwner):
return false

func get_obj_idx(newSlabVar, subtile):
if newSlabVar >= 1304: return -1 # Out of bounds, causes crash
if newSlabVar >= Slabset.tngIndex.size(): return -1 # Out of bounds, causes crash

var idx = Slabset.tngIndex[newSlabVar]
if idx >= Slabset.numberOfThings: return -1
Expand Down
6 changes: 2 additions & 4 deletions Scenes/SlabPlacement.gd
Original file line number Diff line number Diff line change
Expand Up @@ -752,10 +752,8 @@ func dkdat_position_to_column_data(clmIndexGroup):
#print(clmIndexGroup)

for subtile in 9:
var index = clmIndexGroup[subtile] / 9
var slabID = index / 28
var variation = index % 28
var dkClmIndex = Slabset.fetch_column_index(slabID, variation, subtile)
var variation = clmIndexGroup[subtile] / 9
var dkClmIndex = Slabset.fetch_column_index(variation, subtile)

# Get the cube data from oDkClm
slabCubes.append(Columnset.cubes[dkClmIndex])
Expand Down
9 changes: 4 additions & 5 deletions Scenes/SlabsetWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,19 @@ func _on_VariationNumberSpinBox_value_changed(value):
update_columns_ui()

func update_columns_ui():

var variation = int(oVariationNumberSpinBox.value)
var slabID = int(oSlabsetIDSpinBox.value)
var variation = (slabID * 28) + int(oVariationNumberSpinBox.value)

for subtile in columnSettersArray.size():
var spinbox = columnSettersArray[subtile].get_node("CustomSpinBox")
spinbox.disconnect("value_changed",self,"_on_Slabset3x3ColumnSpinBox_value_changed")
var clmIndex = Slabset.fetch_column_index(slabID, variation, subtile)
var clmIndex = Slabset.fetch_column_index(variation, subtile)
spinbox.value = clmIndex
spinbox.connect("value_changed",self,"_on_Slabset3x3ColumnSpinBox_value_changed")

func _on_Slabset3x3ColumnSpinBox_value_changed(value):
var variation = int(oVariationNumberSpinBox.value)
var slabID = int(oSlabsetIDSpinBox.value)
var variation = (slabID * 28) + int(oVariationNumberSpinBox.value)

for y in 3:
for x in 3:
Expand All @@ -176,7 +175,7 @@ func _on_Slabset3x3ColumnSpinBox_value_changed(value):
var spinbox = id.get_node("CustomSpinBox")
var clmIndex = spinbox.value

Slabset.dat[slabID][variation][i] = clmIndex
Slabset.dat[variation][i] = clmIndex
#oSlabPalette.slabPal[variation][i] = clmIndex # This may not be working


Expand Down
6 changes: 4 additions & 2 deletions Scenes/VoxelViewer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ func do_all():
oAllVoxelObjects.translation.x = -0.5
var CODETIME_START = OS.get_ticks_msec()



if displayingType == DK_SLABSET: # This is not for custom slab, this is for dynamic slabs
var slabID = oSlabsetIDSpinBox.value
var separation = 0

var variationStart = slabID * 28
for variation in 28:
var surrClmIndex = [-1,-1,-1,-1]
for ySubtile in 3:
Expand All @@ -141,7 +143,7 @@ func do_all():
var x = (variation*3) + xSubtile + separation
var z = (variation*3) + ySubtile + separation

var clmIndex = Slabset.fetch_column_index(slabID, variation, subtile)
var clmIndex = Slabset.fetch_column_index(variationStart+variation, subtile)

oVoxelGen.column_gen(genArray, x-1.5, z-1.5, clmIndex, surrClmIndex, true, Columnset)

Expand Down

0 comments on commit 0aad3c1

Please sign in to comment.