From 05ddde9788ca5512dc98302df73958ec888cd4ae Mon Sep 17 00:00:00 2001 From: John Breaux Date: Fri, 29 Oct 2021 17:39:46 -0500 Subject: [PATCH] Partial refactor of debug menu and Main script --- godot_ship/script/debug/debug_menu.gd | 21 ++++++++++++++------- godot_ship/script/game/Main.gd | 25 ++++++++++--------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/godot_ship/script/debug/debug_menu.gd b/godot_ship/script/debug/debug_menu.gd index 03eeb74..6ef4b42 100644 --- a/godot_ship/script/debug/debug_menu.gd +++ b/godot_ship/script/debug/debug_menu.gd @@ -141,18 +141,21 @@ func _on_LineEdit_text_entered(line): debug_print_line("> ") # History_related helper functions: +# history_append: add a line of text to the history +# params: text: line of text (unparsed command) to add to history +# returns: void func history_append(text): history.resize(history_pos + 2) history[history_pos] = text history_pos += 1 -func history_move(direction): - if history_pos + direction < 0: - pass - elif history_pos + direction >= history.size(): - pass - else: - history_pos += direction; +# history_move: Traverse the history and update the user input box +# params: rel_pos: amount to move, relative to the current history_pos +# returns: void +func history_move(rel_pos): + var new_pos = history_pos + rel_pos + if new_pos >= 0 and new_pos < history.size(): + history_pos = new_pos; if history[history_pos]: emit_signal("history_event", history[history_pos]) else: @@ -205,6 +208,8 @@ func get_canonical(alias): return null # get_usage: Construct the usage string for a command +# params: alias: alias of a command +# returns: usage string for the command, formatted for printing func get_usage(alias): return "Usage: " + alias + helptext[parse(alias)][0] + "\n" @@ -335,6 +340,7 @@ func command_call(command): else: debug_print_line(get_usage(command[0])) +# history: print the command history func command_history(_command): var lnum = 0 for line in history: @@ -343,6 +349,7 @@ func command_history(_command): lnum += 1 debug_print_line("history_pos = " + String(history_pos) + "\n") +# perf: Print the value of a Godot Engine performance counter func command_perf(command): if command.size() > 1: var stat = perf(command[1]) diff --git a/godot_ship/script/game/Main.gd b/godot_ship/script/game/Main.gd index 84e5b39..f2c99d9 100644 --- a/godot_ship/script/game/Main.gd +++ b/godot_ship/script/game/Main.gd @@ -1,10 +1,10 @@ extends Control # Scenes -var title_screen -var gameplay -var options -var debug_menu +onready var title_screen = preload("res://scenes/Title Screen.tscn") +onready var gameplay = preload("res://scenes/Gameplay.tscn" ) +onready var options = preload("res://scenes/Options.tscn" ) +onready var debug_menu = preload("res://scenes/Debug Menu.tscn" ) var debug_enabled = true var start_fullscreen = false @@ -13,17 +13,12 @@ var start_fullscreen = false func _ready(): # Connect to signals var _errno = 0; - _errno += MessageBus.connect("start_tcsn", self, "_on_scene_start_by_name") - _errno += MessageBus.connect("change_scene", self, "_on_scene_start") - _errno += MessageBus.connect("kill_scene", self, "_on_scene_kill") - _errno += MessageBus.connect("list_scenes", self, "_on_scene_list") - _errno += MessageBus.connect("quit", self, "_on_quit_request") - _errno += MessageBus.connect("return_to_title", self, "_on_title_request") - # Create the scenes - title_screen = preload("res://scenes/Title Screen.tscn") - gameplay = preload("res://scenes/Gameplay.tscn") - options = preload("res://scenes/Options.tscn") - debug_menu = preload("res://scenes/Debug Menu.tscn") + _errno += MessageBus.connect("start_tcsn" , self, "_on_scene_start_by_name") + _errno += MessageBus.connect("change_scene" , self, "_on_scene_start" ) + _errno += MessageBus.connect("kill_scene" , self, "_on_scene_kill" ) + _errno += MessageBus.connect("list_scenes" , self, "_on_scene_list" ) + _errno += MessageBus.connect("quit" , self, "_on_quit_request" ) + _errno += MessageBus.connect("return_to_title", self, "_on_title_request" ) # go fullscreen if start_fullscreen: OS.window_fullscreen = true