Set up goal and active level from template repos

This commit is contained in:
Sebastian Morr 2020-09-01 18:26:43 +02:00
parent eb53163676
commit 1b5cbe9cb0
5 changed files with 37 additions and 22 deletions

View file

@ -30,3 +30,9 @@ func load_state() -> bool:
state[key] = new_state[key] state[key] = new_state[key]
savegame.close() savegame.close()
return true 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)

24
main.gd
View file

@ -2,13 +2,21 @@ extends Node2D
var dragged = null var dragged = null
var viewport_size
var server var server
var client_connection var client_connection
func _ready(): 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 = TCP_Server.new()
server.listen(1234) server.listen(1234)
@ -29,7 +37,15 @@ func _process(delta):
# dragged = null # dragged = null
# if dragged: # if dragged:
# dragged.position = get_global_mouse_position() # 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(): func read_commit_message():
$CommitMessage.show() $CommitMessage.show()

View file

@ -50,14 +50,12 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="Repository" parent="." instance=ExtResource( 3 )] [node name="GoalRepository" parent="." instance=ExtResource( 3 )]
position = Vector2( 264.285, 118.658 ) position = Vector2( 21.5742, 19.4168 )
path = "/tmp/githydragit/"
size = Vector2( 500, 1000 ) size = Vector2( 500, 1000 )
[node name="Repository2" parent="." instance=ExtResource( 3 )] [node name="ActiveRepository" parent="." instance=ExtResource( 3 )]
position = Vector2( 880.229, 135.918 ) position = Vector2( 704.399, 17.2594 )
path = "/tmp/githydragit/"
size = Vector2( 500, 1000 ) size = Vector2( 500, 1000 )
[connection signal="text_entered" from="Terminal/Input" to="Terminal" method="send_command"] [connection signal="text_entered" from="Terminal/Input" to="Terminal" method="send_command"]
[connection signal="pressed" from="CommitMessage/Button" to="." method="save_commit_message"] [connection signal="pressed" from="CommitMessage/Button" to="." method="save_commit_message"]

View file

@ -9,11 +9,12 @@ func _ready():
pass pass
func _process(delta): func _process(delta):
update_head() if path:
update_refs() update_head()
update_index() update_refs()
update_objects() update_index()
apply_forces() update_objects()
apply_forces()
func set_path(new_path): func set_path(new_path):
path = new_path path = new_path

View file

@ -7,7 +7,7 @@ func send_command(command):
thread.start(self, "run_command_in_a_thread", command) thread.start(self, "run_command_in_a_thread", command)
func 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 output = []
var hacky_command = command var hacky_command = command
@ -19,9 +19,3 @@ func run_command_in_a_thread(command):
$Input.text = "" $Input.text = ""
$Output.text = $Output.text + "$ " + command + "\n" + output[0] $Output.text = $Output.text + "$ " + command + "\n" + output[0]
$Output.scroll_vertical = 999999 $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)