1
0
mirror of https://github.com/JohnBreaux/Boat-Battle.git synced 2024-11-15 05:25:57 +00:00
Boat-Battle/godot_ship/script/debug/debug_menu.gd

169 lines
5.4 KiB
GDScript3
Raw Normal View History

extends Control
# Declare member variables here.
var debug_output
var debug_line = 0
var debug_canvas
var debug_transform
var debug_active = false
var menu_position = 0.0
2021-10-20 06:05:39 +00:00
var menu_velocity = 4
# positions when the menu is hidden/active
var menu_hidden = Transform2D(Vector2(1,0), Vector2(0,1), Vector2(0,-170))
var menu_active = Transform2D(Vector2(1,0), Vector2(0,1), Vector2(0, 0))
# signals
2021-10-20 11:00:09 +00:00
signal clear_in # clears the debug input
signal clear_out # clears the debug output
signal print_text(text) # Sends text for printing to the Out buffer
# Called when the node enters the scene tree for the first time.
func _ready():
debug_canvas = get_node("debug_canvas")
debug_transform = debug_canvas.get_transform()
debug_output = get_node("debug_canvas/VBoxContainer/TextEdit")
2021-10-20 11:00:09 +00:00
command_help([""])
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if (debug_active && menu_position < 1):
2021-10-20 11:00:09 +00:00
# Move the menu down
menu_position += menu_velocity * delta;
2021-10-20 11:00:09 +00:00
$debug_canvas/VBoxContainer/LineEdit.grab_focus()
elif (!debug_active && menu_position > 0):
2021-10-20 11:00:09 +00:00
# Move the menu up
menu_position -= menu_velocity * delta;
2021-10-20 11:00:09 +00:00
# Clear the input box
emit_signal("clear_in")
else:
menu_position = round(menu_position)
debug_canvas.set_transform(menu_hidden.interpolate_with(menu_active, menu_position))
func _input(event):
if event.is_action_pressed("ui_debug"):
# open debug menu
debug_active = !debug_active;
2021-10-20 11:00:09 +00:00
# Hand the keyboard focus to the next valid focus
if (!debug_active): find_next_valid_focus().grab_focus()
2021-10-20 05:40:31 +00:00
func _on_LineEdit_text_entered(line):
2021-10-20 10:13:24 +00:00
emit_signal("clear_in")
debug_print_line("")
var command = line.split(' ', true, 1)
2021-10-20 10:13:24 +00:00
match command[0]:
"start", "s":
command_start(command)
"stop", "kill", "k":
command_stop(command)
"list", "ls", "l":
command_list(command)
"restart", "killall":
command_restart(command)
"print", "p":
command_print(command)
"raw_emit", "emit", "r", "e": # Send a signal over the MessageBus
command_emit(command)
"clear","cls": # Clear the output
command_clear(command)
"help", "h":
command_help(command)
_:
debug_print_line("Command not recognized.\n")
2021-10-20 05:40:31 +00:00
func debug_print_line(string):
emit_signal("print_text", string.c_unescape())
2021-10-20 10:13:24 +00:00
# Commands
# start: Loads scene from res://scenes/*.tscn by filename, and starts it
func command_start (command):
if command.size() > 1:
MessageBus.emit_signal("start_tcsn", command[1])
debug_print_line("start '" + command[1] + "'\n")
else:
debug_print_line("Usage: start scene")
# stop: Stops scene by name of root node.
func command_stop (command):
2021-10-20 11:00:09 +00:00
if command.size() > 1:
if command[1] != "Debug":
debug_print_line("kill '" + command[1] + "'\n")
MessageBus.emit_signal("kill_scene", command[1])
else:
debug_print_line("YOU DIDN'T SAY THE MAGIC WORD!\n")
2021-10-20 10:13:24 +00:00
else:
debug_print_line("Usage: kill scene")
# list: Lists names of active scenes (children of Root)
2021-10-20 11:00:09 +00:00
func command_list (_command):
2021-10-20 10:13:24 +00:00
debug_print_line("list: ")
MessageBus.emit_signal("list_scenes")
# restart: Kills the current tree and replants Root
2021-10-20 11:00:09 +00:00
func command_restart (_command):
2021-10-20 10:13:24 +00:00
MessageBus.emit_signal("return_to_title")
# print: prints a message to the in-game debug console
func command_print(command):
if command.size() > 1:
debug_print_line(command[1] + "\n")
# emit: emits a message onto the MessageBus (!Extremely Danger!)
func command_emit (command):
var mbus_signal = command[1].split(' ', true, 1)
match mbus_signal.size():
2:
debug_print_line("Message: " + String(mbus_signal) + "\n")
MessageBus.emit_signal(mbus_signal[0], mbus_signal[1])
1:
debug_print_line("Message: " + String(mbus_signal) + "\n")
MessageBus.emit_signal(mbus_signal[0])
0: debug_print_line( "Usage: raw_emit signal [value]\n")
# clear: clears the debug output
2021-10-20 11:00:09 +00:00
func command_clear (_command):
2021-10-20 10:13:24 +00:00
emit_signal("clear_out");
2021-10-20 11:00:09 +00:00
func command_tree (_command):
pass
2021-10-20 10:13:24 +00:00
# help: Prints help dialogue
func command_help (command):
if (command.size() == 1):
2021-10-20 11:00:09 +00:00
debug_print_line("Ship's Commander V 0.1\n")
2021-10-20 10:13:24 +00:00
debug_print_line("Valid commands:\nstart, stop, list, restart, print, emit, clear, help\n")
else:
debug_print_line(command[1])
match command[1]:
"start", "s":
debug_print_line(" filename\nAliases: 'start', 's'\n")
debug_print_line("Loads and runs the scene filename.tscn\n")
"stop", "kill", "k":
debug_print_line(" scene\nAliases: 'stop', 'kill', 'k'\n")
debug_print_line("Kills an active scene whose name matches node.\n")
"list", "ls", "l":
debug_print_line("\nAliases: 'list', 'ls', 'l'\n")
debug_print_line("Lists the currently active scenes\n")
"restart", "killall":
debug_print_line("\nAliases: 'restart', 'killall'\n")
debug_print_line("Kills the current scene tree and plants a new Root.\n")
"print", "p":
debug_print_line(" string\nAliases: 'print', 'p'\n")
debug_print_line("Prints a string to the in-game debug console\n")
"raw_emit", "emit", "r", "e":
debug_print_line(" signal [message]\nAliases: 'raw_emit', 'emit', 'r', 'e'\n")
debug_print_line("Puts a message on the MessageBus without validation.\n")
"clear","cls":
debug_print_line("\nAliases: 'clear', 'cls'\n")
debug_print_line("Clears the debug output.\n")
"help", "h":
debug_print_line(" [command]\nAliases: 'help', 'h'\n")
debug_print_line("Prints information about a command.\n")
_:
debug_print_line(command[1] + "\nIsn't a valid command\n")
2021-10-20 11:00:09 +00:00
debug_print_line("\n")