From d8d48c245e4ebf3d487c887c7eb15df34a3b3016 Mon Sep 17 00:00:00 2001 From: blinry Date: Tue, 22 Dec 2020 16:05:35 +0100 Subject: [PATCH] Take hints on port 1235, hint script in user's PATH --- scenes/game.gd | 9 ++++++--- scenes/main.gd | 15 ++++++++++++++- scenes/shell.gd | 1 + scripts/fake-editor | 2 +- scripts/hint | 15 +++++++++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100755 scripts/hint diff --git a/scenes/game.gd b/scenes/game.gd index 358f0f2..1d5f865 100644 --- a/scenes/game.gd +++ b/scenes/game.gd @@ -15,11 +15,14 @@ func _ready(): create_file_in_game_env(".gitconfig", helpers.read_file("res://scripts/gitconfig")) - create_file_in_game_env("fake-editor", helpers.read_file("res://scripts/fake-editor")) - fake_editor = tmp_prefix + "fake-editor" - global_shell.run("chmod u+x '%s'" % fake_editor) + copy_script_to_game_env("fake-editor") + copy_script_to_game_env("hint") load_state() + +func copy_script_to_game_env(name): + create_file_in_game_env(name, helpers.read_file("res://scripts/%s" % name)) + global_shell.run("chmod u+x '%s'" % (tmp_prefix + name)) func _initial_state(): return {"history": []} diff --git a/scenes/main.gd b/scenes/main.gd index 566af3e..9bbc6e1 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -20,7 +20,13 @@ onready var cards = $Rows/Controls/Cards onready var file_browser = $Rows/Columns/RightSide/FileBrowser onready var index = $Rows/Columns/RightSide/Index +var _hint_server +var _hint_client_connection + func _ready(): + _hint_server = TCP_Server.new() + _hint_server.listen(1235) + var args = helpers.parse_args() if args.has("sandbox"): @@ -45,6 +51,14 @@ func _ready(): # Load first chapter. load_chapter(current_chapter) input.grab_focus() + +func _process(delta): + if _hint_server.is_connection_available(): + _hint_client_connection = _hint_server.take_connection() + var length = _hint_client_connection.get_u32() + var message = _hint_client_connection.get_string(length) + game.notify(message) + func load_chapter(id): current_chapter = id @@ -97,7 +111,6 @@ func load_level(level_id): terminal.find_node("TextEditor").close() update_repos() - game.notify("Level loaded!") # Unmute the audio after a while, so that player can hear pop sounds for # nodes they create. diff --git a/scenes/shell.gd b/scenes/shell.gd index 40cfda8..0788214 100644 --- a/scenes/shell.gd +++ b/scenes/shell.gd @@ -48,6 +48,7 @@ func run_async_thread(shell_command): var env = {} env["HOME"] = game.tmp_prefix + env["PATH"] = game.tmp_prefix+":/usr/bin:/bin" var hacky_command = "" for variable in env: diff --git a/scripts/fake-editor b/scripts/fake-editor index 9e5a929..690694d 100755 --- a/scripts/fake-editor +++ b/scripts/fake-editor @@ -10,7 +10,7 @@ $socket = IO::Socket::INET->new(PeerAddr => "127.0.0.1", my $absolute_path = File::Spec->rel2abs($ARGV[0]); -# Send the length of the first argument as a byte. +# Send the length of the first argument as four bytes. $socket->send(pack("L", length($absolute_path))); # Send the first argument as a string. $socket->send($absolute_path); diff --git a/scripts/hint b/scripts/hint new file mode 100755 index 0000000..8b24e7a --- /dev/null +++ b/scripts/hint @@ -0,0 +1,15 @@ +#!/usr/bin/env perl + +use IO::Socket; + +$socket = IO::Socket::INET->new(PeerAddr => "127.0.0.1", + PeerPort => 1235, + Proto => "tcp", + Type => SOCK_STREAM); + +my $message = join " ", @ARGV; + +# Send the length of the first argument as four bytes. +$socket->send(pack("L", length($message))); +# Send the first argument as a string. +$socket->send($message);