make grid shuffle, grid sizy, gem color types

This commit is contained in:
2025-09-24 01:39:18 +04:00
parent de68edb1b0
commit 122b5cb55f
12 changed files with 565 additions and 48 deletions

203
scenes/ui/DebugMenu.gd Normal file
View File

@@ -0,0 +1,203 @@
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
var search_timer: Timer
# Fixed: Add cleanup function
func _exit_tree():
if search_timer:
search_timer.queue_free()
func _ready():
visible = false
DebugManager.debug_toggled.connect(_on_debug_toggled)
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)
# Initialize gem types spinbox
gem_types_spinbox.min_value = 3
gem_types_spinbox.max_value = 8
gem_types_spinbox.step = 1
gem_types_spinbox.value = 5 # Default value
# Initialize grid size spinboxes
grid_width_spinbox.min_value = 4
grid_width_spinbox.max_value = 12
grid_width_spinbox.step = 1
grid_width_spinbox.value = 8 # Default value
grid_height_spinbox.min_value = 4
grid_height_spinbox.max_value = 12
grid_height_spinbox.step = 1
grid_height_spinbox.value = 8 # Default value
# Fixed: Create timer for periodic match3 scene search
search_timer = Timer.new()
search_timer.wait_time = 0.1
search_timer.timeout.connect(_find_match3_scene)
add_child(search_timer)
# Start searching immediately and continue until found
_find_match3_scene()
func _find_match3_scene():
# Fixed: Search more thoroughly for match3 scene
if match3_scene:
# Already found, stop searching
if search_timer and search_timer.timeout.is_connected(_find_match3_scene):
search_timer.stop()
return
# Search in current scene tree
var current_scene = get_tree().current_scene
if current_scene:
# Try to find match3 by class name first
match3_scene = _find_node_by_script(current_scene, "res://scenes/match3/match3.gd")
# 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)
if match3_scene:
break
if match3_scene:
print("Debug: Found match3 scene: ", match3_scene.name)
# Update UI with current values
if 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 values
if "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)
# Stop the search timer
if search_timer and search_timer.timeout.is_connected(_find_match3_scene):
search_timer.stop()
else:
# Continue searching if not found
if search_timer and not search_timer.timeout.is_connected(_find_match3_scene):
search_timer.timeout.connect(_find_match3_scene)
search_timer.start()
func _find_node_by_script(node: Node, script_path: String) -> Node:
# Helper function to find node by its script path
if node.get_script():
var node_script = node.get_script()
if node_script.resource_path == script_path:
return node
for child in node.get_children():
var result = _find_node_by_script(child, script_path)
if result:
return result
return null
func _on_debug_toggled(enabled: bool):
visible = enabled
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:
print("Error: Could not find match3 scene for regeneration")
return
if match3_scene.has_method("regenerate_grid"):
print("Debug: Calling regenerate_grid()")
await match3_scene.regenerate_grid()
else:
print("Error: match3_scene does not have regenerate_grid method")
func _on_gem_types_changed(value: float):
if not match3_scene:
_find_match3_scene()
if not match3_scene:
print("Error: Could not find match3 scene for gem types change")
return
var new_value = int(value)
if match3_scene.has_method("set_tile_types"):
print("Debug: Setting tile types to ", new_value)
await match3_scene.set_tile_types(new_value)
gem_types_label.text = "Gem Types: " + str(new_value)
else:
print("Error: match3_scene does not have set_tile_types method")
# Fallback: try to set TILE_TYPES directly
if "TILE_TYPES" in match3_scene:
match3_scene.TILE_TYPES = new_value
gem_types_label.text = "Gem Types: " + str(new_value)
func _on_grid_width_changed(value: float):
if not match3_scene:
_find_match3_scene()
if not match3_scene:
print("Error: Could not find match3 scene for grid width change")
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"):
print("Debug: Setting grid size to ", new_width, "x", current_height)
await match3_scene.set_grid_size(Vector2i(new_width, current_height))
else:
print("Error: match3_scene does not have set_grid_size method")
func _on_grid_height_changed(value: float):
if not match3_scene:
_find_match3_scene()
if not match3_scene:
print("Error: Could not find match3 scene for grid height change")
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"):
print("Debug: Setting grid size to ", current_width, "x", new_height)
await match3_scene.set_grid_size(Vector2i(current_width, new_height))
else:
print("Error: match3_scene does not have set_grid_size method")