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

Partial refactor of debug menu and Main script

This commit is contained in:
John 2021-10-29 17:39:46 -05:00
parent 909773a65b
commit 05ddde9788
2 changed files with 24 additions and 22 deletions

View File

@ -141,18 +141,21 @@ func _on_LineEdit_text_entered(line):
debug_print_line("> ") debug_print_line("> ")
# History_related helper functions: # 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): func history_append(text):
history.resize(history_pos + 2) history.resize(history_pos + 2)
history[history_pos] = text history[history_pos] = text
history_pos += 1 history_pos += 1
func history_move(direction): # history_move: Traverse the history and update the user input box
if history_pos + direction < 0: # params: rel_pos: amount to move, relative to the current history_pos
pass # returns: void
elif history_pos + direction >= history.size(): func history_move(rel_pos):
pass var new_pos = history_pos + rel_pos
else: if new_pos >= 0 and new_pos < history.size():
history_pos += direction; history_pos = new_pos;
if history[history_pos]: if history[history_pos]:
emit_signal("history_event", history[history_pos]) emit_signal("history_event", history[history_pos])
else: else:
@ -205,6 +208,8 @@ func get_canonical(alias):
return null return null
# get_usage: Construct the usage string for a command # 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): func get_usage(alias):
return "Usage: " + alias + helptext[parse(alias)][0] + "\n" return "Usage: " + alias + helptext[parse(alias)][0] + "\n"
@ -335,6 +340,7 @@ func command_call(command):
else: else:
debug_print_line(get_usage(command[0])) debug_print_line(get_usage(command[0]))
# history: print the command history
func command_history(_command): func command_history(_command):
var lnum = 0 var lnum = 0
for line in history: for line in history:
@ -343,6 +349,7 @@ func command_history(_command):
lnum += 1 lnum += 1
debug_print_line("history_pos = " + String(history_pos) + "\n") debug_print_line("history_pos = " + String(history_pos) + "\n")
# perf: Print the value of a Godot Engine performance counter
func command_perf(command): func command_perf(command):
if command.size() > 1: if command.size() > 1:
var stat = perf(command[1]) var stat = perf(command[1])

View File

@ -1,10 +1,10 @@
extends Control extends Control
# Scenes # Scenes
var title_screen onready var title_screen = preload("res://scenes/Title Screen.tscn")
var gameplay onready var gameplay = preload("res://scenes/Gameplay.tscn" )
var options onready var options = preload("res://scenes/Options.tscn" )
var debug_menu onready var debug_menu = preload("res://scenes/Debug Menu.tscn" )
var debug_enabled = true var debug_enabled = true
var start_fullscreen = false var start_fullscreen = false
@ -13,17 +13,12 @@ var start_fullscreen = false
func _ready(): func _ready():
# Connect to signals # Connect to signals
var _errno = 0; var _errno = 0;
_errno += MessageBus.connect("start_tcsn", self, "_on_scene_start_by_name") _errno += MessageBus.connect("start_tcsn" , self, "_on_scene_start_by_name")
_errno += MessageBus.connect("change_scene", self, "_on_scene_start") _errno += MessageBus.connect("change_scene" , self, "_on_scene_start" )
_errno += MessageBus.connect("kill_scene", self, "_on_scene_kill") _errno += MessageBus.connect("kill_scene" , self, "_on_scene_kill" )
_errno += MessageBus.connect("list_scenes", self, "_on_scene_list") _errno += MessageBus.connect("list_scenes" , self, "_on_scene_list" )
_errno += MessageBus.connect("quit", self, "_on_quit_request") _errno += MessageBus.connect("quit" , self, "_on_quit_request" )
_errno += MessageBus.connect("return_to_title", self, "_on_title_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")
# go fullscreen # go fullscreen
if start_fullscreen: if start_fullscreen:
OS.window_fullscreen = true OS.window_fullscreen = true