2021-10-19 05:10:13 +00:00
|
|
|
extends Control
|
|
|
|
|
2021-10-20 03:14:30 +00:00
|
|
|
# Declare member variables here.
|
2021-10-20 07:26:32 +00:00
|
|
|
var debug_output
|
|
|
|
var debug_line = 0
|
|
|
|
|
2021-10-20 03:14:30 +00:00
|
|
|
var debug_canvas
|
|
|
|
var debug_transform
|
2021-10-19 05:10:13 +00:00
|
|
|
|
2021-10-20 03:14:30 +00:00
|
|
|
var debug_active = false
|
|
|
|
var menu_position = 0.0
|
2021-10-20 06:05:39 +00:00
|
|
|
var menu_velocity = 4
|
2021-10-19 05:10:13 +00:00
|
|
|
|
2021-10-21 10:22:42 +00:00
|
|
|
onready var present_working_node = get_node("/root/Main")
|
2021-10-21 08:18:31 +00:00
|
|
|
|
2021-10-20 03:14:30 +00:00
|
|
|
# positions when the menu is hidden/active
|
2021-10-20 07:26:32 +00:00
|
|
|
var menu_hidden = Transform2D(Vector2(1,0), Vector2(0,1), Vector2(0,-170))
|
2021-10-20 03:14:30 +00:00
|
|
|
var menu_active = Transform2D(Vector2(1,0), Vector2(0,1), Vector2(0, 0))
|
2021-10-19 05:10:13 +00:00
|
|
|
|
2021-10-20 08:18:06 +00:00
|
|
|
# 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
|
2021-10-20 08:18:06 +00:00
|
|
|
|
2021-10-19 05:10:13 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2021-10-20 03:14:30 +00:00
|
|
|
debug_canvas = get_node("debug_canvas")
|
|
|
|
debug_transform = debug_canvas.get_transform()
|
2021-10-20 07:26:32 +00:00
|
|
|
debug_output = get_node("debug_canvas/VBoxContainer/TextEdit")
|
2021-10-20 11:00:09 +00:00
|
|
|
command_help([""])
|
2021-10-21 10:22:42 +00:00
|
|
|
debug_print_line("> ")
|
2021-10-19 05:10:13 +00:00
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
2021-10-20 03:14:30 +00:00
|
|
|
func _process(delta):
|
|
|
|
if (debug_active && menu_position < 1):
|
2021-10-20 11:00:09 +00:00
|
|
|
# Move the menu down
|
2021-10-20 03:14:30 +00:00
|
|
|
menu_position += menu_velocity * delta;
|
2021-10-20 11:00:09 +00:00
|
|
|
$debug_canvas/VBoxContainer/LineEdit.grab_focus()
|
2021-10-20 03:14:30 +00:00
|
|
|
elif (!debug_active && menu_position > 0):
|
2021-10-20 11:00:09 +00:00
|
|
|
# Move the menu up
|
2021-10-20 03:14:30 +00:00
|
|
|
menu_position -= menu_velocity * delta;
|
2021-10-20 11:00:09 +00:00
|
|
|
# Clear the input box
|
|
|
|
emit_signal("clear_in")
|
2021-10-20 03:14:30 +00:00
|
|
|
else:
|
|
|
|
menu_position = round(menu_position)
|
|
|
|
|
|
|
|
debug_canvas.set_transform(menu_hidden.interpolate_with(menu_active, menu_position))
|
|
|
|
|
2021-10-20 08:18:06 +00:00
|
|
|
func _input(event):
|
2021-10-20 03:14:30 +00:00
|
|
|
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
|
2021-10-21 06:24:27 +00:00
|
|
|
if (!debug_active) && find_next_valid_focus(): find_next_valid_focus().grab_focus()
|
2021-10-20 05:40:31 +00:00
|
|
|
|
2021-10-20 07:26:32 +00:00
|
|
|
func _on_LineEdit_text_entered(line):
|
2021-10-20 10:13:24 +00:00
|
|
|
emit_signal("clear_in")
|
2021-10-21 10:22:42 +00:00
|
|
|
debug_print_line(line + "\n")
|
2021-10-20 07:26:32 +00:00
|
|
|
var command = line.split(' ', true, 1)
|
2021-10-20 10:13:24 +00:00
|
|
|
match command[0]:
|
2021-10-21 10:22:42 +00:00
|
|
|
"start", "open", "o":
|
|
|
|
command_start(command)
|
2021-10-20 10:13:24 +00:00
|
|
|
"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)
|
2021-10-21 08:18:31 +00:00
|
|
|
"pwd", "pwn":
|
|
|
|
command_pwd(command)
|
|
|
|
"cd", "cn":
|
|
|
|
command_cd(command)
|
2021-10-20 10:13:24 +00:00
|
|
|
_:
|
|
|
|
debug_print_line("Command not recognized.\n")
|
2021-10-21 10:22:42 +00:00
|
|
|
debug_print_line("> ")
|
2021-10-20 05:40:31 +00:00
|
|
|
|
2021-10-20 07:26:32 +00:00
|
|
|
func debug_print_line(string):
|
2021-10-20 08:18:06 +00:00
|
|
|
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:
|
2021-10-21 10:22:42 +00:00
|
|
|
var pack = load("res://scenes/" + command[1] + ".tscn");
|
|
|
|
present_working_node.add_child(pack.instance());
|
2021-10-20 10:13:24 +00:00
|
|
|
debug_print_line("start '" + command[1] + "'\n")
|
|
|
|
else:
|
|
|
|
debug_print_line("Usage: start scene")
|
|
|
|
|
2021-10-21 10:22:42 +00:00
|
|
|
# stop: kills a child of current working node
|
2021-10-20 10:13:24 +00:00
|
|
|
func command_stop (command):
|
2021-10-20 11:00:09 +00:00
|
|
|
if command.size() > 1:
|
2021-10-21 10:22:42 +00:00
|
|
|
var node = present_working_node.find_node(command[1], false, false)
|
|
|
|
if node:
|
|
|
|
if String(node.get_path()).match("*Debug*"):
|
|
|
|
debug_print_line("YOU DIDN'T SAY THE MAGIC WORD!\n")
|
|
|
|
else:
|
|
|
|
node.queue_free()
|
|
|
|
debug_print_line(command[1] + " killed\n")
|
2021-10-20 11:00:09 +00:00
|
|
|
else:
|
2021-10-21 10:22:42 +00:00
|
|
|
debug_print_line(command[0] + ": " + command[1] + " not found.\n")
|
2021-10-20 10:13:24 +00:00
|
|
|
else:
|
2021-10-21 10:22:42 +00:00
|
|
|
debug_print_line("Usage: kill name\n")
|
|
|
|
|
|
|
|
# list: Lists children of node
|
|
|
|
func command_list (command):
|
|
|
|
var node = null
|
|
|
|
if (command.size() > 1):
|
|
|
|
node = complete_path(command[1])
|
|
|
|
if (!node):
|
|
|
|
node = present_working_node
|
|
|
|
var children = node.get_children()
|
2021-10-21 08:18:31 +00:00
|
|
|
var names = []
|
|
|
|
for i in range (children.size()):
|
|
|
|
names.append(children[i].name)
|
|
|
|
debug_print_line(String(names) + "\n")
|
2021-10-20 10:13:24 +00:00
|
|
|
|
|
|
|
# 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")
|
2021-10-21 10:22:42 +00:00
|
|
|
else:
|
|
|
|
debug_print_line("\n")
|
2021-10-20 10:13:24 +00:00
|
|
|
|
2021-10-21 10:22:42 +00:00
|
|
|
# emit: emits a message onto the MessageBus
|
2021-10-20 10:13:24 +00:00
|
|
|
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-21 10:22:42 +00:00
|
|
|
# pwd: print the current working node's path
|
2021-10-21 08:18:31 +00:00
|
|
|
func command_pwd (_command):
|
2021-10-21 10:22:42 +00:00
|
|
|
debug_print_line(String(present_working_node.get_path()) + "\n")
|
|
|
|
# cd: change the current working node
|
2021-10-21 08:18:31 +00:00
|
|
|
func command_cd (command):
|
|
|
|
if command.size() > 1:
|
2021-10-21 10:22:42 +00:00
|
|
|
var node = complete_path(command[1])
|
2021-10-21 08:18:31 +00:00
|
|
|
if node:
|
|
|
|
present_working_node = node
|
|
|
|
else:
|
2021-10-21 10:22:42 +00:00
|
|
|
debug_print_line ('cn: no such node: ' + command[1] + '\n')
|
2021-10-21 08:18:31 +00:00
|
|
|
else:
|
|
|
|
debug_print_line("")
|
2021-10-20 11:00:09 +00:00
|
|
|
pass
|
|
|
|
|
2021-10-20 10:13:24 +00:00
|
|
|
# help: Prints help dialogue
|
|
|
|
func command_help (command):
|
|
|
|
if (command.size() == 1):
|
2021-10-21 10:22:42 +00:00
|
|
|
debug_print_line("Valid commands:\nhelp, start, stop, list, restart, print, emit, clear, pwn, cn\n")
|
2021-10-20 10:13:24 +00:00
|
|
|
else:
|
|
|
|
debug_print_line(command[1])
|
|
|
|
match command[1]:
|
2021-10-21 10:22:42 +00:00
|
|
|
"start", "open", "o":
|
|
|
|
debug_print_line(" filename\nAliases: 'start', 'open', 'o'\n")
|
|
|
|
debug_print_line("Load add the scene filename.tscn as child\n")
|
2021-10-20 10:13:24 +00:00
|
|
|
"stop", "kill", "k":
|
2021-10-21 10:22:42 +00:00
|
|
|
debug_print_line(" name\nAliases: 'stop', 'kill', 'k'\n")
|
|
|
|
debug_print_line("Kill node with matching name\n")
|
2021-10-20 10:13:24 +00:00
|
|
|
"list", "ls", "l":
|
2021-10-21 10:22:42 +00:00
|
|
|
debug_print_line(" [path]\nAliases: 'list', 'ls', 'l'\n")
|
|
|
|
debug_print_line("List node children\n")
|
2021-10-20 10:13:24 +00:00
|
|
|
"restart", "killall":
|
|
|
|
debug_print_line("\nAliases: 'restart', 'killall'\n")
|
2021-10-21 10:22:42 +00:00
|
|
|
debug_print_line("Kill the current scene tree and plant a new Root.\n")
|
2021-10-20 10:13:24 +00:00
|
|
|
"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")
|
2021-10-21 10:22:42 +00:00
|
|
|
"pwd", "pwn":
|
|
|
|
debug_print_line("\nAliases: 'pwn', 'pwd'\n")
|
|
|
|
debug_print_line("Prints the Present Working Node.\n")
|
|
|
|
"cd", "cn":
|
|
|
|
debug_print_line(" path/to/node\nAliases: 'cn', 'cd'\n")
|
|
|
|
debug_print_line("Change the Present Working Node.\n")
|
2021-10-20 10:13:24 +00:00
|
|
|
_:
|
|
|
|
debug_print_line(command[1] + "\nIsn't a valid command\n")
|
2021-10-21 10:22:42 +00:00
|
|
|
|
|
|
|
# Completes a relative or absolute path, and returns the node it refers to
|
|
|
|
func complete_path(path):
|
|
|
|
if path.is_rel_path(): # convert to absolute path
|
|
|
|
path = String(present_working_node.get_path()) + "/" + path
|
|
|
|
var node = get_node(path)
|
|
|
|
if node:
|
|
|
|
return node
|
|
|
|
return null
|