From 590408e54cbdaf79d0d32c3457b98a8b2c497f97 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Tue, 1 Sep 2020 19:59:07 +0200 Subject: [PATCH] Implement very stupid history --- levels/blobs/goal | 4 ++-- main.gd | 3 +++ terminal.gd | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/levels/blobs/goal b/levels/blobs/goal index 5533642..d3c66f7 100644 --- a/levels/blobs/goal +++ b/levels/blobs/goal @@ -1,6 +1,6 @@ echo "Hi" > file1 -echo "Ho" > file1 -echo "Hu" > file1 +echo "Ho" > file2 +echo "Hu" > file3 git hash-object -w file1 git hash-object -w file2 git hash-object -w file3 diff --git a/main.gd b/main.gd index 1330fdf..2c2437c 100644 --- a/main.gd +++ b/main.gd @@ -18,6 +18,7 @@ func _ready(): # Load first level. load_level(0) + $Terminal/Input.grab_focus() func list_levels(): var levels = [] @@ -96,6 +97,7 @@ func read_commit_message(): $CommitMessage.show() $Terminal/Input.editable = false $CommitMessage.text = game.read_file($ActiveRepository.path+"/.git/COMMIT_EDITMSG") + $CommitMessage.grab_focus() func save_commit_message(): game.write_file($ActiveRepository.path+"/.git/COMMIT_EDITMSG", $CommitMessage.text) @@ -104,3 +106,4 @@ func save_commit_message(): $Terminal/Input.editable = true $CommitMessage.text = "" $CommitMessage.hide() + $Terminal/Input.grab_focus() diff --git a/terminal.gd b/terminal.gd index a5ea6b7..c864b0d 100644 --- a/terminal.gd +++ b/terminal.gd @@ -2,7 +2,24 @@ extends Node2D var thread +var history = [] +var history_position = 0 + +func _input(event): + if history.size() > 0: + if event.is_action_pressed("ui_up"): + history_position -= 1 + history_position %= history.size() + $Input.text = history[history_position] + if event.is_action_pressed("ui_down"): + history_position += 1 + history_position %= history.size() + $Input.text = history[history_position] + func send_command(command): + history.push_back(command) + history_position += 1 + thread = Thread.new() thread.start(self, "run_command_in_a_thread", command)