extends Control @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 grid_width_spinbox: SpinBox = $VBoxContainer/GridSizeContainer/GridWidthContainer/GridWidthSpinBox @onready var grid_height_spinbox: SpinBox = $VBoxContainer/GridSizeContainer/GridHeightContainer/GridHeightSpinBox @onready var grid_width_label: Label = $VBoxContainer/GridSizeContainer/GridWidthContainer/GridWidthLabel @onready var grid_height_label: Label = $VBoxContainer/GridSizeContainer/GridHeightContainer/GridHeightLabel var match3_scene: Node2D func _ready(): DebugManager.log_debug("Match3DebugMenu _ready() called", "Match3") DebugManager.debug_toggled.connect(_on_debug_toggled) # Initialize with current debug state var current_debug_state = DebugManager.is_debug_enabled() DebugManager.log_debug("Match3DebugMenu current debug state is " + str(current_debug_state), "Match3") visible = current_debug_state DebugManager.log_debug("Match3DebugMenu initial visibility set to " + str(visible), "Match3") if current_debug_state: _on_debug_toggled(true) regenerate_button.pressed.connect(_on_regenerate_pressed) gem_types_spinbox.value_changed.connect(_on_gem_types_changed) grid_width_spinbox.value_changed.connect(_on_grid_width_changed) grid_height_spinbox.value_changed.connect(_on_grid_height_changed) func _find_match3_scene(): # Debug menu is now: Match3 -> UILayer -> Match3DebugMenu # So we need to go up two levels: get_parent() = UILayer, get_parent().get_parent() = Match3 var ui_layer = get_parent() if ui_layer and ui_layer is CanvasLayer: match3_scene = ui_layer.get_parent() if match3_scene and match3_scene.get_script(): var script_path = match3_scene.get_script().resource_path if script_path == "res://scenes/game/gameplays/match3_gameplay.gd": DebugManager.log_debug("Found match3 scene: " + match3_scene.name + " at path: " + str(match3_scene.get_path()), "Match3") return # If we couldn't find it, clear the reference match3_scene = null DebugManager.log_error("Could not find match3_gameplay scene", "Match3") func _on_debug_toggled(enabled: bool): DebugManager.log_debug("Match3DebugMenu debug toggled to " + str(enabled), "Match3") visible = enabled DebugManager.log_debug("Match3DebugMenu visibility set to " + str(visible), "Match3") if enabled: # Always refresh match3 scene reference when debug menu opens if not match3_scene: _find_match3_scene() # Update display values if match3_scene and match3_scene.has_method("get") and "TILE_TYPES" in match3_scene: gem_types_spinbox.value = match3_scene.TILE_TYPES gem_types_label.text = "Gem Types: " + str(match3_scene.TILE_TYPES) # Update grid size display values if match3_scene and "GRID_SIZE" in match3_scene: var grid_size = match3_scene.GRID_SIZE grid_width_spinbox.value = grid_size.x grid_height_spinbox.value = grid_size.y grid_width_label.text = "Width: " + str(grid_size.x) grid_height_label.text = "Height: " + str(grid_size.y) func _on_regenerate_pressed(): if not match3_scene: _find_match3_scene() if not match3_scene: DebugManager.log_error("Could not find match3 scene for regeneration", "Match3") return if match3_scene.has_method("regenerate_grid"): DebugManager.log_debug("Calling regenerate_grid()", "Match3") await match3_scene.regenerate_grid() else: DebugManager.log_error("match3_scene does not have regenerate_grid method", "Match3") func _on_gem_types_changed(value: float): if not match3_scene: _find_match3_scene() if not match3_scene: DebugManager.log_error("Could not find match3 scene for gem types change", "Match3") return var new_value = int(value) if match3_scene.has_method("set_tile_types"): DebugManager.log_debug("Setting tile types to " + str(new_value), "Match3") await match3_scene.set_tile_types(new_value) gem_types_label.text = "Gem Types: " + str(new_value) else: DebugManager.log_error("match3_scene does not have set_tile_types method", "Match3") func _on_grid_width_changed(value: float): if not match3_scene: _find_match3_scene() if not match3_scene: DebugManager.log_error("Could not find match3 scene for grid width change", "Match3") return var new_width = int(value) grid_width_label.text = "Width: " + str(new_width) # Get current height var current_height = int(grid_height_spinbox.value) if match3_scene.has_method("set_grid_size"): DebugManager.log_debug("Setting grid size to " + str(new_width) + "x" + str(current_height), "Match3") await match3_scene.set_grid_size(Vector2i(new_width, current_height)) func _on_grid_height_changed(value: float): if not match3_scene: _find_match3_scene() if not match3_scene: DebugManager.log_error("Could not find match3 scene for grid height change", "Match3") return var new_height = int(value) grid_height_label.text = "Height: " + str(new_height) # Get current width var current_width = int(grid_width_spinbox.value) if match3_scene.has_method("set_grid_size"): DebugManager.log_debug("Setting grid size to " + str(current_width) + "x" + str(new_height), "Match3") await match3_scene.set_grid_size(Vector2i(current_width, new_height))