Add gdlint and gdformat scripts
This commit is contained in:
@@ -4,10 +4,14 @@ 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
|
||||
@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
|
||||
|
||||
@export var target_script_path: String = "res://scenes/game/gameplays/match3_gameplay.gd"
|
||||
@export var log_category: String = "DebugMenu"
|
||||
@@ -23,16 +27,18 @@ var search_timer: Timer
|
||||
var last_scene_search_time: float = 0.0
|
||||
const SCENE_SEARCH_COOLDOWN := 0.5 # Prevent excessive scene searching
|
||||
|
||||
func _exit_tree():
|
||||
|
||||
func _exit_tree() -> void:
|
||||
if search_timer:
|
||||
search_timer.queue_free()
|
||||
|
||||
func _ready():
|
||||
|
||||
func _ready() -> void:
|
||||
DebugManager.log_debug("DebugMenuBase _ready() called", log_category)
|
||||
DebugManager.debug_toggled.connect(_on_debug_toggled)
|
||||
|
||||
# Initialize with current debug state
|
||||
var current_debug_state = DebugManager.is_debug_enabled()
|
||||
var current_debug_state: bool = DebugManager.is_debug_enabled()
|
||||
visible = current_debug_state
|
||||
|
||||
# Connect signals
|
||||
@@ -50,7 +56,8 @@ func _ready():
|
||||
# Start searching for target scene
|
||||
_find_target_scene()
|
||||
|
||||
func _initialize_spinboxes():
|
||||
|
||||
func _initialize_spinboxes() -> void:
|
||||
# Initialize gem types spinbox with safety limits
|
||||
gem_types_spinbox.min_value = MIN_TILE_TYPES
|
||||
gem_types_spinbox.max_value = MAX_TILE_TYPES
|
||||
@@ -68,40 +75,47 @@ func _initialize_spinboxes():
|
||||
grid_height_spinbox.step = 1
|
||||
grid_height_spinbox.value = 8 # Default value
|
||||
|
||||
func _setup_scene_finding():
|
||||
|
||||
func _setup_scene_finding() -> void:
|
||||
# Create timer for periodic scene search with longer intervals to reduce CPU usage
|
||||
search_timer = Timer.new()
|
||||
search_timer.wait_time = 0.5 # Reduced frequency from 0.1 to 0.5 seconds
|
||||
search_timer.timeout.connect(_find_target_scene)
|
||||
add_child(search_timer)
|
||||
|
||||
|
||||
# Virtual method - override in derived classes for specific finding logic
|
||||
func _find_target_scene():
|
||||
func _find_target_scene() -> void:
|
||||
DebugManager.log_error("_find_target_scene() not implemented in derived class", log_category)
|
||||
|
||||
|
||||
func _find_node_by_script(node: Node, script_path: String) -> Node:
|
||||
# Helper function to find node by its script path
|
||||
if not node:
|
||||
return null
|
||||
|
||||
if node.get_script():
|
||||
var node_script = node.get_script()
|
||||
var node_script: 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)
|
||||
var result: Node = _find_node_by_script(child, script_path)
|
||||
if result:
|
||||
return result
|
||||
|
||||
return null
|
||||
|
||||
func _update_ui_from_scene():
|
||||
|
||||
func _update_ui_from_scene() -> void:
|
||||
if not match3_scene:
|
||||
return
|
||||
|
||||
# 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):
|
||||
if (
|
||||
match3_scene.has_signal("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)
|
||||
|
||||
@@ -112,14 +126,18 @@ func _update_ui_from_scene():
|
||||
|
||||
# Update grid size display
|
||||
if "GRID_SIZE" in match3_scene:
|
||||
var grid_size = match3_scene.GRID_SIZE
|
||||
var grid_size: Vector2i = 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_grid_state_loaded(grid_size: Vector2i, tile_types: int):
|
||||
DebugManager.log_debug("Grid state loaded signal received: size=%s, types=%d" % [grid_size, tile_types], log_category)
|
||||
|
||||
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],
|
||||
log_category
|
||||
)
|
||||
|
||||
# Update the UI with the actual loaded values
|
||||
gem_types_spinbox.value = tile_types
|
||||
@@ -130,16 +148,19 @@ func _on_grid_state_loaded(grid_size: Vector2i, tile_types: int):
|
||||
grid_width_label.text = "Width: " + str(grid_size.x)
|
||||
grid_height_label.text = "Height: " + str(grid_size.y)
|
||||
|
||||
func _stop_search_timer():
|
||||
|
||||
func _stop_search_timer() -> void:
|
||||
if search_timer and search_timer.timeout.is_connected(_find_target_scene):
|
||||
search_timer.stop()
|
||||
|
||||
func _start_search_timer():
|
||||
|
||||
func _start_search_timer() -> void:
|
||||
if search_timer and not search_timer.timeout.is_connected(_find_target_scene):
|
||||
search_timer.timeout.connect(_find_target_scene)
|
||||
search_timer.start()
|
||||
|
||||
func _on_debug_toggled(enabled: bool):
|
||||
|
||||
func _on_debug_toggled(enabled: bool) -> void:
|
||||
DebugManager.log_debug("Debug toggled to " + str(enabled), log_category)
|
||||
visible = enabled
|
||||
if enabled:
|
||||
@@ -150,13 +171,17 @@ func _on_debug_toggled(enabled: bool):
|
||||
# Force refresh the values in case they changed while debug was hidden
|
||||
_refresh_current_values()
|
||||
|
||||
func _refresh_current_values():
|
||||
|
||||
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)
|
||||
DebugManager.log_debug(
|
||||
"Refreshing debug menu values from current scene state", log_category
|
||||
)
|
||||
_update_ui_from_scene()
|
||||
|
||||
func _on_regenerate_pressed():
|
||||
|
||||
func _on_regenerate_pressed() -> void:
|
||||
if not match3_scene:
|
||||
_find_target_scene()
|
||||
|
||||
@@ -170,9 +195,10 @@ func _on_regenerate_pressed():
|
||||
else:
|
||||
DebugManager.log_error("Target scene does not have regenerate_grid method", log_category)
|
||||
|
||||
func _on_gem_types_changed(value: float):
|
||||
|
||||
func _on_gem_types_changed(value: float) -> void:
|
||||
# Rate limiting for scene searches
|
||||
var current_time = Time.get_ticks_msec() / 1000.0
|
||||
var current_time: float = Time.get_ticks_msec() / 1000.0
|
||||
if current_time - last_scene_search_time < SCENE_SEARCH_COOLDOWN:
|
||||
return
|
||||
|
||||
@@ -184,10 +210,16 @@ func _on_gem_types_changed(value: float):
|
||||
DebugManager.log_error("Could not find target scene for gem types change", log_category)
|
||||
return
|
||||
|
||||
var new_value = int(value)
|
||||
var new_value: int = int(value)
|
||||
# Enhanced input validation with safety constants
|
||||
if new_value < MIN_TILE_TYPES or new_value > MAX_TILE_TYPES:
|
||||
DebugManager.log_error("Invalid gem types value: %d (range: %d-%d)" % [new_value, MIN_TILE_TYPES, MAX_TILE_TYPES], log_category)
|
||||
DebugManager.log_error(
|
||||
(
|
||||
"Invalid gem types value: %d (range: %d-%d)"
|
||||
% [new_value, MIN_TILE_TYPES, MAX_TILE_TYPES]
|
||||
),
|
||||
log_category
|
||||
)
|
||||
# Reset to valid value
|
||||
gem_types_spinbox.value = clamp(new_value, MIN_TILE_TYPES, MAX_TILE_TYPES)
|
||||
return
|
||||
@@ -203,9 +235,10 @@ func _on_gem_types_changed(value: float):
|
||||
match3_scene.TILE_TYPES = new_value
|
||||
gem_types_label.text = "Gem Types: " + str(new_value)
|
||||
|
||||
func _on_grid_width_changed(value: float):
|
||||
|
||||
func _on_grid_width_changed(value: float) -> void:
|
||||
# Rate limiting for scene searches
|
||||
var current_time = Time.get_ticks_msec() / 1000.0
|
||||
var current_time: float = Time.get_ticks_msec() / 1000.0
|
||||
if current_time - last_scene_search_time < SCENE_SEARCH_COOLDOWN:
|
||||
return
|
||||
|
||||
@@ -217,10 +250,16 @@ func _on_grid_width_changed(value: float):
|
||||
DebugManager.log_error("Could not find target scene for grid width change", log_category)
|
||||
return
|
||||
|
||||
var new_width = int(value)
|
||||
var new_width: int = int(value)
|
||||
# Enhanced input validation with safety constants
|
||||
if new_width < MIN_GRID_SIZE or new_width > MAX_GRID_SIZE:
|
||||
DebugManager.log_error("Invalid grid width value: %d (range: %d-%d)" % [new_width, MIN_GRID_SIZE, MAX_GRID_SIZE], log_category)
|
||||
DebugManager.log_error(
|
||||
(
|
||||
"Invalid grid width value: %d (range: %d-%d)"
|
||||
% [new_width, MIN_GRID_SIZE, MAX_GRID_SIZE]
|
||||
),
|
||||
log_category
|
||||
)
|
||||
# Reset to valid value
|
||||
grid_width_spinbox.value = clamp(new_width, MIN_GRID_SIZE, MAX_GRID_SIZE)
|
||||
return
|
||||
@@ -228,17 +267,20 @@ func _on_grid_width_changed(value: float):
|
||||
grid_width_label.text = "Width: " + str(new_width)
|
||||
|
||||
# Get current height
|
||||
var current_height = int(grid_height_spinbox.value)
|
||||
var current_height: int = 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), log_category)
|
||||
DebugManager.log_debug(
|
||||
"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)
|
||||
|
||||
func _on_grid_height_changed(value: float):
|
||||
|
||||
func _on_grid_height_changed(value: float) -> void:
|
||||
# Rate limiting for scene searches
|
||||
var current_time = Time.get_ticks_msec() / 1000.0
|
||||
var current_time: float = Time.get_ticks_msec() / 1000.0
|
||||
if current_time - last_scene_search_time < SCENE_SEARCH_COOLDOWN:
|
||||
return
|
||||
|
||||
@@ -250,10 +292,16 @@ func _on_grid_height_changed(value: float):
|
||||
DebugManager.log_error("Could not find target scene for grid height change", log_category)
|
||||
return
|
||||
|
||||
var new_height = int(value)
|
||||
var new_height: int = int(value)
|
||||
# Enhanced input validation with safety constants
|
||||
if new_height < MIN_GRID_SIZE or new_height > MAX_GRID_SIZE:
|
||||
DebugManager.log_error("Invalid grid height value: %d (range: %d-%d)" % [new_height, MIN_GRID_SIZE, MAX_GRID_SIZE], log_category)
|
||||
DebugManager.log_error(
|
||||
(
|
||||
"Invalid grid height value: %d (range: %d-%d)"
|
||||
% [new_height, MIN_GRID_SIZE, MAX_GRID_SIZE]
|
||||
),
|
||||
log_category
|
||||
)
|
||||
# Reset to valid value
|
||||
grid_height_spinbox.value = clamp(new_height, MIN_GRID_SIZE, MAX_GRID_SIZE)
|
||||
return
|
||||
@@ -261,10 +309,12 @@ func _on_grid_height_changed(value: float):
|
||||
grid_height_label.text = "Height: " + str(new_height)
|
||||
|
||||
# Get current width
|
||||
var current_width = int(grid_width_spinbox.value)
|
||||
var current_width: int = 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), log_category)
|
||||
DebugManager.log_debug(
|
||||
"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)
|
||||
|
||||
Reference in New Issue
Block a user