slight code cleanup
bendn 2022-04-22
parent 8494890 · commit 562c21a
-rw-r--r--Block.gd10
-rw-r--r--Grid.gd10
2 files changed, 11 insertions, 9 deletions
diff --git a/Block.gd b/Block.gd
index 8101e48..bde3ce9 100644
--- a/Block.gd
+++ b/Block.gd
@@ -12,3 +12,13 @@ func configure(text: String, background: Color, text_color: Color = Color.white)
label.text = text
if text_color != Color.white:
label.add_color_override("font_color", text_color)
+
+func update_colors(new_number):
+ if new_number == 0:
+ configure("", Constants.BACKGROUND_COLOR_CELL_EMPTY)
+ else:
+ configure(
+ str(new_number),
+ Constants.BACKGROUND_COLOR_ARRAY[Constants.cells[new_number]],
+ Constants.CELL_COLOR_ARRAY[Constants.cells[new_number]]
+ ) \ No newline at end of file
diff --git a/Grid.gd b/Grid.gd
index 930d09b..8077245 100644
--- a/Grid.gd
+++ b/Grid.gd
@@ -31,19 +31,11 @@ func init_grid():
grid_row.append(block)
grid_cells.append(grid_row)
-
func update_grid_cells():
for i in range(Constants.GRID_LEN):
for j in range(Constants.GRID_LEN):
var new_number = matrix[i][j]
- if new_number == 0:
- grid_cells[i][j].configure("", Constants.BACKGROUND_COLOR_CELL_EMPTY)
- else:
- grid_cells[i][j].configure(
- str(new_number),
- Constants.BACKGROUND_COLOR_ARRAY[Constants.cells[new_number]],
- Constants.CELL_COLOR_ARRAY[Constants.cells[new_number]]
- )
+ grid_cells[i][j].update_colors(new_number)
func _input(event):