From 078c1612acb1117d40607f87c95d7b30b1c71a49 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Sun, 13 Sep 2020 18:40:44 +0200 Subject: [PATCH] fake-editor sends filename now, so that we can write tag descriptions, for example --- main.gd | 24 ++++++++++++++++-------- main.tscn | 4 +++- scripts/fake-editor | 6 ++++++ text_editor.gd | 3 +++ 4 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 text_editor.gd diff --git a/main.gd b/main.gd index d4e2563..4aa647d 100644 --- a/main.gd +++ b/main.gd @@ -92,7 +92,9 @@ func load_next_level(): func construct_repo(script, path): # Becase in an exported game, all assets are in a .pck file, we need to put # the script somewhere in the filesystem. - var content = game.read_file(script) + var content = "" + if ResourceLoader.exists(script): + content = game.read_file(script) var script_path_outside = game.tmp_prefix+"/git-hydra-script" var script_path = "/tmp/git-hydra-script" game.write_file(script_path_outside, content) @@ -106,19 +108,25 @@ func _process(_delta): if server.is_connection_available(): print("Client connected") client_connection = server.take_connection() - read_commit_message() + var length = client_connection.get_u8() + var filename = client_connection.get_string(length) + var regex = RegEx.new() + regex.compile("(\\.git\\/.*)") + filename = regex.search(filename).get_string() + print(filename) + read_commit_message(filename) -func read_commit_message(): +func read_commit_message(filename): $CommitMessage.show() input.editable = false - var fixme_path = game.tmp_prefix+"/active" - $CommitMessage.text = game.read_file(fixme_path+"/.git/COMMIT_EDITMSG") + var fixme_path = game.tmp_prefix+"/active/" + $CommitMessage.text = game.read_file(fixme_path+filename) + $CommitMessage.path = filename $CommitMessage.grab_focus() func save_commit_message(): - var fixme_path = game.tmp_prefix+"/active" - game.write_file(fixme_path+"/.git/COMMIT_EDITMSG", $CommitMessage.text) - print("disconnect") + var fixme_path = game.tmp_prefix+"/active/" + game.write_file(fixme_path+$CommitMessage.path, $CommitMessage.text) client_connection.disconnect_from_host() input.editable = true $CommitMessage.text = "" diff --git a/main.tscn b/main.tscn index 2ccc6f8..c1a2b64 100644 --- a/main.tscn +++ b/main.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://terminal.tscn" type="PackedScene" id=1] [ext_resource path="res://main.gd" type="Script" id=2] [ext_resource path="res://repository.tscn" type="PackedScene" id=3] [ext_resource path="res://styles/alert_button.tres" type="StyleBox" id=4] [ext_resource path="res://fonts/default.tres" type="DynamicFont" id=5] +[ext_resource path="res://text_editor.gd" type="Script" id=6] [sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0.847059, 0.0666667, 0.0666667, 1 ) @@ -42,6 +43,7 @@ margin_bottom = 1068.0 custom_fonts/font = ExtResource( 5 ) custom_colors/background_color = Color( 0, 0, 0, 1 ) syntax_highlighting = true +script = ExtResource( 6 ) __meta__ = { "_edit_use_anchors_": false } diff --git a/scripts/fake-editor b/scripts/fake-editor index f270d81..208e82a 100755 --- a/scripts/fake-editor +++ b/scripts/fake-editor @@ -7,5 +7,11 @@ $socket = IO::Socket::INET->new(PeerAddr => "127.0.0.1", Proto => "tcp", Type => SOCK_STREAM); +# Send the length of the first argument as a byte. +$socket->send(chr(length($ARGV[0]))); +# Send the first argument as a string. +$socket->send($ARGV[0]); + +# This call is intended to block, we're waiting for Godot to close the connection. my $reply; $socket->read($reply, 1000); diff --git a/text_editor.gd b/text_editor.gd new file mode 100644 index 0000000..db6fa16 --- /dev/null +++ b/text_editor.gd @@ -0,0 +1,3 @@ +extends TextEdit + +var path