add unit tests
saveload fixes
This commit is contained in:
@@ -43,7 +43,7 @@ var grid_initialized: bool = false
|
||||
var instance_id: String
|
||||
|
||||
func _ready():
|
||||
# Generate unique instance ID for debugging
|
||||
# Generate instance ID
|
||||
instance_id = "Match3_%d" % get_instance_id()
|
||||
|
||||
if grid_initialized:
|
||||
@@ -53,10 +53,10 @@ func _ready():
|
||||
DebugManager.log_debug("[%s] Match3 _ready() started" % instance_id, "Match3")
|
||||
grid_initialized = true
|
||||
|
||||
# Always calculate grid layout first
|
||||
# Calculate grid layout
|
||||
_calculate_grid_layout()
|
||||
|
||||
# Try to load saved state first, otherwise use default initialization
|
||||
# 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")
|
||||
@@ -66,10 +66,10 @@ func _ready():
|
||||
|
||||
DebugManager.log_debug("Match3 _ready() completed, calling debug structure check", "Match3")
|
||||
|
||||
# Emit signal to notify UI components (like debug menu) that grid state is fully loaded
|
||||
# Notify UI that grid state is loaded
|
||||
grid_state_loaded.emit(GRID_SIZE, TILE_TYPES)
|
||||
|
||||
# Debug: Check scene tree structure immediately
|
||||
# Debug: Check scene tree structure
|
||||
call_deferred("_debug_scene_structure")
|
||||
|
||||
func _calculate_grid_layout():
|
||||
@@ -82,7 +82,7 @@ func _calculate_grid_layout():
|
||||
var max_tile_height = available_height / GRID_SIZE.y
|
||||
tile_size = min(max_tile_width, max_tile_height)
|
||||
|
||||
# Align grid to left side with configurable margins
|
||||
# Align grid to left side with margins
|
||||
var total_grid_height = tile_size * GRID_SIZE.y
|
||||
grid_offset = Vector2(
|
||||
GRID_LEFT_MARGIN,
|
||||
@@ -107,7 +107,7 @@ func _initialize_grid():
|
||||
# Set gem types for this tile
|
||||
tile.set_active_gem_types(gem_indices)
|
||||
|
||||
# Set tile type after adding to scene tree so sprite reference is available
|
||||
# Set tile type after adding to scene tree
|
||||
var new_type = randi() % TILE_TYPES
|
||||
tile.tile_type = new_type
|
||||
|
||||
@@ -117,7 +117,7 @@ func _initialize_grid():
|
||||
grid[y].append(tile)
|
||||
|
||||
func _has_match_at(pos: Vector2i) -> bool:
|
||||
# Comprehensive bounds and null checks
|
||||
# Bounds and null checks
|
||||
if not _is_valid_grid_position(pos):
|
||||
return false
|
||||
|
||||
@@ -141,7 +141,7 @@ func _has_match_at(pos: Vector2i) -> bool:
|
||||
var matches_vertical = _get_match_line(pos, Vector2i(0, 1))
|
||||
return matches_vertical.size() >= 3
|
||||
|
||||
# Fixed: Add missing function to check for any matches on the board
|
||||
# Check for any matches on the board
|
||||
func _check_for_matches() -> bool:
|
||||
for y in range(GRID_SIZE.y):
|
||||
for x in range(GRID_SIZE.x):
|
||||
@@ -173,7 +173,7 @@ func _get_match_line(start: Vector2i, dir: Vector2i) -> Array:
|
||||
var line = [start_tile]
|
||||
var type = start_tile.tile_type
|
||||
|
||||
# Check in both directions separately with safety limits
|
||||
# Check both directions with safety limits
|
||||
for offset in [1, -1]:
|
||||
var current = start + dir * offset
|
||||
var steps = 0
|
||||
@@ -195,7 +195,7 @@ func _get_match_line(start: Vector2i, dir: Vector2i) -> Array:
|
||||
return line
|
||||
|
||||
func _clear_matches():
|
||||
# Safety check for grid integrity
|
||||
# Check grid integrity
|
||||
if not _validate_grid_integrity():
|
||||
DebugManager.log_error("Grid integrity check failed in _clear_matches", "Match3")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user