🎨 Auto-format GDScript code

Automated formatting applied by tools/run_development.py

🤖 Generated by Gitea Actions
Workflow: Continuous Integration
Run: http://server:3000/nett00n/skelly/actions/runs/90
This commit is contained in:
Gitea Actions
2025-10-01 11:05:19 +00:00
parent 3b8da89ad5
commit 1f1c394587
28 changed files with 655 additions and 1945 deletions

View File

@@ -20,20 +20,15 @@ func _ready() -> void:
# GameManager will set the gameplay mode, don't set default here
DebugManager.log_debug(
"Game _ready() completed, waiting for GameManager to set gameplay mode",
"Game"
"Game _ready() completed, waiting for GameManager to set gameplay mode", "Game"
)
func set_gameplay_mode(mode: String) -> void:
DebugManager.log_info(
"set_gameplay_mode called with mode: %s" % mode, "Game"
)
DebugManager.log_info("set_gameplay_mode called with mode: %s" % mode, "Game")
current_gameplay_mode = mode
await load_gameplay(mode)
DebugManager.log_info(
"set_gameplay_mode completed for mode: %s" % mode, "Game"
)
DebugManager.log_info("set_gameplay_mode completed for mode: %s" % mode, "Game")
func load_gameplay(mode: String) -> void:
@@ -42,35 +37,24 @@ func load_gameplay(mode: String) -> void:
# Clear existing gameplay and wait for removal
var existing_children = gameplay_container.get_children()
if existing_children.size() > 0:
DebugManager.log_debug(
"Removing %d existing children" % existing_children.size(), "Game"
)
DebugManager.log_debug("Removing %d existing children" % existing_children.size(), "Game")
for child in existing_children:
DebugManager.log_debug(
"Removing existing child: %s" % child.name, "Game"
)
DebugManager.log_debug("Removing existing child: %s" % child.name, "Game")
child.queue_free()
# Wait for children to be properly removed from scene tree
await get_tree().process_frame
DebugManager.log_debug(
(
"Children removal complete, container count: %d"
% gameplay_container.get_child_count()
),
"Children removal complete, container count: %d" % gameplay_container.get_child_count(),
"Game"
)
# Load new gameplay
if GAMEPLAY_SCENES.has(mode):
DebugManager.log_debug(
"Found scene path: %s" % GAMEPLAY_SCENES[mode], "Game"
)
DebugManager.log_debug("Found scene path: %s" % GAMEPLAY_SCENES[mode], "Game")
var gameplay_scene = load(GAMEPLAY_SCENES[mode])
var gameplay_instance = gameplay_scene.instantiate()
DebugManager.log_debug(
"Instantiated gameplay: %s" % gameplay_instance.name, "Game"
)
DebugManager.log_debug("Instantiated gameplay: %s" % gameplay_instance.name, "Game")
gameplay_container.add_child(gameplay_instance)
DebugManager.log_debug(
(
@@ -85,9 +69,7 @@ func load_gameplay(mode: String) -> void:
gameplay_instance.score_changed.connect(_on_score_changed)
DebugManager.log_debug("Connected score_changed signal", "Game")
else:
DebugManager.log_error(
"Gameplay mode '%s' not found in GAMEPLAY_SCENES" % mode, "Game"
)
DebugManager.log_error("Gameplay mode '%s' not found in GAMEPLAY_SCENES" % mode, "Game")
func set_global_score(value: int) -> void:
@@ -120,15 +102,10 @@ func _on_back_button_pressed() -> void:
if gameplay_instance and gameplay_instance.has_method("save_current_state"):
DebugManager.log_info("Saving grid state before exit", "Game")
# Make sure the gameplay instance is still valid and not being destroyed
if (
is_instance_valid(gameplay_instance)
and gameplay_instance.is_inside_tree()
):
if is_instance_valid(gameplay_instance) and gameplay_instance.is_inside_tree():
gameplay_instance.save_current_state()
else:
DebugManager.log_warn(
"Gameplay instance invalid, skipping grid save on exit", "Game"
)
DebugManager.log_warn("Gameplay instance invalid, skipping grid save on exit", "Game")
# Save the current score immediately before exiting
SaveManager.finish_game(global_score)
@@ -139,10 +116,7 @@ func _input(event: InputEvent) -> void:
if event.is_action_pressed("ui_back"):
# Handle gamepad/keyboard back action - same as back button
_on_back_button_pressed()
elif (
event.is_action_pressed("action_south")
and Input.is_action_pressed("action_north")
):
elif event.is_action_pressed("action_south") and Input.is_action_pressed("action_north"):
# Debug: Switch to clickomania when primary+secondary actions pressed together
if current_gameplay_mode == "match3":
set_gameplay_mode("clickomania")

View File

@@ -49,21 +49,13 @@ func _ready() -> void:
instance_id = "Match3_%d" % get_instance_id()
if grid_initialized:
(
DebugManager
. log_warn(
(
"[%s] Match3 _ready() called multiple times, skipping initialization"
% instance_id
),
"Match3"
)
DebugManager.log_warn(
"[%s] Match3 _ready() called multiple times, skipping initialization" % instance_id,
"Match3"
)
return
DebugManager.log_debug(
"[%s] Match3 _ready() started" % instance_id, "Match3"
)
DebugManager.log_debug("[%s] Match3 _ready() started" % instance_id, "Match3")
grid_initialized = true
# Calculate grid layout
@@ -72,16 +64,12 @@ func _ready() -> void:
# Try to load saved state, otherwise use default
var loaded_saved_state = await load_saved_state()
if not loaded_saved_state:
DebugManager.log_info(
"No saved state found, using default grid initialization", "Match3"
)
DebugManager.log_info("No saved state found, using default grid initialization", "Match3")
_initialize_grid()
else:
DebugManager.log_info("Successfully loaded saved grid state", "Match3")
DebugManager.log_debug(
"Match3 _ready() completed, calling debug structure check", "Match3"
)
DebugManager.log_debug("Match3 _ready() completed, calling debug structure check", "Match3")
# Notify UI that grid state is loaded
grid_state_loaded.emit(grid_size, tile_types)
@@ -103,8 +91,7 @@ func _calculate_grid_layout():
# Align grid to left side with margins
var total_grid_height = tile_size * grid_size.y
grid_offset = Vector2(
GRID_LEFT_MARGIN,
(viewport_size.y - total_grid_height) / 2 + GRID_TOP_MARGIN
GRID_LEFT_MARGIN, (viewport_size.y - total_grid_height) / 2 + GRID_TOP_MARGIN
)
@@ -149,9 +136,7 @@ func _has_match_at(pos: Vector2i) -> bool:
return false
if pos.y >= grid.size() or pos.x >= grid[pos.y].size():
DebugManager.log_error(
"Grid array bounds exceeded at (%d,%d)" % [pos.x, pos.y], "Match3"
)
DebugManager.log_error("Grid array bounds exceeded at (%d,%d)" % [pos.x, pos.y], "Match3")
return false
var tile = grid[pos.y][pos.x]
@@ -161,8 +146,7 @@ func _has_match_at(pos: Vector2i) -> bool:
# Check if tile has required properties
if not "tile_type" in tile:
DebugManager.log_warn(
"Tile at (%d,%d) missing tile_type property" % [pos.x, pos.y],
"Match3"
"Tile at (%d,%d) missing tile_type property" % [pos.x, pos.y], "Match3"
)
return false
@@ -193,18 +177,13 @@ func _get_match_line(start: Vector2i, dir: Vector2i) -> Array:
# Validate input parameters
if not _is_valid_grid_position(start):
DebugManager.log_error(
(
"Invalid start position for match line: (%d,%d)"
% [start.x, start.y]
),
"Match3"
"Invalid start position for match line: (%d,%d)" % [start.x, start.y], "Match3"
)
return []
if abs(dir.x) + abs(dir.y) != 1 or (dir.x != 0 and dir.y != 0):
DebugManager.log_error(
"Invalid direction vector for match line: (%d,%d)" % [dir.x, dir.y],
"Match3"
"Invalid direction vector for match line: (%d,%d)" % [dir.x, dir.y], "Match3"
)
return []
@@ -227,10 +206,7 @@ func _get_match_line(start: Vector2i, dir: Vector2i) -> Array:
var current = start + dir * offset
var steps = 0
# Safety limit prevents infinite loops in case of logic errors
while (
steps < grid_size.x + grid_size.y
and _is_valid_grid_position(current)
):
while steps < grid_size.x + grid_size.y and _is_valid_grid_position(current):
if current.y >= grid.size() or current.x >= grid[current.y].size():
break
@@ -257,9 +233,7 @@ func _clear_matches() -> void:
"""
# Check grid integrity
if not _validate_grid_integrity():
DebugManager.log_error(
"Grid integrity check failed in _clear_matches", "Match3"
)
DebugManager.log_error("Grid integrity check failed in _clear_matches", "Match3")
return
var match_groups := []
@@ -308,9 +282,7 @@ func _clear_matches() -> void:
else:
match_score = match_size + max(0, match_size - 2) # n + (n-2) for n >= 4
total_score += match_score
print(
"Debug: Match of ", match_size, " gems = ", match_score, " points"
)
print("Debug: Match of ", match_size, " gems = ", match_score, " points")
# Remove duplicates from all matches combined
var to_clear := []
@@ -336,9 +308,7 @@ func _clear_matches() -> void:
# Validate tile has grid_position property
if not "grid_position" in tile:
DebugManager.log_warn(
"Tile missing grid_position during removal", "Match3"
)
DebugManager.log_warn("Tile missing grid_position during removal", "Match3")
tile.queue_free()
continue
@@ -352,10 +322,7 @@ func _clear_matches() -> void:
grid[tile_pos.y][tile_pos.x] = null
else:
DebugManager.log_warn(
(
"Invalid grid position during tile removal: (%d,%d)"
% [tile_pos.x, tile_pos.y]
),
"Invalid grid position during tile removal: (%d,%d)" % [tile_pos.x, tile_pos.y],
"Match3"
)
@@ -391,9 +358,7 @@ func _drop_tiles():
func _fill_empty_cells():
# Safety check for grid integrity
if not _validate_grid_integrity():
DebugManager.log_error(
"Grid integrity check failed in _fill_empty_cells", "Match3"
)
DebugManager.log_error("Grid integrity check failed in _fill_empty_cells", "Match3")
return
# Create gem pool for current tile types
@@ -409,17 +374,14 @@ func _fill_empty_cells():
for x in range(grid_size.x):
if x >= grid[y].size():
DebugManager.log_error(
"Grid column %d does not exist in row %d" % [x, y], "Match3"
)
DebugManager.log_error("Grid column %d does not exist in row %d" % [x, y], "Match3")
continue
if not grid[y][x]:
var tile = TILE_SCENE.instantiate()
if not tile:
DebugManager.log_error(
"Failed to instantiate tile at (%d,%d)" % [x, y],
"Match3"
"Failed to instantiate tile at (%d,%d)" % [x, y], "Match3"
)
continue
@@ -431,17 +393,13 @@ func _fill_empty_cells():
if tile.has_method("set_active_gem_types"):
tile.set_active_gem_types(gem_indices)
else:
DebugManager.log_warn(
"Tile missing set_active_gem_types method", "Match3"
)
DebugManager.log_warn("Tile missing set_active_gem_types method", "Match3")
# Set random tile type with bounds checking
if tile_types > 0:
tile.tile_type = randi() % tile_types
else:
DebugManager.log_error(
"tile_types is 0, cannot set tile type", "Match3"
)
DebugManager.log_error("tile_types is 0, cannot set tile type", "Match3")
tile.queue_free()
continue
@@ -450,9 +408,7 @@ func _fill_empty_cells():
if tile.has_signal("tile_selected"):
tile.tile_selected.connect(_on_tile_selected)
else:
DebugManager.log_warn(
"Tile missing tile_selected signal", "Match3"
)
DebugManager.log_warn("Tile missing tile_selected signal", "Match3")
tiles_created += 1
@@ -467,15 +423,12 @@ func _fill_empty_cells():
iteration += 1
if iteration >= MAX_CASCADE_ITERATIONS:
(
DebugManager
. log_warn(
(
"Maximum cascade iterations reached (%d), stopping to prevent infinite loop"
% MAX_CASCADE_ITERATIONS
),
"Match3"
)
DebugManager.log_warn(
(
"Maximum cascade iterations reached (%d), stopping to prevent infinite loop"
% MAX_CASCADE_ITERATIONS
),
"Match3"
)
# Save grid state after cascades complete
@@ -491,27 +444,20 @@ func regenerate_grid():
or grid_size.y > MAX_GRID_SIZE
):
DebugManager.log_error(
(
"Invalid grid size for regeneration: %dx%d"
% [grid_size.x, grid_size.y]
),
"Match3"
"Invalid grid size for regeneration: %dx%d" % [grid_size.x, grid_size.y], "Match3"
)
return
if tile_types < 3 or tile_types > MAX_TILE_TYPES:
DebugManager.log_error(
"Invalid tile types count for regeneration: %d" % tile_types,
"Match3"
"Invalid tile types count for regeneration: %d" % tile_types, "Match3"
)
return
# Use time-based seed to ensure different patterns each time
var new_seed = Time.get_ticks_msec()
seed(new_seed)
DebugManager.log_debug(
"Regenerating grid with seed: " + str(new_seed), "Match3"
)
DebugManager.log_debug("Regenerating grid with seed: " + str(new_seed), "Match3")
# Safe tile cleanup with improved error handling
var children_to_remove = []
@@ -531,9 +477,7 @@ func regenerate_grid():
children_to_remove.append(child)
removed_count += 1
DebugManager.log_debug(
"Found %d tile children to remove" % removed_count, "Match3"
)
DebugManager.log_debug("Found %d tile children to remove" % removed_count, "Match3")
# First clear grid array references to prevent access to nodes being freed
for y in range(grid.size()):
@@ -564,30 +508,20 @@ func regenerate_grid():
func set_tile_types(new_count: int):
# Input validation
if new_count < 3:
DebugManager.log_error(
"Tile types count too low: %d (minimum 3)" % new_count, "Match3"
)
DebugManager.log_error("Tile types count too low: %d (minimum 3)" % new_count, "Match3")
return
if new_count > MAX_TILE_TYPES:
DebugManager.log_error(
(
"Tile types count too high: %d (maximum %d)"
% [new_count, MAX_TILE_TYPES]
),
"Match3"
"Tile types count too high: %d (maximum %d)" % [new_count, MAX_TILE_TYPES], "Match3"
)
return
if new_count == tile_types:
DebugManager.log_debug(
"Tile types count unchanged, skipping regeneration", "Match3"
)
DebugManager.log_debug("Tile types count unchanged, skipping regeneration", "Match3")
return
DebugManager.log_debug(
"Changing tile types from %d to %d" % [tile_types, new_count], "Match3"
)
DebugManager.log_debug("Changing tile types from %d to %d" % [tile_types, new_count], "Match3")
tile_types = new_count
# Regenerate grid with new tile types (gem pool is updated in regenerate_grid)
@@ -617,14 +551,10 @@ func set_grid_size(new_size: Vector2i):
return
if new_size == grid_size:
DebugManager.log_debug(
"Grid size unchanged, skipping regeneration", "Match3"
)
DebugManager.log_debug("Grid size unchanged, skipping regeneration", "Match3")
return
DebugManager.log_debug(
"Changing grid size from %s to %s" % [grid_size, new_size], "Match3"
)
DebugManager.log_debug("Changing grid size from %s to %s" % [grid_size, new_size], "Match3")
grid_size = new_size
# Regenerate grid with new size
@@ -647,19 +577,13 @@ func reset_all_visual_states() -> void:
func _debug_scene_structure() -> void:
DebugManager.log_debug("=== Scene Structure Debug ===", "Match3")
DebugManager.log_debug(
"Match3 node children count: %d" % get_child_count(), "Match3"
)
DebugManager.log_debug(
"Match3 global position: %s" % global_position, "Match3"
)
DebugManager.log_debug("Match3 node children count: %d" % get_child_count(), "Match3")
DebugManager.log_debug("Match3 global position: %s" % global_position, "Match3")
DebugManager.log_debug("Match3 scale: %s" % scale, "Match3")
# Check if grid is properly initialized
if not grid or grid.size() == 0:
DebugManager.log_error(
"Grid not initialized when debug structure called", "Match3"
)
DebugManager.log_error("Grid not initialized when debug structure called", "Match3")
return
# Check tiles
@@ -669,33 +593,23 @@ func _debug_scene_structure() -> void:
if y < grid.size() and x < grid[y].size() and grid[y][x]:
tile_count += 1
DebugManager.log_debug(
(
"Created %d tiles out of %d expected"
% [tile_count, grid_size.x * grid_size.y]
),
"Match3"
"Created %d tiles out of %d expected" % [tile_count, grid_size.x * grid_size.y], "Match3"
)
# Check first tile in detail
if grid.size() > 0 and grid[0].size() > 0 and grid[0][0]:
var first_tile = grid[0][0]
DebugManager.log_debug(
"First tile global position: %s" % first_tile.global_position,
"Match3"
)
DebugManager.log_debug(
"First tile local position: %s" % first_tile.position, "Match3"
"First tile global position: %s" % first_tile.global_position, "Match3"
)
DebugManager.log_debug("First tile local position: %s" % first_tile.position, "Match3")
# Check parent chain
var current_node = self
var depth = 0
while current_node and depth < 10:
DebugManager.log_debug(
(
"Parent level %d: %s (type: %s)"
% [depth, current_node.name, current_node.get_class()]
),
"Parent level %d: %s (type: %s)" % [depth, current_node.name, current_node.get_class()],
"Match3"
)
current_node = current_node.get_parent()
@@ -704,27 +618,16 @@ func _debug_scene_structure() -> void:
func _input(event: InputEvent) -> void:
# Debug key to reset all visual states
if (
event.is_action_pressed("action_east")
and DebugManager.is_debug_enabled()
):
if event.is_action_pressed("action_east") and DebugManager.is_debug_enabled():
reset_all_visual_states()
return
if (
current_state == GameState.SWAPPING
or current_state == GameState.PROCESSING
):
if current_state == GameState.SWAPPING or current_state == GameState.PROCESSING:
return
# Handle action_east (B button/ESC) to deselect selected tile
if (
event.is_action_pressed("action_east")
and current_state == GameState.SELECTING
):
DebugManager.log_debug(
"action_east pressed - deselecting current tile", "Match3"
)
if event.is_action_pressed("action_east") and current_state == GameState.SELECTING:
DebugManager.log_debug("action_east pressed - deselecting current tile", "Match3")
_deselect_tile()
return
@@ -749,23 +652,18 @@ func _input(event: InputEvent) -> void:
func _move_cursor(direction: Vector2i) -> void:
# Input validation for direction vector
if abs(direction.x) > 1 or abs(direction.y) > 1:
DebugManager.log_error(
"Invalid cursor direction vector: " + str(direction), "Match3"
)
DebugManager.log_error("Invalid cursor direction vector: " + str(direction), "Match3")
return
if direction.x != 0 and direction.y != 0:
DebugManager.log_error(
"Diagonal cursor movement not supported: " + str(direction),
"Match3"
"Diagonal cursor movement not supported: " + str(direction), "Match3"
)
return
# Validate grid integrity before cursor operations
if not _validate_grid_integrity():
DebugManager.log_error(
"Grid integrity check failed in cursor movement", "Match3"
)
DebugManager.log_error("Grid integrity check failed in cursor movement", "Match3")
return
var old_pos = cursor_position
@@ -778,30 +676,19 @@ func _move_cursor(direction: Vector2i) -> void:
if new_pos != cursor_position:
# Safe access to old tile
var old_tile = _safe_grid_access(old_pos)
if (
old_tile
and "is_selected" in old_tile
and "is_highlighted" in old_tile
):
if old_tile and "is_selected" in old_tile and "is_highlighted" in old_tile:
if not old_tile.is_selected:
old_tile.is_highlighted = false
DebugManager.log_debug(
(
"Cursor moved from (%d,%d) to (%d,%d)"
% [old_pos.x, old_pos.y, new_pos.x, new_pos.y]
),
"Cursor moved from (%d,%d) to (%d,%d)" % [old_pos.x, old_pos.y, new_pos.x, new_pos.y],
"Match3"
)
cursor_position = new_pos
# Safe access to new tile
var new_tile = _safe_grid_access(cursor_position)
if (
new_tile
and "is_selected" in new_tile
and "is_highlighted" in new_tile
):
if new_tile and "is_selected" in new_tile and "is_highlighted" in new_tile:
if not new_tile.is_selected:
new_tile.is_highlighted = true
@@ -821,19 +708,13 @@ func _select_tile_at_cursor() -> void:
var tile = _safe_grid_access(cursor_position)
if tile:
DebugManager.log_debug(
(
"Keyboard selection at cursor (%d,%d)"
% [cursor_position.x, cursor_position.y]
),
"Keyboard selection at cursor (%d,%d)" % [cursor_position.x, cursor_position.y],
"Match3"
)
_on_tile_selected(tile)
else:
DebugManager.log_warn(
(
"No valid tile at cursor position (%d,%d)"
% [cursor_position.x, cursor_position.y]
),
"No valid tile at cursor position (%d,%d)" % [cursor_position.x, cursor_position.y],
"Match3"
)
@@ -847,15 +728,9 @@ func _on_tile_selected(tile: Node2D) -> void:
SELECTING -> SWAPPING: Different tile clicked (attempt swap)
"""
# Block tile selection during busy states
if (
current_state == GameState.SWAPPING
or current_state == GameState.PROCESSING
):
if current_state == GameState.SWAPPING or current_state == GameState.PROCESSING:
DebugManager.log_debug(
(
"Tile selection ignored - game busy (state: %s)"
% [GameState.keys()[current_state]]
),
"Tile selection ignored - game busy (state: %s)" % [GameState.keys()[current_state]],
"Match3"
)
return
@@ -898,11 +773,7 @@ func _select_tile(tile: Node2D) -> void:
tile.is_selected = true
current_state = GameState.SELECTING # State transition: WAITING -> SELECTING
DebugManager.log_debug(
(
"Selected tile at (%d, %d)"
% [tile.grid_position.x, tile.grid_position.y]
),
"Match3"
"Selected tile at (%d, %d)" % [tile.grid_position.x, tile.grid_position.y], "Match3"
)
@@ -913,17 +784,12 @@ func _deselect_tile() -> void:
DebugManager.log_debug(
(
"Deselecting tile at (%d,%d)"
% [
selected_tile.grid_position.x,
selected_tile.grid_position.y
]
% [selected_tile.grid_position.x, selected_tile.grid_position.y]
),
"Match3"
)
else:
DebugManager.log_debug(
"Deselecting tile (no grid position available)", "Match3"
)
DebugManager.log_debug("Deselecting tile (no grid position available)", "Match3")
# Safe property access for selection state
if "is_selected" in selected_tile:
@@ -967,9 +833,7 @@ func _are_adjacent(tile1: Node2D, tile2: Node2D) -> bool:
func _attempt_swap(tile1: Node2D, tile2: Node2D) -> void:
if not _are_adjacent(tile1, tile2):
DebugManager.log_debug(
"Tiles are not adjacent, selecting new tile instead", "Match3"
)
DebugManager.log_debug("Tiles are not adjacent, selecting new tile instead", "Match3")
_deselect_tile()
_select_tile(tile2)
return
@@ -1022,9 +886,7 @@ func _attempt_swap(tile1: Node2D, tile2: Node2D) -> void:
func _swap_tiles(tile1: Node2D, tile2: Node2D) -> void:
if not tile1 or not tile2:
DebugManager.log_error(
"Cannot swap tiles - one or both tiles are null", "Match3"
)
DebugManager.log_error("Cannot swap tiles - one or both tiles are null", "Match3")
return
# Update grid positions
@@ -1072,9 +934,7 @@ func serialize_grid_state() -> Array:
)
if grid.size() == 0:
DebugManager.log_error(
"Grid array is empty during serialization!", "Match3"
)
DebugManager.log_error("Grid array is empty during serialization!", "Match3")
return []
var serialized_grid = []
@@ -1090,11 +950,7 @@ func serialize_grid_state() -> Array:
# Only log first few for brevity
if valid_tiles <= 5:
DebugManager.log_debug(
(
"Serializing tile (%d,%d): type %d"
% [x, y, grid[y][x].tile_type]
),
"Match3"
"Serializing tile (%d,%d): type %d" % [x, y, grid[y][x].tile_type], "Match3"
)
else:
row.append(-1) # Invalid/empty tile
@@ -1102,8 +958,7 @@ func serialize_grid_state() -> Array:
# Only log first few nulls for brevity
if null_tiles <= 5:
DebugManager.log_debug(
"Serializing tile (%d,%d): NULL/empty (-1)" % [x, y],
"Match3"
"Serializing tile (%d,%d): NULL/empty (-1)" % [x, y], "Match3"
)
serialized_grid.append(row)
@@ -1147,9 +1002,7 @@ func save_current_state():
func load_saved_state() -> bool:
# Check if there's a saved grid state
if not SaveManager.has_saved_grid():
DebugManager.log_info(
"No saved grid state found, using default generation", "Match3"
)
DebugManager.log_info("No saved grid state found, using default generation", "Match3")
return false
var saved_state = SaveManager.get_saved_grid_state()
@@ -1162,21 +1015,12 @@ func load_saved_state() -> bool:
saved_gems.append(int(gem))
var saved_layout = saved_state.grid_layout
(
DebugManager
. log_info(
(
"[%s] Loading saved grid state: size(%d,%d), %d tile types, layout_size=%d"
% [
instance_id,
saved_size.x,
saved_size.y,
tile_types,
saved_layout.size()
]
),
"Match3"
)
DebugManager.log_info(
(
"[%s] Loading saved grid state: size(%d,%d), %d tile types, layout_size=%d"
% [instance_id, saved_size.x, saved_size.y, tile_types, saved_layout.size()]
),
"Match3"
)
# Debug: Print first few rows of loaded layout
@@ -1214,10 +1058,7 @@ func load_saved_state() -> bool:
# Recalculate layout if size changed
if old_size != saved_size:
DebugManager.log_info(
(
"Grid size changed from %s to %s, recalculating layout"
% [old_size, saved_size]
),
"Grid size changed from %s to %s, recalculating layout" % [old_size, saved_size],
"Match3"
)
_calculate_grid_layout()
@@ -1228,9 +1069,7 @@ func load_saved_state() -> bool:
return true
func _restore_grid_from_layout(
grid_layout: Array, active_gems: Array[int]
) -> void:
func _restore_grid_from_layout(grid_layout: Array, active_gems: Array[int]) -> void:
DebugManager.log_info(
(
"[%s] Starting grid restoration: layout_size=%d, active_gems=%s"
@@ -1249,8 +1088,7 @@ func _restore_grid_from_layout(
all_tile_children.append(child)
DebugManager.log_debug(
"Found %d existing tile children to remove" % all_tile_children.size(),
"Match3"
"Found %d existing tile children to remove" % all_tile_children.size(), "Match3"
)
# Remove all found tile children
@@ -1295,24 +1133,17 @@ func _restore_grid_from_layout(
if saved_tile_type >= 0 and saved_tile_type < tile_types:
tile.tile_type = saved_tile_type
DebugManager.log_debug(
(
"✓ Restored tile (%d,%d) with saved type %d"
% [x, y, saved_tile_type]
),
"Match3"
"✓ Restored tile (%d,%d) with saved type %d" % [x, y, saved_tile_type], "Match3"
)
else:
# Fallback for invalid tile types
tile.tile_type = randi() % tile_types
(
DebugManager
. log_error(
(
"✗ Invalid saved tile type %d at (%d,%d), using random %d"
% [saved_tile_type, x, y, tile.tile_type]
),
"Match3"
)
DebugManager.log_error(
(
"✗ Invalid saved tile type %d at (%d,%d), using random %d"
% [saved_tile_type, x, y, tile.tile_type]
),
"Match3"
)
# Connect tile signals
@@ -1320,22 +1151,13 @@ func _restore_grid_from_layout(
grid[y].append(tile)
DebugManager.log_info(
(
"Completed grid restoration: %d tiles restored"
% [grid_size.x * grid_size.y]
),
"Match3"
"Completed grid restoration: %d tiles restored" % [grid_size.x * grid_size.y], "Match3"
)
# Safety and validation helper functions
func _is_valid_grid_position(pos: Vector2i) -> bool:
return (
pos.x >= 0
and pos.y >= 0
and pos.x < grid_size.x
and pos.y < grid_size.y
)
return pos.x >= 0 and pos.y >= 0 and pos.x < grid_size.x and pos.y < grid_size.y
func _validate_grid_integrity() -> bool:
@@ -1346,8 +1168,7 @@ func _validate_grid_integrity() -> bool:
if grid.size() != grid_size.y:
DebugManager.log_error(
"Grid height mismatch: %d vs %d" % [grid.size(), grid_size.y],
"Match3"
"Grid height mismatch: %d vs %d" % [grid.size(), grid_size.y], "Match3"
)
return false
@@ -1358,11 +1179,7 @@ func _validate_grid_integrity() -> bool:
if grid[y].size() != grid_size.x:
DebugManager.log_error(
(
"Grid row %d width mismatch: %d vs %d"
% [y, grid[y].size(), grid_size.x]
),
"Match3"
"Grid row %d width mismatch: %d vs %d" % [y, grid[y].size(), grid_size.x], "Match3"
)
return false
@@ -1375,9 +1192,7 @@ func _safe_grid_access(pos: Vector2i) -> Node2D:
return null
if pos.y >= grid.size() or pos.x >= grid[pos.y].size():
DebugManager.log_warn(
"Grid bounds exceeded: (%d,%d)" % [pos.x, pos.y], "Match3"
)
DebugManager.log_warn("Grid bounds exceeded: (%d,%d)" % [pos.x, pos.y], "Match3")
return null
var tile = grid[pos.y][pos.x]

View File

@@ -11,9 +11,7 @@ extends RefCounted
## var grid_pos = Match3InputHandler.get_grid_position_from_world(node, world_pos, offset, size)
static func find_tile_at_position(
grid: Array, grid_size: Vector2i, world_pos: Vector2
) -> Node2D:
static func find_tile_at_position(grid: Array, grid_size: Vector2i, world_pos: Vector2) -> Node2D:
## Find the tile that contains the world position.
##
## Iterates through all tiles and checks if the world position falls within
@@ -33,9 +31,7 @@ static func find_tile_at_position(
if tile and tile.has_node("Sprite2D"):
var sprite = tile.get_node("Sprite2D")
if sprite and sprite.texture:
var sprite_bounds = get_sprite_world_bounds(
tile, sprite
)
var sprite_bounds = get_sprite_world_bounds(tile, sprite)
if is_point_inside_rect(world_pos, sprite_bounds):
return tile
return null

View File

@@ -51,9 +51,7 @@ static func serialize_grid_state(grid: Array, grid_size: Vector2i) -> Array:
return serialized_grid
static func get_active_gem_types_from_grid(
grid: Array, tile_types: int
) -> Array:
static func get_active_gem_types_from_grid(grid: Array, tile_types: int) -> Array:
# Get active gem types from the first available tile
if grid.size() > 0 and grid[0].size() > 0 and grid[0][0]:
return grid[0][0].active_gem_types.duplicate()
@@ -134,15 +132,9 @@ static func restore_grid_from_layout(
tile.tile_type = randi() % tile_types
# Connect tile signals
if (
tile.has_signal("tile_selected")
and match3_node.has_method("_on_tile_selected")
):
if tile.has_signal("tile_selected") and match3_node.has_method("_on_tile_selected"):
tile.tile_selected.connect(match3_node._on_tile_selected)
if (
tile.has_signal("tile_hovered")
and match3_node.has_method("_on_tile_hovered")
):
if tile.has_signal("tile_hovered") and match3_node.has_method("_on_tile_hovered"):
tile.tile_hovered.connect(match3_node._on_tile_hovered)
tile.tile_unhovered.connect(match3_node._on_tile_unhovered)

View File

@@ -25,12 +25,7 @@ static func is_valid_grid_position(pos: Vector2i, grid_size: Vector2i) -> bool:
##
## Returns:
## bool: True if position is valid, False if out of bounds
return (
pos.x >= 0
and pos.y >= 0
and pos.x < grid_size.x
and pos.y < grid_size.y
)
return pos.x >= 0 and pos.y >= 0 and pos.x < grid_size.x and pos.y < grid_size.y
static func validate_grid_integrity(grid: Array, grid_size: Vector2i) -> bool:
@@ -51,8 +46,7 @@ static func validate_grid_integrity(grid: Array, grid_size: Vector2i) -> bool:
if grid.size() != grid_size.y:
DebugManager.log_error(
"Grid height mismatch: %d vs %d" % [grid.size(), grid_size.y],
"Match3"
"Grid height mismatch: %d vs %d" % [grid.size(), grid_size.y], "Match3"
)
return false
@@ -63,28 +57,20 @@ static func validate_grid_integrity(grid: Array, grid_size: Vector2i) -> bool:
if grid[y].size() != grid_size.x:
DebugManager.log_error(
(
"Grid row %d width mismatch: %d vs %d"
% [y, grid[y].size(), grid_size.x]
),
"Match3"
"Grid row %d width mismatch: %d vs %d" % [y, grid[y].size(), grid_size.x], "Match3"
)
return false
return true
static func safe_grid_access(
grid: Array, pos: Vector2i, grid_size: Vector2i
) -> Node2D:
static func safe_grid_access(grid: Array, pos: Vector2i, grid_size: Vector2i) -> Node2D:
# Safe grid access with comprehensive bounds checking
if not is_valid_grid_position(pos, grid_size):
return null
if pos.y >= grid.size() or pos.x >= grid[pos.y].size():
DebugManager.log_warn(
"Grid bounds exceeded: (%d,%d)" % [pos.x, pos.y], "Match3"
)
DebugManager.log_warn("Grid bounds exceeded: (%d,%d)" % [pos.x, pos.y], "Match3")
return null
var tile = grid[pos.y][pos.x]

View File

@@ -123,9 +123,7 @@ func remove_gem_type(gem_index: int) -> bool:
return false
if active_gem_types.size() <= 2: # Keep at least 2 gem types
DebugManager.log_warn(
"Cannot remove gem type - minimum 2 types required", "Tile"
)
DebugManager.log_warn("Cannot remove gem type - minimum 2 types required", "Tile")
return false
active_gem_types.erase(gem_index)
@@ -180,12 +178,7 @@ func _update_visual_feedback() -> void:
DebugManager.log_debug(
(
"SELECTING tile (%d,%d): target scale %.2fx, current scale %s"
% [
grid_position.x,
grid_position.y,
scale_multiplier,
sprite.scale
]
% [grid_position.x, grid_position.y, scale_multiplier, sprite.scale]
),
"Match3"
)
@@ -193,20 +186,12 @@ func _update_visual_feedback() -> void:
# Highlighted: subtle glow and larger than original board size
target_modulate = Color(1.1, 1.1, 1.1, 1.0)
scale_multiplier = UIConstants.TILE_HIGHLIGHTED_SCALE
(
DebugManager
. log_debug(
(
"HIGHLIGHTING tile (%d,%d): target scale %.2fx, current scale %s"
% [
grid_position.x,
grid_position.y,
scale_multiplier,
sprite.scale
]
),
"Match3"
)
DebugManager.log_debug(
(
"HIGHLIGHTING tile (%d,%d): target scale %.2fx, current scale %s"
% [grid_position.x, grid_position.y, scale_multiplier, sprite.scale]
),
"Match3"
)
else:
# Normal state: white and original board size
@@ -215,12 +200,7 @@ func _update_visual_feedback() -> void:
DebugManager.log_debug(
(
"NORMALIZING tile (%d,%d): target scale %.2fx, current scale %s"
% [
grid_position.x,
grid_position.y,
scale_multiplier,
sprite.scale
]
% [grid_position.x, grid_position.y, scale_multiplier, sprite.scale]
),
"Match3"
)
@@ -248,11 +228,7 @@ func _update_visual_feedback() -> void:
tween.tween_callback(_on_scale_animation_completed.bind(target_scale))
else:
DebugManager.log_debug(
(
"No scale change needed for tile (%d,%d)"
% [grid_position.x, grid_position.y]
),
"Match3"
"No scale change needed for tile (%d,%d)" % [grid_position.x, grid_position.y], "Match3"
)
@@ -288,9 +264,7 @@ func _input(event: InputEvent) -> void:
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
# Check if the mouse click is within the tile's bounds
var local_position = to_local(get_global_mouse_position())
var sprite_rect = Rect2(
-TILE_SIZE / 2.0, -TILE_SIZE / 2.0, TILE_SIZE, TILE_SIZE
)
var sprite_rect = Rect2(-TILE_SIZE / 2.0, -TILE_SIZE / 2.0, TILE_SIZE, TILE_SIZE)
if sprite_rect.has_point(local_position):
tile_selected.emit(self)