Reorganized files, started splitting up unit

This commit is contained in:
gamer147
2026-04-08 18:28:52 -04:00
parent 24134cfa33
commit c192d48bc4
70 changed files with 528 additions and 56 deletions

View File

@@ -0,0 +1,7 @@
@abstract class_name ConsoleCommand extends RefCounted
@abstract func get_command_name() -> String
@abstract func get_help_text() -> String
@abstract func run(args: Array, context: Dictionary) -> String

View File

@@ -0,0 +1 @@
uid://b2kk8l3kumxpr

View File

@@ -0,0 +1,15 @@
class_name HelpCommand extends ConsoleCommand
func get_command_name() -> String:
return "help"
func get_help_text() -> String:
return "Lists all available commands"
func run(_args: Array, context: Dictionary) -> String:
var commands: Array = context["commands"]
var lines: PackedStringArray = []
for command: ConsoleCommand in commands:
lines.append("%s - %s" % [command.get_command_name(), command.get_help_text()])
lines.append("Any other input is evaluated as a GDScript expression.")
return "\n".join(lines)

View File

@@ -0,0 +1 @@
uid://bvat5xgudptct

View File

@@ -0,0 +1,14 @@
class_name ListScenesCommand extends ConsoleCommand
func get_command_name() -> String:
return "list_scenes"
func get_help_text() -> String:
return "Lists available scenes for swapping"
func run(_args: Array, context: Dictionary) -> String:
var registry: Array = context["scene_registry"]
var lines: PackedStringArray = []
for entry: Dictionary in registry:
lines.append(entry["name"])
return "\n".join(lines)

View File

@@ -0,0 +1 @@
uid://b51b3np7lxd3v

View File

@@ -0,0 +1,21 @@
class_name SwapCommand extends ConsoleCommand
func get_command_name() -> String:
return "swap"
func get_help_text() -> String:
return "swap <name> - Swap to a scene by name (use list_scenes to see options)"
func run(args: Array, context: Dictionary) -> String:
if args.size() == 0:
return "Usage: swap <scene name>"
var search_name := " ".join(args).to_lower()
var registry: Array = context["scene_registry"]
for entry: Dictionary in registry:
if entry["name"].to_lower() == search_name:
var debug_menu: DebugMenu = context["debug_menu"]
debug_menu.swap_scene(entry)
return ""
return "Scene not found: %s" % search_name

View File

@@ -0,0 +1 @@
uid://b56j4uyjiaku1

104
scripts/debug/debug_menu.gd Normal file
View File

@@ -0,0 +1,104 @@
class_name DebugMenu extends CanvasLayer
signal close_requested
var active_scene_container: Node
var scene_registry: Array = [
{ "name": "Battle Test", "path": "res://scenes/views/battle_view.tscn" },
{ "name": "Main Menu", "path": "res://scenes/views/main_menu_view.tscn" },
{ "name": "Dialogue Test", "path": "res://scenes/dialogue_scene.tscn" },
]
var commands: Array[ConsoleCommand] = []
@onready var panel: PanelContainer = %Panel
@onready var scene_list: VBoxContainer = %SceneList
@onready var command_input: LineEdit = %CommandInput
@onready var result_label: Label = %ResultLabel
func _ready() -> void:
commands = [
HelpCommand.new(),
ListScenesCommand.new(),
SwapCommand.new(),
]
_build_scene_buttons()
command_input.text_submitted.connect(_on_command_submitted)
result_label.text = ""
func _build_scene_buttons() -> void:
for child in scene_list.get_children():
child.queue_free()
for entry: Dictionary in scene_registry:
var button := Button.new()
button.text = entry["name"]
button.pressed.connect(swap_scene.bind(entry))
scene_list.add_child(button)
func swap_scene(entry: Dictionary) -> void:
for child in active_scene_container.get_children():
active_scene_container.remove_child(child)
child.queue_free()
var scene: PackedScene = load(entry["path"])
var instance := scene.instantiate()
active_scene_container.add_child(instance)
if entry.has("setup"):
_apply_setup(entry["setup"], instance)
close_requested.emit()
func _apply_setup(setup_key: String, _scene_instance: Node) -> void:
match setup_key:
_:
push_warning("Unknown setup key: %s" % setup_key)
func _on_command_submitted(text: String) -> void:
command_input.text = ""
if text.strip_edges().is_empty():
return
var result := _execute_command(text.strip_edges())
_show_result(result)
func _execute_command(input: String) -> String:
var parts := input.split(" ", false)
var command_name := parts[0]
var args: Array = []
if parts.size() > 1:
args = Array(parts.slice(1))
var context := {
"commands": commands,
"scene_registry": scene_registry,
"debug_menu": self,
"active_scene_container": active_scene_container,
}
for command: ConsoleCommand in commands:
if command.get_command_name() == command_name:
return command.run(args, context)
return _eval_expression(input)
func _eval_expression(input: String) -> String:
var expression := Expression.new()
var error := expression.parse(input)
if error != OK:
return "Parse error: %s" % expression.get_error_text()
var active_scene: Node = null
if active_scene_container.get_child_count() > 0:
active_scene = active_scene_container.get_child(0)
var result = expression.execute([], active_scene)
if expression.has_execute_failed():
return "Error: %s" % expression.get_error_text()
return str(result)
func _show_result(text: String) -> void:
result_label.text = text
# if _result_tween and _result_tween.is_valid():
# _result_tween.kill()
# _result_tween = create_tween()
# _result_tween.tween_interval(2.0)
# _result_tween.tween_callback(func(): result_label.text = "")

View File

@@ -0,0 +1 @@
uid://c64yr8xvkb5cw