From 1b5cbe9cb082049840480c47770f3519ae58e46d Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Tue, 1 Sep 2020 18:26:43 +0200 Subject: [PATCH] Set up goal and active level from template repos --- game.gd | 6 ++++++ main.gd | 24 ++++++++++++++++++++---- main.tscn | 10 ++++------ repository.gd | 11 ++++++----- terminal.gd | 8 +------- 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/game.gd b/game.gd index 18758b8..dd51227 100644 --- a/game.gd +++ b/game.gd @@ -30,3 +30,9 @@ func load_state() -> bool: state[key] = new_state[key] savegame.close() return true + +func run(command): + var output = [] + OS.execute(command, [], true, output, true) + # Remove trailing newline. + return output[0].substr(0,len(output[0])-1) diff --git a/main.gd b/main.gd index 6edc646..3bc915e 100644 --- a/main.gd +++ b/main.gd @@ -2,13 +2,21 @@ extends Node2D var dragged = null -var viewport_size - var server var client_connection func _ready(): - viewport_size = get_viewport_rect().size + var level = "first" + var goal_repository_path = "goal" + var start_repository_path = "start" + var active_repository_path = "active" + var active_prefix = "/tmp/" + var levels_prefix = game.run("pwd")+"/levels/"+level+"/" + + OS.execute("rm", ["-r", active_prefix+active_repository_path], true) + OS.execute("cp", ["-ra", levels_prefix+start_repository_path, active_prefix+active_repository_path], true) + $GoalRepository.path = levels_prefix+goal_repository_path + $ActiveRepository.path = active_prefix+active_repository_path server = TCP_Server.new() server.listen(1234) @@ -29,7 +37,15 @@ func _process(delta): # dragged = null # if dragged: # dragged.position = get_global_mouse_position() - + +#func run(command): +# var a = command.split(" ") +# var cmd = a[0] +# a.remove(0) +# var output = [] +# OS.execute(cmd, a, true, output, true) +# print(command) +# print(output[0]) func read_commit_message(): $CommitMessage.show() diff --git a/main.tscn b/main.tscn index 58a028c..74eaff1 100644 --- a/main.tscn +++ b/main.tscn @@ -50,14 +50,12 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="Repository" parent="." instance=ExtResource( 3 )] -position = Vector2( 264.285, 118.658 ) -path = "/tmp/githydragit/" +[node name="GoalRepository" parent="." instance=ExtResource( 3 )] +position = Vector2( 21.5742, 19.4168 ) size = Vector2( 500, 1000 ) -[node name="Repository2" parent="." instance=ExtResource( 3 )] -position = Vector2( 880.229, 135.918 ) -path = "/tmp/githydragit/" +[node name="ActiveRepository" parent="." instance=ExtResource( 3 )] +position = Vector2( 704.399, 17.2594 ) size = Vector2( 500, 1000 ) [connection signal="text_entered" from="Terminal/Input" to="Terminal" method="send_command"] [connection signal="pressed" from="CommitMessage/Button" to="." method="save_commit_message"] diff --git a/repository.gd b/repository.gd index 9304d40..b7cab10 100644 --- a/repository.gd +++ b/repository.gd @@ -9,11 +9,12 @@ func _ready(): pass func _process(delta): - update_head() - update_refs() - update_index() - update_objects() - apply_forces() + if path: + update_head() + update_refs() + update_index() + update_objects() + apply_forces() func set_path(new_path): path = new_path diff --git a/terminal.gd b/terminal.gd index e96e12c..3bc73d6 100644 --- a/terminal.gd +++ b/terminal.gd @@ -7,7 +7,7 @@ func send_command(command): thread.start(self, "run_command_in_a_thread", command) func run_command_in_a_thread(command): - var cwd = run("pwd") + var cwd = game.run("pwd") var output = [] var hacky_command = command @@ -19,9 +19,3 @@ func run_command_in_a_thread(command): $Input.text = "" $Output.text = $Output.text + "$ " + command + "\n" + output[0] $Output.scroll_vertical = 999999 - -func run(command): - var output = [] - OS.execute(command, [], true, output, true) - # Remove trailing newline. - return output[0].substr(0,len(output[0])-1)