Skip to content

Commit

Permalink
Column Editor's 'Sort' function updated to always put blank columns a…
Browse files Browse the repository at this point in the history
…t the end
  • Loading branch information
rainlizard committed Jun 13, 2024
1 parent a1bf4c7 commit 963cbac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
45 changes: 18 additions & 27 deletions Scenes/DataClm.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ func store_default_data():

#var testingSpecialByte = []

var unknownData #The second 4 bytes


func clm_data_exists():
if cubes.empty() == true:
Expand Down Expand Up @@ -111,36 +109,31 @@ func clear_unused_entries():
func sort_columns_by_utilized():
oMessage.quick("Sorted columns by utilized value")


var array = []
var dictSrcDest = {}

utilized[0] = 999999 # Pretend that the utilized value is maximum for column 0, so it's placed first when sorted. Set it back to 0 afterwards.

var CODETIME_START = OS.get_ticks_msec()
for i in column_count:

# Each column gets its own array which contains all of its column values.
array.append([])

array[i].append(i) #[0] # Its old original index before being sorted
array[i].append(utilized[i]) #[1]
array[i].append(orientation[i]) #[2]
array[i].append(solidMask[i]) #[3]
array[i].append(permanent[i]) #[4]
array[i].append(lintel[i]) #[5]
array[i].append(height[i]) #[6]
array[i].append(cubes[i].duplicate(true)) #[7]
array[i].append(floorTexture[i]) #[8]
array.append([
i,
utilized[i],
orientation[i],
solidMask[i],
permanent[i],
lintel[i],
height[i],
cubes[i].duplicate(true),
floorTexture[i]
])

# Sort
array.sort_custom(self, "sorter_utilized")

for i in column_count:
var sourceIndex = array[i][0]
dictSrcDest[sourceIndex] = i # for swapping the column indexes easier in oDataClmPos

# Move to new position
for i in column_count:
utilized[i] = array[i][1]
orientation[i] = array[i][2]
solidMask[i] = array[i][3]
Expand All @@ -150,8 +143,6 @@ func sort_columns_by_utilized():
cubes[i] = array[i][7]
floorTexture[i] = array[i][8]

#print(dictionary[419])

for y in (M.ySize*3):
for x in (M.xSize*3):
var clmIndex = oDataClmPos.get_cell_clmpos(x,y)
Expand All @@ -164,16 +155,16 @@ func sort_columns_by_utilized():

oOverheadGraphics.overhead2d_update_rect_single_threaded(shapePositionArray)


utilized[0] = 0 # Pretend that the utilized value is maximum for column 0, so it's placed first. Set it back to 0 afterwards.

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

static func sorter_utilized(a, b): # Sort by an array value within the array
if a[1] > b[1]: # 1 is the utilized value of the column
return true
return false

static func sorter_utilized(a, b):
if a[1] == b[1]:
if a[1] == 0:
return a[7] != [0,0,0,0, 0,0,0,0] or a[8] != 0
return false
return a[1] > b[1]

#func find_blank_slot():
# var index = cubes.find([0,0,0,0, 0,0,0,0], 1) # Skip looking at index 0
Expand Down
3 changes: 1 addition & 2 deletions Scenes/ReadData.gd
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func read_clm(buffer):
buffer.seek(0)
# Do not read column count from the .clm file, just hardcode it. #buffer.get_32()
buffer.seek(4)
oDataClm.unknownData = oDataClm.column_count #buffer.get_32()
# Ignore second lot of 4 bytes
buffer.seek(8) # For reading maps
for entry in oDataClm.column_count:
oDataClm.utilized[entry] = buffer.get_u16() # 0-1
Expand All @@ -206,7 +206,6 @@ func new_clm():
oDataClm.column_count = 8192
oDataClm.clear_all_column_data()

oDataClm.unknownData = 0
for entry in oDataClm.column_count:
oDataClm.utilized[entry] = 0
oDataClm.permanent[entry] = 0
Expand Down
2 changes: 1 addition & 1 deletion Scenes/WriteData.gd
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func write_clm():
var buffer = StreamPeerBuffer.new()

buffer.put_32(oDataClm.column_count)
buffer.put_32(oDataClm.unknownData)
buffer.put_32(0)
var data = PoolByteArray()
data.resize(oDataClm.column_count * 24)

Expand Down

0 comments on commit 963cbac

Please sign in to comment.