vertical collapse much cleaner. horizontal to do.
This commit is contained in:
98
grid.gd
98
grid.gd
@@ -93,47 +93,69 @@ func clear_highlights():
|
|||||||
|
|
||||||
func update_grid():
|
func update_grid():
|
||||||
# search for empty cells and drop tokens above them down
|
# search for empty cells and drop tokens above them down
|
||||||
for column in range(cols):
|
var temp_col
|
||||||
var col_array = []
|
for col in range(cols):
|
||||||
for row in range(rows-1, -1, -1):
|
temp_col = grid[col].filter(func(token): return token != null)
|
||||||
# create a temporary array from the column
|
for idx in range(rows - temp_col.size()):
|
||||||
col_array.append(grid[row][column])
|
set_token(null, idx, col)
|
||||||
|
for idx in range(temp_col.size()):
|
||||||
# filter the nulls out of the array
|
set_token(temp_col[idx], rows - temp_col.size() + idx, col)
|
||||||
col_array = col_array.filter(func(token): return token != null)
|
|
||||||
|
# search for empty columns and compact horizontally
|
||||||
# put the filtered column back into the grid
|
|
||||||
for row in range(rows-1, -1, -1):
|
|
||||||
var idx = rows - row - 1
|
|
||||||
grid[row][column] = col_array[idx] if idx < col_array.size() else null
|
|
||||||
|
|
||||||
|
|
||||||
# search for empty coluns and shift tokens horizontally to fill them
|
|
||||||
var empty_columns = []
|
var empty_columns = []
|
||||||
for column in range(cols):
|
for col in range(cols):
|
||||||
var col_array = []
|
if grid[col].all(func(token): return token == null):
|
||||||
for row in range(rows):
|
empty_columns.append(col)
|
||||||
col_array.append(grid[row][column])
|
|
||||||
|
print(empty_columns)
|
||||||
if col_array.all(func(token): return token == null):
|
|
||||||
empty_columns.append(column)
|
|
||||||
|
|
||||||
if empty_columns.size() > 0:
|
|
||||||
var idx = 0
|
|
||||||
var dest_column = 0
|
|
||||||
while idx < cols:
|
|
||||||
if idx in empty_columns:
|
|
||||||
idx += 1
|
|
||||||
continue
|
|
||||||
|
|
||||||
for row in range(rows):
|
|
||||||
grid[row][dest_column] = grid[row][idx]
|
|
||||||
idx += 1
|
|
||||||
dest_column += 1
|
|
||||||
|
|
||||||
redraw_grid()
|
redraw_grid()
|
||||||
calculate_token_groups()
|
calculate_token_groups()
|
||||||
|
|
||||||
|
#func donot():
|
||||||
|
#for col in range(cols):
|
||||||
|
#var col_array = []
|
||||||
|
#for row in range(rows-1, -1, -1):
|
||||||
|
## create a temporary array from the column
|
||||||
|
#col_array.append(grid[row])
|
||||||
|
#
|
||||||
|
## filter the nulls out of the array
|
||||||
|
#col_array = col_array.filter(func(token): return token != null)
|
||||||
|
#
|
||||||
|
## put the filtered column back into the grid
|
||||||
|
#for row in range(rows-1, -1, -1):
|
||||||
|
#var idx = rows - row - 1
|
||||||
|
#grid[row][column] = col_array[idx] if idx < col_array.size() else null
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
## search for empty coluns and shift tokens horizontally to fill them
|
||||||
|
#var empty_columns = []
|
||||||
|
#for column in range(cols):
|
||||||
|
#var col_array = []
|
||||||
|
#for row in range(rows):
|
||||||
|
#col_array.append(grid[row][column])
|
||||||
|
#
|
||||||
|
#if col_array.all(func(token): return token == null):
|
||||||
|
#empty_columns.append(column)
|
||||||
|
#
|
||||||
|
#if empty_columns.size() > 0:
|
||||||
|
#var idx = 0
|
||||||
|
#var dest_column = 0
|
||||||
|
#while idx < cols:
|
||||||
|
#if idx in empty_columns:
|
||||||
|
#idx += 1
|
||||||
|
#continue
|
||||||
|
#
|
||||||
|
#for row in range(rows):
|
||||||
|
#grid[row][dest_column] = grid[row][idx]
|
||||||
|
#idx += 1
|
||||||
|
#dest_column += 1
|
||||||
|
#
|
||||||
|
#redraw_grid()
|
||||||
|
#calculate_token_groups()
|
||||||
|
|
||||||
func redraw_grid():
|
func redraw_grid():
|
||||||
for row in range(rows):
|
for row in range(rows):
|
||||||
for column in range(cols):
|
for column in range(cols):
|
||||||
@@ -206,7 +228,7 @@ func _on_boundary_area_input_event(viewport: Node, event: InputEvent, shape_idx:
|
|||||||
var group = get_group_of_token(token_coord)
|
var group = get_group_of_token(token_coord)
|
||||||
if group.size() >= min_group_size:
|
if group.size() >= min_group_size:
|
||||||
for coord in group:
|
for coord in group:
|
||||||
var current_token = grid[coord[0]][coord[1]] as Token
|
var current_token = get_token(coord[0], coord[1])
|
||||||
current_token.queue_free()
|
current_token.queue_free()
|
||||||
set_token(null, coord[0], coord[1])# do I actually want a null value or should there be some other placeholder?
|
set_token(null, coord[0], coord[1])# do I actually want a null value or should there be some other placeholder?
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user