more lint and formatting
Some checks failed
Some checks failed
This commit is contained in:
@@ -20,15 +20,20 @@ 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:
|
||||
@@ -37,24 +42,35 @@ 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(
|
||||
(
|
||||
@@ -69,7 +85,9 @@ 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:
|
||||
@@ -102,10 +120,15 @@ 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)
|
||||
@@ -116,7 +139,10 @@ 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")
|
||||
|
||||
@@ -49,13 +49,21 @@ 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
|
||||
@@ -64,12 +72,16 @@ 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)
|
||||
@@ -91,7 +103,8 @@ 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
|
||||
)
|
||||
|
||||
|
||||
@@ -136,7 +149,9 @@ 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]
|
||||
@@ -146,7 +161,8 @@ 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
|
||||
|
||||
@@ -177,13 +193,18 @@ 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 []
|
||||
|
||||
@@ -206,7 +227,10 @@ 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
|
||||
|
||||
@@ -233,7 +257,9 @@ 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 := []
|
||||
@@ -282,7 +308,9 @@ 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 := []
|
||||
@@ -308,7 +336,9 @@ 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
|
||||
|
||||
@@ -322,7 +352,10 @@ 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"
|
||||
)
|
||||
|
||||
@@ -358,7 +391,9 @@ 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
|
||||
@@ -374,14 +409,17 @@ 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
|
||||
|
||||
@@ -393,13 +431,17 @@ 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
|
||||
|
||||
@@ -408,7 +450,9 @@ 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
|
||||
|
||||
@@ -423,12 +467,15 @@ 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
|
||||
@@ -444,20 +491,27 @@ 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 = []
|
||||
@@ -477,7 +531,9 @@ 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()):
|
||||
@@ -508,20 +564,30 @@ 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)
|
||||
@@ -551,10 +617,14 @@ 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
|
||||
@@ -577,13 +647,19 @@ 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
|
||||
@@ -593,23 +669,33 @@ 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"
|
||||
"First tile global position: %s" % first_tile.global_position,
|
||||
"Match3"
|
||||
)
|
||||
DebugManager.log_debug(
|
||||
"First tile local position: %s" % first_tile.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()
|
||||
@@ -618,16 +704,27 @@ 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
|
||||
|
||||
@@ -652,18 +749,23 @@ 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
|
||||
@@ -676,19 +778,30 @@ 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
|
||||
|
||||
@@ -708,13 +821,19 @@ 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"
|
||||
)
|
||||
|
||||
@@ -728,9 +847,15 @@ 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
|
||||
@@ -773,7 +898,11 @@ 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"
|
||||
)
|
||||
|
||||
|
||||
@@ -784,12 +913,17 @@ 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:
|
||||
@@ -833,7 +967,9 @@ 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
|
||||
@@ -886,7 +1022,9 @@ 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
|
||||
@@ -934,7 +1072,9 @@ 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 = []
|
||||
@@ -950,7 +1090,11 @@ 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
|
||||
@@ -958,7 +1102,8 @@ 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)
|
||||
|
||||
@@ -1002,7 +1147,9 @@ 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()
|
||||
@@ -1015,12 +1162,21 @@ 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
|
||||
@@ -1058,7 +1214,10 @@ 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()
|
||||
@@ -1069,7 +1228,9 @@ 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"
|
||||
@@ -1088,7 +1249,8 @@ func _restore_grid_from_layout(grid_layout: Array, active_gems: Array[int]) -> v
|
||||
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
|
||||
@@ -1133,17 +1295,24 @@ func _restore_grid_from_layout(grid_layout: Array, active_gems: Array[int]) -> v
|
||||
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
|
||||
@@ -1151,13 +1320,22 @@ func _restore_grid_from_layout(grid_layout: Array, active_gems: Array[int]) -> v
|
||||
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:
|
||||
@@ -1168,7 +1346,8 @@ 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
|
||||
|
||||
@@ -1179,7 +1358,11 @@ 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
|
||||
|
||||
@@ -1192,7 +1375,9 @@ 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]
|
||||
|
||||
@@ -11,7 +11,9 @@ 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
|
||||
@@ -31,7 +33,9 @@ static func find_tile_at_position(grid: Array, grid_size: Vector2i, world_pos: V
|
||||
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
|
||||
|
||||
@@ -51,7 +51,9 @@ 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()
|
||||
@@ -132,9 +134,15 @@ 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)
|
||||
|
||||
|
||||
@@ -25,7 +25,12 @@ 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:
|
||||
@@ -46,7 +51,8 @@ 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
|
||||
|
||||
@@ -57,20 +63,28 @@ 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]
|
||||
|
||||
@@ -123,7 +123,9 @@ 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)
|
||||
@@ -178,7 +180,12 @@ 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"
|
||||
)
|
||||
@@ -186,12 +193,20 @@ 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
|
||||
@@ -200,7 +215,12 @@ 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"
|
||||
)
|
||||
@@ -228,7 +248,11 @@ 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"
|
||||
)
|
||||
|
||||
|
||||
@@ -264,7 +288,9 @@ 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)
|
||||
|
||||
@@ -22,7 +22,9 @@ func _setup_splash_screen_connection() -> void:
|
||||
# Try to find SplashScreen node
|
||||
splash_screen = get_node_or_null("SplashScreen")
|
||||
if not splash_screen:
|
||||
DebugManager.log_warn("SplashScreen node not found, trying alternative methods", "Main")
|
||||
DebugManager.log_warn(
|
||||
"SplashScreen node not found, trying alternative methods", "Main"
|
||||
)
|
||||
# Try to find by class or group
|
||||
var splash_nodes = get_tree().get_nodes_in_group("localizable")
|
||||
for node in splash_nodes:
|
||||
@@ -31,11 +33,15 @@ func _setup_splash_screen_connection() -> void:
|
||||
break
|
||||
|
||||
if splash_screen:
|
||||
DebugManager.log_debug("SplashScreen node found: %s" % splash_screen.name, "Main")
|
||||
DebugManager.log_debug(
|
||||
"SplashScreen node found: %s" % splash_screen.name, "Main"
|
||||
)
|
||||
# Try connecting to the signal if it exists
|
||||
if splash_screen.has_signal("confirm_pressed"):
|
||||
splash_screen.confirm_pressed.connect(_on_confirm_pressed)
|
||||
DebugManager.log_debug("Connected to confirm_pressed signal", "Main")
|
||||
DebugManager.log_debug(
|
||||
"Connected to confirm_pressed signal", "Main"
|
||||
)
|
||||
else:
|
||||
# Fallback: use input handling directly on the main scene
|
||||
DebugManager.log_warn("Using fallback input handling", "Main")
|
||||
|
||||
@@ -9,8 +9,10 @@ const YAML_SOURCES: Array[String] = [
|
||||
# "res://assets/sprites/sprite-sources.yaml",
|
||||
]
|
||||
|
||||
@onready var scroll_container: ScrollContainer = $MarginContainer/VBoxContainer/ScrollContainer
|
||||
@onready var credits_text: RichTextLabel = $MarginContainer/VBoxContainer/ScrollContainer/CreditsText
|
||||
@onready
|
||||
var scroll_container: ScrollContainer = $MarginContainer/VBoxContainer/ScrollContainer
|
||||
@onready
|
||||
var credits_text: RichTextLabel = $MarginContainer/VBoxContainer/ScrollContainer/CreditsText
|
||||
@onready var back_button: Button = $MarginContainer/VBoxContainer/BackButton
|
||||
|
||||
|
||||
@@ -40,7 +42,9 @@ func _load_yaml_file(yaml_path: String) -> Dictionary:
|
||||
var file := FileAccess.open(yaml_path, FileAccess.READ)
|
||||
|
||||
if not file:
|
||||
DebugManager.log_warn("Could not open YAML file: %s" % yaml_path, "Credits")
|
||||
DebugManager.log_warn(
|
||||
"Could not open YAML file: %s" % yaml_path, "Credits"
|
||||
)
|
||||
return {}
|
||||
|
||||
var content: String = file.get_as_text()
|
||||
@@ -67,10 +71,18 @@ func _parse_yaml_content(yaml_content: String) -> Dictionary:
|
||||
continue
|
||||
|
||||
# Top-level section (audio, sprites, textures, etc.)
|
||||
if not line.begins_with(" ") and not line.begins_with("\t") and trimmed.ends_with(":"):
|
||||
if (
|
||||
not line.begins_with(" ")
|
||||
and not line.begins_with("\t")
|
||||
and trimmed.ends_with(":")
|
||||
):
|
||||
if current_asset and not current_asset_data.is_empty():
|
||||
_store_asset_data(
|
||||
result, current_section, current_subsection, current_asset, current_asset_data
|
||||
result,
|
||||
current_section,
|
||||
current_subsection,
|
||||
current_asset,
|
||||
current_asset_data
|
||||
)
|
||||
current_section = trimmed.trim_suffix(":")
|
||||
current_subsection = ""
|
||||
@@ -80,22 +92,37 @@ func _parse_yaml_content(yaml_content: String) -> Dictionary:
|
||||
result[current_section] = {}
|
||||
|
||||
# Subsection (music, sfx, characters, etc.)
|
||||
elif line.begins_with(" ") and not line.begins_with(" ") and trimmed.ends_with(":"):
|
||||
elif (
|
||||
line.begins_with(" ")
|
||||
and not line.begins_with(" ")
|
||||
and trimmed.ends_with(":")
|
||||
):
|
||||
if current_asset and not current_asset_data.is_empty():
|
||||
_store_asset_data(
|
||||
result, current_section, current_subsection, current_asset, current_asset_data
|
||||
result,
|
||||
current_section,
|
||||
current_subsection,
|
||||
current_asset,
|
||||
current_asset_data
|
||||
)
|
||||
current_subsection = trimmed.trim_suffix(":")
|
||||
current_asset = ""
|
||||
current_asset_data = {}
|
||||
if current_section and not result[current_section].has(current_subsection):
|
||||
if (
|
||||
current_section
|
||||
and not result[current_section].has(current_subsection)
|
||||
):
|
||||
result[current_section][current_subsection] = {}
|
||||
|
||||
# Asset name
|
||||
elif trimmed.begins_with('"') and trimmed.contains('":'):
|
||||
if current_asset and not current_asset_data.is_empty():
|
||||
_store_asset_data(
|
||||
result, current_section, current_subsection, current_asset, current_asset_data
|
||||
result,
|
||||
current_section,
|
||||
current_subsection,
|
||||
current_asset,
|
||||
current_asset_data
|
||||
)
|
||||
var parts: Array = trimmed.split('"')
|
||||
current_asset = parts[1] if parts.size() > 1 else ""
|
||||
@@ -106,21 +133,31 @@ func _parse_yaml_content(yaml_content: String) -> Dictionary:
|
||||
var parts: Array = trimmed.split(":", false, 1)
|
||||
if parts.size() == 2:
|
||||
var key: String = parts[0].strip_edges()
|
||||
var value: String = parts[1].strip_edges().trim_prefix('"').trim_suffix('"')
|
||||
var value: String = (
|
||||
parts[1].strip_edges().trim_prefix('"').trim_suffix('"')
|
||||
)
|
||||
if value and value != '""':
|
||||
current_asset_data[key] = value
|
||||
|
||||
# Store last asset
|
||||
if current_asset and not current_asset_data.is_empty():
|
||||
_store_asset_data(
|
||||
result, current_section, current_subsection, current_asset, current_asset_data
|
||||
result,
|
||||
current_section,
|
||||
current_subsection,
|
||||
current_asset,
|
||||
current_asset_data
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
func _store_asset_data(
|
||||
result: Dictionary, section: String, subsection: String, asset: String, data: Dictionary
|
||||
result: Dictionary,
|
||||
section: String,
|
||||
subsection: String,
|
||||
asset: String,
|
||||
data: Dictionary
|
||||
) -> void:
|
||||
"""Store parsed asset data into result dictionary"""
|
||||
if not section or not asset:
|
||||
@@ -150,7 +187,9 @@ func _merge_credits_data(target: Dictionary, source: Dictionary) -> void:
|
||||
func _display_formatted_credits(credits_data: Dictionary) -> void:
|
||||
"""Generate BBCode formatted credits from parsed data"""
|
||||
if not credits_text:
|
||||
DebugManager.log_error("Credits text node is null, cannot display credits", "Credits")
|
||||
DebugManager.log_error(
|
||||
"Credits text node is null, cannot display credits", "Credits"
|
||||
)
|
||||
return
|
||||
|
||||
var credits_bbcode: String = "[center][b][font_size=32]CREDITS[/font_size][/b][/center]\n\n"
|
||||
@@ -227,11 +266,17 @@ func _on_back_button_pressed() -> void:
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_back") or event.is_action_pressed("action_east"):
|
||||
if (
|
||||
event.is_action_pressed("ui_back")
|
||||
or event.is_action_pressed("action_east")
|
||||
):
|
||||
_on_back_button_pressed()
|
||||
elif event.is_action_pressed("move_up") or event.is_action_pressed("ui_up"):
|
||||
_scroll_credits(-50.0)
|
||||
elif event.is_action_pressed("move_down") or event.is_action_pressed("ui_down"):
|
||||
elif (
|
||||
event.is_action_pressed("move_down")
|
||||
or event.is_action_pressed("ui_down")
|
||||
):
|
||||
_scroll_credits(50.0)
|
||||
|
||||
|
||||
@@ -239,4 +284,6 @@ func _scroll_credits(amount: float) -> void:
|
||||
"""Scroll the credits by the specified amount"""
|
||||
var current_scroll: float = scroll_container.scroll_vertical
|
||||
scroll_container.scroll_vertical = int(current_scroll + amount)
|
||||
DebugManager.log_debug("Scrolled credits to: %d" % scroll_container.scroll_vertical, "Credits")
|
||||
DebugManager.log_debug(
|
||||
"Scrolled credits to: %d" % scroll_container.scroll_vertical, "Credits"
|
||||
)
|
||||
|
||||
@@ -17,12 +17,16 @@ func _find_target_scene():
|
||||
# Fallback: search by common node names
|
||||
if not match3_scene:
|
||||
for possible_name in ["Match3", "match3", "Match3Game"]:
|
||||
match3_scene = current_scene.find_child(possible_name, true, false)
|
||||
match3_scene = current_scene.find_child(
|
||||
possible_name, true, false
|
||||
)
|
||||
if match3_scene:
|
||||
break
|
||||
|
||||
if match3_scene:
|
||||
DebugManager.log_debug("Found match3 scene: " + match3_scene.name, log_category)
|
||||
DebugManager.log_debug(
|
||||
"Found match3 scene: " + match3_scene.name, log_category
|
||||
)
|
||||
_update_ui_from_scene()
|
||||
_stop_search_timer()
|
||||
else:
|
||||
|
||||
@@ -8,7 +8,8 @@ const MIN_GRID_SIZE := 3
|
||||
const MIN_TILE_TYPES := 3
|
||||
const SCENE_SEARCH_COOLDOWN := 0.5
|
||||
|
||||
@export var target_script_path: String = "res://scenes/game/gameplays/Match3Gameplay.gd"
|
||||
@export
|
||||
var target_script_path: String = "res://scenes/game/gameplays/Match3Gameplay.gd"
|
||||
@export var log_category: String = "DebugMenu"
|
||||
|
||||
var match3_scene: Node2D
|
||||
@@ -16,8 +17,10 @@ var search_timer: Timer
|
||||
var last_scene_search_time: float = 0.0
|
||||
|
||||
@onready var regenerate_button: Button = $VBoxContainer/RegenerateButton
|
||||
@onready var gem_types_spinbox: SpinBox = $VBoxContainer/GemTypesContainer/GemTypesSpinBox
|
||||
@onready var gem_types_label: Label = $VBoxContainer/GemTypesContainer/GemTypesLabel
|
||||
@onready
|
||||
var gem_types_spinbox: SpinBox = $VBoxContainer/GemTypesContainer/GemTypesSpinBox
|
||||
@onready
|
||||
var gem_types_label: Label = $VBoxContainer/GemTypesContainer/GemTypesLabel
|
||||
@onready
|
||||
var grid_width_spinbox: SpinBox = $VBoxContainer/GridSizeContainer/GridWidthContainer/GridWidthSpinBox
|
||||
@onready
|
||||
@@ -86,7 +89,9 @@ func _setup_scene_finding() -> void:
|
||||
|
||||
# Virtual method - override in derived classes for specific finding logic
|
||||
func _find_target_scene() -> void:
|
||||
DebugManager.log_error("_find_target_scene() not implemented in derived class", log_category)
|
||||
DebugManager.log_error(
|
||||
"_find_target_scene() not implemented in derived class", log_category
|
||||
)
|
||||
|
||||
|
||||
func _find_node_by_script(node: Node, script_path: String) -> Node:
|
||||
@@ -114,10 +119,14 @@ func _update_ui_from_scene() -> void:
|
||||
# Connect to grid state loaded signal if not already connected
|
||||
if (
|
||||
match3_scene.has_signal("grid_state_loaded")
|
||||
and not match3_scene.grid_state_loaded.is_connected(_on_grid_state_loaded)
|
||||
and not match3_scene.grid_state_loaded.is_connected(
|
||||
_on_grid_state_loaded
|
||||
)
|
||||
):
|
||||
match3_scene.grid_state_loaded.connect(_on_grid_state_loaded)
|
||||
DebugManager.log_debug("Connected to grid_state_loaded signal", log_category)
|
||||
DebugManager.log_debug(
|
||||
"Connected to grid_state_loaded signal", log_category
|
||||
)
|
||||
|
||||
# Update gem types display
|
||||
if match3_scene.has_method("get") and "TILE_TYPES" in match3_scene:
|
||||
@@ -135,7 +144,10 @@ func _update_ui_from_scene() -> void:
|
||||
|
||||
func _on_grid_state_loaded(grid_size: Vector2i, tile_types: int) -> void:
|
||||
DebugManager.log_debug(
|
||||
"Grid state loaded signal received: size=%s, types=%d" % [grid_size, tile_types],
|
||||
(
|
||||
"Grid state loaded signal received: size=%s, types=%d"
|
||||
% [grid_size, tile_types]
|
||||
),
|
||||
log_category
|
||||
)
|
||||
|
||||
@@ -155,7 +167,10 @@ func _stop_search_timer() -> void:
|
||||
|
||||
|
||||
func _start_search_timer() -> void:
|
||||
if search_timer and not search_timer.timeout.is_connected(_find_target_scene):
|
||||
if (
|
||||
search_timer
|
||||
and not search_timer.timeout.is_connected(_find_target_scene)
|
||||
):
|
||||
search_timer.timeout.connect(_find_target_scene)
|
||||
search_timer.start()
|
||||
|
||||
@@ -176,7 +191,8 @@ func _refresh_current_values() -> void:
|
||||
# Refresh UI with current values from the scene
|
||||
if match3_scene:
|
||||
DebugManager.log_debug(
|
||||
"Refreshing debug menu values from current scene state", log_category
|
||||
"Refreshing debug menu values from current scene state",
|
||||
log_category
|
||||
)
|
||||
_update_ui_from_scene()
|
||||
|
||||
@@ -186,14 +202,18 @@ func _on_regenerate_pressed() -> void:
|
||||
_find_target_scene()
|
||||
|
||||
if not match3_scene:
|
||||
DebugManager.log_error("Could not find target scene for regeneration", log_category)
|
||||
DebugManager.log_error(
|
||||
"Could not find target scene for regeneration", log_category
|
||||
)
|
||||
return
|
||||
|
||||
if match3_scene.has_method("regenerate_grid"):
|
||||
DebugManager.log_debug("Calling regenerate_grid()", log_category)
|
||||
await match3_scene.regenerate_grid()
|
||||
else:
|
||||
DebugManager.log_error("Target scene does not have regenerate_grid method", log_category)
|
||||
DebugManager.log_error(
|
||||
"Target scene does not have regenerate_grid method", log_category
|
||||
)
|
||||
|
||||
|
||||
func _on_gem_types_changed(value: float) -> void:
|
||||
@@ -207,7 +227,9 @@ func _on_gem_types_changed(value: float) -> void:
|
||||
last_scene_search_time = current_time
|
||||
|
||||
if not match3_scene:
|
||||
DebugManager.log_error("Could not find target scene for gem types change", log_category)
|
||||
DebugManager.log_error(
|
||||
"Could not find target scene for gem types change", log_category
|
||||
)
|
||||
return
|
||||
|
||||
var new_value: int = int(value)
|
||||
@@ -221,15 +243,21 @@ func _on_gem_types_changed(value: float) -> void:
|
||||
log_category
|
||||
)
|
||||
# Reset to valid value
|
||||
gem_types_spinbox.value = clamp(new_value, MIN_TILE_TYPES, MAX_TILE_TYPES)
|
||||
gem_types_spinbox.value = clamp(
|
||||
new_value, MIN_TILE_TYPES, MAX_TILE_TYPES
|
||||
)
|
||||
return
|
||||
|
||||
if match3_scene.has_method("set_tile_types"):
|
||||
DebugManager.log_debug("Setting tile types to " + str(new_value), log_category)
|
||||
DebugManager.log_debug(
|
||||
"Setting tile types to " + str(new_value), log_category
|
||||
)
|
||||
await match3_scene.set_tile_types(new_value)
|
||||
gem_types_label.text = "Gem Types: " + str(new_value)
|
||||
else:
|
||||
DebugManager.log_error("Target scene does not have set_tile_types method", log_category)
|
||||
DebugManager.log_error(
|
||||
"Target scene does not have set_tile_types method", log_category
|
||||
)
|
||||
# Fallback: try to set TILE_TYPES directly
|
||||
if "TILE_TYPES" in match3_scene:
|
||||
match3_scene.TILE_TYPES = new_value
|
||||
@@ -247,7 +275,9 @@ func _on_grid_width_changed(value: float) -> void:
|
||||
last_scene_search_time = current_time
|
||||
|
||||
if not match3_scene:
|
||||
DebugManager.log_error("Could not find target scene for grid width change", log_category)
|
||||
DebugManager.log_error(
|
||||
"Could not find target scene for grid width change", log_category
|
||||
)
|
||||
return
|
||||
|
||||
var new_width: int = int(value)
|
||||
@@ -261,7 +291,9 @@ func _on_grid_width_changed(value: float) -> void:
|
||||
log_category
|
||||
)
|
||||
# Reset to valid value
|
||||
grid_width_spinbox.value = clamp(new_width, MIN_GRID_SIZE, MAX_GRID_SIZE)
|
||||
grid_width_spinbox.value = clamp(
|
||||
new_width, MIN_GRID_SIZE, MAX_GRID_SIZE
|
||||
)
|
||||
return
|
||||
|
||||
grid_width_label.text = "Width: " + str(new_width)
|
||||
@@ -271,11 +303,19 @@ func _on_grid_width_changed(value: float) -> void:
|
||||
|
||||
if match3_scene.has_method("set_grid_size"):
|
||||
DebugManager.log_debug(
|
||||
"Setting grid size to " + str(new_width) + "x" + str(current_height), log_category
|
||||
(
|
||||
"Setting grid size to "
|
||||
+ str(new_width)
|
||||
+ "x"
|
||||
+ str(current_height)
|
||||
),
|
||||
log_category
|
||||
)
|
||||
await match3_scene.set_grid_size(Vector2i(new_width, current_height))
|
||||
else:
|
||||
DebugManager.log_error("Target scene does not have set_grid_size method", log_category)
|
||||
DebugManager.log_error(
|
||||
"Target scene does not have set_grid_size method", log_category
|
||||
)
|
||||
|
||||
|
||||
func _on_grid_height_changed(value: float) -> void:
|
||||
@@ -289,7 +329,9 @@ func _on_grid_height_changed(value: float) -> void:
|
||||
last_scene_search_time = current_time
|
||||
|
||||
if not match3_scene:
|
||||
DebugManager.log_error("Could not find target scene for grid height change", log_category)
|
||||
DebugManager.log_error(
|
||||
"Could not find target scene for grid height change", log_category
|
||||
)
|
||||
return
|
||||
|
||||
var new_height: int = int(value)
|
||||
@@ -303,7 +345,9 @@ func _on_grid_height_changed(value: float) -> void:
|
||||
log_category
|
||||
)
|
||||
# Reset to valid value
|
||||
grid_height_spinbox.value = clamp(new_height, MIN_GRID_SIZE, MAX_GRID_SIZE)
|
||||
grid_height_spinbox.value = clamp(
|
||||
new_height, MIN_GRID_SIZE, MAX_GRID_SIZE
|
||||
)
|
||||
return
|
||||
|
||||
grid_height_label.text = "Height: " + str(new_height)
|
||||
@@ -313,8 +357,16 @@ func _on_grid_height_changed(value: float) -> void:
|
||||
|
||||
if match3_scene.has_method("set_grid_size"):
|
||||
DebugManager.log_debug(
|
||||
"Setting grid size to " + str(current_width) + "x" + str(new_height), log_category
|
||||
(
|
||||
"Setting grid size to "
|
||||
+ str(current_width)
|
||||
+ "x"
|
||||
+ str(new_height)
|
||||
),
|
||||
log_category
|
||||
)
|
||||
await match3_scene.set_grid_size(Vector2i(current_width, new_height))
|
||||
else:
|
||||
DebugManager.log_error("Target scene does not have set_grid_size method", log_category)
|
||||
DebugManager.log_error(
|
||||
"Target scene does not have set_grid_size method", log_category
|
||||
)
|
||||
|
||||
@@ -81,13 +81,17 @@ func _navigate_menu(direction: int) -> void:
|
||||
if current_menu_index < 0:
|
||||
current_menu_index = menu_buttons.size() - 1
|
||||
_update_visual_selection()
|
||||
DebugManager.log_info("Menu navigation: index " + str(current_menu_index), "MainMenu")
|
||||
DebugManager.log_info(
|
||||
"Menu navigation: index " + str(current_menu_index), "MainMenu"
|
||||
)
|
||||
|
||||
|
||||
func _activate_current_button() -> void:
|
||||
if current_menu_index >= 0 and current_menu_index < menu_buttons.size():
|
||||
var button: Button = menu_buttons[current_menu_index]
|
||||
DebugManager.log_info("Activating button via keyboard/gamepad: " + button.text, "MainMenu")
|
||||
DebugManager.log_info(
|
||||
"Activating button via keyboard/gamepad: " + button.text, "MainMenu"
|
||||
)
|
||||
button.pressed.emit()
|
||||
|
||||
|
||||
@@ -95,7 +99,9 @@ func _update_visual_selection() -> void:
|
||||
for i in range(menu_buttons.size()):
|
||||
var button: Button = menu_buttons[i]
|
||||
if i == current_menu_index:
|
||||
button.scale = original_button_scales[i] * UIConstants.BUTTON_HOVER_SCALE
|
||||
button.scale = (
|
||||
original_button_scales[i] * UIConstants.BUTTON_HOVER_SCALE
|
||||
)
|
||||
button.modulate = Color(1.2, 1.2, 1.0)
|
||||
else:
|
||||
button.scale = original_button_scales[i]
|
||||
|
||||
@@ -14,10 +14,13 @@ var current_control_index: int = 0
|
||||
var original_control_scales: Array[Vector2] = []
|
||||
var original_control_modulates: Array[Color] = []
|
||||
|
||||
@onready var master_slider = $SettingsContainer/MasterVolumeContainer/MasterVolumeSlider
|
||||
@onready var music_slider = $SettingsContainer/MusicVolumeContainer/MusicVolumeSlider
|
||||
@onready
|
||||
var master_slider = $SettingsContainer/MasterVolumeContainer/MasterVolumeSlider
|
||||
@onready
|
||||
var music_slider = $SettingsContainer/MusicVolumeContainer/MusicVolumeSlider
|
||||
@onready var sfx_slider = $SettingsContainer/SFXVolumeContainer/SFXVolumeSlider
|
||||
@onready var language_stepper = $SettingsContainer/LanguageContainer/LanguageStepper
|
||||
@onready
|
||||
var language_stepper = $SettingsContainer/LanguageContainer/LanguageStepper
|
||||
@onready var reset_progress_button = $ResetSettingsContainer/ResetProgressButton
|
||||
|
||||
|
||||
@@ -26,11 +29,15 @@ func _ready() -> void:
|
||||
DebugManager.log_info("SettingsMenu ready", "Settings")
|
||||
# Language selector is initialized automatically
|
||||
|
||||
var master_callback: Callable = _on_volume_slider_changed.bind("master_volume")
|
||||
var master_callback: Callable = _on_volume_slider_changed.bind(
|
||||
"master_volume"
|
||||
)
|
||||
if not master_slider.value_changed.is_connected(master_callback):
|
||||
master_slider.value_changed.connect(master_callback)
|
||||
|
||||
var music_callback: Callable = _on_volume_slider_changed.bind("music_volume")
|
||||
var music_callback: Callable = _on_volume_slider_changed.bind(
|
||||
"music_volume"
|
||||
)
|
||||
if not music_slider.value_changed.is_connected(music_callback):
|
||||
music_slider.value_changed.connect(music_callback)
|
||||
|
||||
@@ -57,20 +64,28 @@ func _update_controls_from_settings() -> void:
|
||||
func _on_volume_slider_changed(value: float, setting_key: String) -> void:
|
||||
# Input validation for volume settings
|
||||
if not setting_key in ["master_volume", "music_volume", "sfx_volume"]:
|
||||
DebugManager.log_error("Invalid volume setting key: " + str(setting_key), "Settings")
|
||||
DebugManager.log_error(
|
||||
"Invalid volume setting key: " + str(setting_key), "Settings"
|
||||
)
|
||||
return
|
||||
|
||||
if typeof(value) != TYPE_FLOAT and typeof(value) != TYPE_INT:
|
||||
DebugManager.log_error("Invalid volume value type: " + str(typeof(value)), "Settings")
|
||||
DebugManager.log_error(
|
||||
"Invalid volume value type: " + str(typeof(value)), "Settings"
|
||||
)
|
||||
return
|
||||
|
||||
# Clamp value to valid range
|
||||
var clamped_value: float = clamp(float(value), 0.0, 1.0)
|
||||
if clamped_value != value:
|
||||
DebugManager.log_warn("Volume value %f clamped to %f" % [value, clamped_value], "Settings")
|
||||
DebugManager.log_warn(
|
||||
"Volume value %f clamped to %f" % [value, clamped_value], "Settings"
|
||||
)
|
||||
|
||||
if not settings_manager.set_setting(setting_key, clamped_value):
|
||||
DebugManager.log_error("Failed to set volume setting: " + setting_key, "Settings")
|
||||
DebugManager.log_error(
|
||||
"Failed to set volume setting: " + setting_key, "Settings"
|
||||
)
|
||||
|
||||
|
||||
func _exit_settings() -> void:
|
||||
@@ -80,8 +95,13 @@ func _exit_settings() -> void:
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("action_east") or event.is_action_pressed("pause_menu"):
|
||||
DebugManager.log_debug("Cancel/back action pressed in settings", "Settings")
|
||||
if (
|
||||
event.is_action_pressed("action_east")
|
||||
or event.is_action_pressed("pause_menu")
|
||||
):
|
||||
DebugManager.log_debug(
|
||||
"Cancel/back action pressed in settings", "Settings"
|
||||
)
|
||||
_exit_settings()
|
||||
get_viewport().set_input_as_handled()
|
||||
return
|
||||
@@ -116,8 +136,12 @@ func _on_back_button_pressed() -> void:
|
||||
|
||||
func update_text() -> void:
|
||||
$SettingsContainer/SettingsTitle.text = tr("settings_title")
|
||||
$SettingsContainer/MasterVolumeContainer/MasterVolume.text = tr("master_volume")
|
||||
$SettingsContainer/MusicVolumeContainer/MusicVolume.text = tr("music_volume")
|
||||
$SettingsContainer/MasterVolumeContainer/MasterVolume.text = tr(
|
||||
"master_volume"
|
||||
)
|
||||
$SettingsContainer/MusicVolumeContainer/MusicVolume.text = tr(
|
||||
"music_volume"
|
||||
)
|
||||
$SettingsContainer/SFXVolumeContainer/SFXVolume.text = tr("sfx_volume")
|
||||
$SettingsContainer/LanguageContainer/LanguageLabel.text = tr("language")
|
||||
$BackButtonContainer/BackButton.text = tr("back")
|
||||
@@ -129,7 +153,9 @@ func _on_reset_setting_button_pressed() -> void:
|
||||
DebugManager.log_info("Resetting settings", "Settings")
|
||||
settings_manager.reset_settings_to_defaults()
|
||||
_update_controls_from_settings()
|
||||
localization_manager.change_language(settings_manager.get_setting("language"))
|
||||
localization_manager.change_language(
|
||||
settings_manager.get_setting("language")
|
||||
)
|
||||
|
||||
|
||||
func _setup_navigation_system() -> void:
|
||||
@@ -156,15 +182,22 @@ func _setup_navigation_system() -> void:
|
||||
|
||||
func _navigate_controls(direction: int) -> void:
|
||||
AudioManager.play_ui_click()
|
||||
current_control_index = (current_control_index + direction) % navigable_controls.size()
|
||||
current_control_index = (
|
||||
(current_control_index + direction) % navigable_controls.size()
|
||||
)
|
||||
if current_control_index < 0:
|
||||
current_control_index = navigable_controls.size() - 1
|
||||
_update_visual_selection()
|
||||
DebugManager.log_info("Settings navigation: index " + str(current_control_index), "Settings")
|
||||
DebugManager.log_info(
|
||||
"Settings navigation: index " + str(current_control_index), "Settings"
|
||||
)
|
||||
|
||||
|
||||
func _adjust_current_control(direction: int) -> void:
|
||||
if current_control_index < 0 or current_control_index >= navigable_controls.size():
|
||||
if (
|
||||
current_control_index < 0
|
||||
or current_control_index >= navigable_controls.size()
|
||||
):
|
||||
return
|
||||
|
||||
var control: Control = navigable_controls[current_control_index]
|
||||
@@ -178,17 +211,26 @@ func _adjust_current_control(direction: int) -> void:
|
||||
slider.value = new_value
|
||||
AudioManager.play_ui_click()
|
||||
DebugManager.log_info(
|
||||
"Slider adjusted: %s = %f" % [_get_control_name(control), new_value], "Settings"
|
||||
(
|
||||
"Slider adjusted: %s = %f"
|
||||
% [_get_control_name(control), new_value]
|
||||
),
|
||||
"Settings"
|
||||
)
|
||||
|
||||
# Handle language stepper with left/right
|
||||
elif control == language_stepper:
|
||||
if language_stepper.handle_input_action("move_left" if direction == -1 else "move_right"):
|
||||
if language_stepper.handle_input_action(
|
||||
"move_left" if direction == -1 else "move_right"
|
||||
):
|
||||
AudioManager.play_ui_click()
|
||||
|
||||
|
||||
func _activate_current_control() -> void:
|
||||
if current_control_index < 0 or current_control_index >= navigable_controls.size():
|
||||
if (
|
||||
current_control_index < 0
|
||||
or current_control_index >= navigable_controls.size()
|
||||
):
|
||||
return
|
||||
|
||||
var control: Control = navigable_controls[current_control_index]
|
||||
@@ -196,12 +238,17 @@ func _activate_current_control() -> void:
|
||||
# Handle buttons
|
||||
if control is Button:
|
||||
AudioManager.play_ui_click()
|
||||
DebugManager.log_info("Activating button via keyboard/gamepad: " + control.text, "Settings")
|
||||
DebugManager.log_info(
|
||||
"Activating button via keyboard/gamepad: " + control.text,
|
||||
"Settings"
|
||||
)
|
||||
control.pressed.emit()
|
||||
|
||||
# Handle language stepper (no action needed on activation, left/right handles it)
|
||||
elif control == language_stepper:
|
||||
DebugManager.log_info("Language stepper selected - use left/right to change", "Settings")
|
||||
DebugManager.log_info(
|
||||
"Language stepper selected - use left/right to change", "Settings"
|
||||
)
|
||||
|
||||
|
||||
func _update_visual_selection() -> void:
|
||||
@@ -212,7 +259,10 @@ func _update_visual_selection() -> void:
|
||||
if control == language_stepper:
|
||||
language_stepper.set_highlighted(true)
|
||||
else:
|
||||
control.scale = original_control_scales[i] * UIConstants.UI_CONTROL_HIGHLIGHT_SCALE
|
||||
control.scale = (
|
||||
original_control_scales[i]
|
||||
* UIConstants.UI_CONTROL_HIGHLIGHT_SCALE
|
||||
)
|
||||
control.modulate = Color(1.1, 1.1, 0.9)
|
||||
else:
|
||||
# Reset highlighting
|
||||
@@ -235,9 +285,17 @@ func _get_control_name(control: Control) -> String:
|
||||
return "button"
|
||||
|
||||
|
||||
func _on_language_stepper_value_changed(new_value: String, new_index: float) -> void:
|
||||
func _on_language_stepper_value_changed(
|
||||
new_value: String, new_index: float
|
||||
) -> void:
|
||||
DebugManager.log_info(
|
||||
"Language changed via ValueStepper: " + new_value + " (index: " + str(int(new_index)) + ")",
|
||||
(
|
||||
"Language changed via ValueStepper: "
|
||||
+ new_value
|
||||
+ " (index: "
|
||||
+ str(int(new_index))
|
||||
+ ")"
|
||||
),
|
||||
"Settings"
|
||||
)
|
||||
|
||||
|
||||
@@ -30,17 +30,25 @@ var is_highlighted: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
DebugManager.log_info("ValueStepper ready for: " + data_source, "ValueStepper")
|
||||
DebugManager.log_info(
|
||||
"ValueStepper ready for: " + data_source, "ValueStepper"
|
||||
)
|
||||
|
||||
# Store original visual properties
|
||||
original_scale = scale
|
||||
original_modulate = modulate
|
||||
|
||||
# Connect button signals
|
||||
if left_button and not left_button.pressed.is_connected(_on_left_button_pressed):
|
||||
if (
|
||||
left_button
|
||||
and not left_button.pressed.is_connected(_on_left_button_pressed)
|
||||
):
|
||||
left_button.pressed.connect(_on_left_button_pressed)
|
||||
|
||||
if right_button and not right_button.pressed.is_connected(_on_right_button_pressed):
|
||||
if (
|
||||
right_button
|
||||
and not right_button.pressed.is_connected(_on_right_button_pressed)
|
||||
):
|
||||
right_button.pressed.connect(_on_right_button_pressed)
|
||||
|
||||
# Initialize data
|
||||
@@ -58,7 +66,9 @@ func _load_data() -> void:
|
||||
"difficulty":
|
||||
_load_difficulty_data()
|
||||
_:
|
||||
DebugManager.log_warn("Unknown data_source: " + data_source, "ValueStepper")
|
||||
DebugManager.log_warn(
|
||||
"Unknown data_source: " + data_source, "ValueStepper"
|
||||
)
|
||||
|
||||
|
||||
func _load_language_data() -> void:
|
||||
@@ -68,22 +78,30 @@ func _load_language_data() -> void:
|
||||
display_names.clear()
|
||||
for lang_code in languages_data.languages.keys():
|
||||
values.append(lang_code)
|
||||
display_names.append(languages_data.languages[lang_code]["display_name"])
|
||||
display_names.append(
|
||||
languages_data.languages[lang_code]["display_name"]
|
||||
)
|
||||
|
||||
# Set current index based on current language
|
||||
var current_lang: String = SettingsManager.get_setting("language")
|
||||
var index: int = values.find(current_lang)
|
||||
current_index = max(0, index)
|
||||
|
||||
DebugManager.log_info("Loaded %d languages" % values.size(), "ValueStepper")
|
||||
DebugManager.log_info(
|
||||
"Loaded %d languages" % values.size(), "ValueStepper"
|
||||
)
|
||||
|
||||
|
||||
func _load_resolution_data() -> void:
|
||||
# Example resolution data - customize as needed
|
||||
values = ["1920x1080", "1366x768", "1280x720", "1024x768"]
|
||||
display_names = ["1920×1080 (Full HD)", "1366×768", "1280×720 (HD)", "1024×768"]
|
||||
display_names = [
|
||||
"1920×1080 (Full HD)", "1366×768", "1280×720 (HD)", "1024×768"
|
||||
]
|
||||
current_index = 0
|
||||
DebugManager.log_info("Loaded %d resolutions" % values.size(), "ValueStepper")
|
||||
DebugManager.log_info(
|
||||
"Loaded %d resolutions" % values.size(), "ValueStepper"
|
||||
)
|
||||
|
||||
|
||||
func _load_difficulty_data() -> void:
|
||||
@@ -91,12 +109,18 @@ func _load_difficulty_data() -> void:
|
||||
values = ["easy", "normal", "hard", "nightmare"]
|
||||
display_names = ["Easy", "Normal", "Hard", "Nightmare"]
|
||||
current_index = 1 # Default to "normal"
|
||||
DebugManager.log_info("Loaded %d difficulty levels" % values.size(), "ValueStepper")
|
||||
DebugManager.log_info(
|
||||
"Loaded %d difficulty levels" % values.size(), "ValueStepper"
|
||||
)
|
||||
|
||||
|
||||
## Updates the display text based on current selection
|
||||
func _update_display() -> void:
|
||||
if values.size() == 0 or current_index < 0 or current_index >= values.size():
|
||||
if (
|
||||
values.size() == 0
|
||||
or current_index < 0
|
||||
or current_index >= values.size()
|
||||
):
|
||||
value_display.text = "N/A"
|
||||
return
|
||||
|
||||
@@ -109,7 +133,9 @@ func _update_display() -> void:
|
||||
## Changes the current value by the specified direction (-1 for previous, +1 for next)
|
||||
func change_value(direction: int) -> void:
|
||||
if values.size() == 0:
|
||||
DebugManager.log_warn("No values available for: " + data_source, "ValueStepper")
|
||||
DebugManager.log_warn(
|
||||
"No values available for: " + data_source, "ValueStepper"
|
||||
)
|
||||
return
|
||||
|
||||
var new_index: int = (current_index + direction) % values.size()
|
||||
@@ -123,7 +149,14 @@ func change_value(direction: int) -> void:
|
||||
_apply_value_change(new_value, current_index)
|
||||
value_changed.emit(new_value, current_index)
|
||||
DebugManager.log_info(
|
||||
"Value changed to: " + new_value + " (index: " + str(current_index) + ")", "ValueStepper"
|
||||
(
|
||||
"Value changed to: "
|
||||
+ new_value
|
||||
+ " (index: "
|
||||
+ str(current_index)
|
||||
+ ")"
|
||||
),
|
||||
"ValueStepper"
|
||||
)
|
||||
|
||||
|
||||
@@ -136,10 +169,14 @@ func _apply_value_change(new_value: String, _index: int) -> void:
|
||||
LocalizationManager.change_language(new_value)
|
||||
"resolution":
|
||||
# Apply resolution change logic here
|
||||
DebugManager.log_info("Resolution would change to: " + new_value, "ValueStepper")
|
||||
DebugManager.log_info(
|
||||
"Resolution would change to: " + new_value, "ValueStepper"
|
||||
)
|
||||
"difficulty":
|
||||
# Apply difficulty change logic here
|
||||
DebugManager.log_info("Difficulty would change to: " + new_value, "ValueStepper")
|
||||
DebugManager.log_info(
|
||||
"Difficulty would change to: " + new_value, "ValueStepper"
|
||||
)
|
||||
|
||||
|
||||
## Sets up custom values for the stepper
|
||||
@@ -148,16 +185,24 @@ func setup_custom_values(
|
||||
) -> void:
|
||||
values = custom_values.duplicate()
|
||||
display_names = (
|
||||
custom_display_names.duplicate() if custom_display_names.size() > 0 else values.duplicate()
|
||||
custom_display_names.duplicate()
|
||||
if custom_display_names.size() > 0
|
||||
else values.duplicate()
|
||||
)
|
||||
current_index = 0
|
||||
_update_display()
|
||||
DebugManager.log_info("Setup custom values: " + str(values.size()) + " items", "ValueStepper")
|
||||
DebugManager.log_info(
|
||||
"Setup custom values: " + str(values.size()) + " items", "ValueStepper"
|
||||
)
|
||||
|
||||
|
||||
## Gets the current value
|
||||
func get_current_value() -> String:
|
||||
if values.size() > 0 and current_index >= 0 and current_index < values.size():
|
||||
if (
|
||||
values.size() > 0
|
||||
and current_index >= 0
|
||||
and current_index < values.size()
|
||||
):
|
||||
return values[current_index]
|
||||
return ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user