Wrote some connections between the shock/alarm buttons and the terminal

This commit is contained in:
2026-03-25 08:28:49 -07:00
parent 13cbcb9914
commit a04d7699ae
3 changed files with 18 additions and 7 deletions

View File

@@ -8,12 +8,12 @@ var commands_directory = DirAccess.open("res://Scripts/Gameplay/CommandLine/Comm
var commands: Dictionary = {}
func _ready():
load_commands()
_load_commands()
input_line.text_submitted.connect(self._on_command_entered)
# To make a new command, write it in ./Commands with a main() function for entry.
# This function will automatically find and register all command files
func load_commands():
func _load_commands():
if not commands_directory:
push_error("Failed to open commands folder!")
return
@@ -37,7 +37,6 @@ func _on_command_entered(new_text: String) -> void:
input_line.clear()
_print("> " + new_text)
# Store command and ensure its not empty
var parts = new_text.strip_edges().split(" ")
if parts.size() == 0:
return
@@ -47,12 +46,17 @@ func _on_command_entered(new_text: String) -> void:
var args = parts.slice(1, parts.size())
if commands.has(cmd):
var cmd_script = commands[cmd].new() # Instantiate the script
var cmd_script = commands[cmd].new()
if cmd_script.has_method("main"):
# Run script
cmd_script.main(args, self)
else:
_print("DEV ERROR !\nCommand '%s' has no main() function!" % cmd)
else:
_print("Unknown command: %s" % cmd)
input_line.text = "" # Clear input
input_line.clear()
func _button_shock():
_print("Shocked")
func _button_alarm():
_print("Alarm Triggered")