2020-03-18 15:23:38 +01:00
|
|
|
extends Node2D
|
|
|
|
|
2020-03-18 20:03:17 +01:00
|
|
|
var dragged = null
|
|
|
|
|
2020-09-01 15:14:01 +02:00
|
|
|
var server
|
|
|
|
var client_connection
|
|
|
|
|
2020-09-01 21:25:24 +02:00
|
|
|
onready var input = $Terminal/Control/Input
|
|
|
|
onready var output = $Terminal/Control/Output
|
2020-09-03 17:50:03 +02:00
|
|
|
onready var goal_repository = $Repositories/GoalRepository
|
|
|
|
onready var active_repository = $Repositories/ActiveRepository
|
2020-09-01 21:25:24 +02:00
|
|
|
|
2020-03-18 15:23:38 +01:00
|
|
|
func _ready():
|
2020-09-04 14:57:37 +02:00
|
|
|
# Initialize level select.
|
|
|
|
var options = $LevelSelect.get_popup()
|
|
|
|
for level in list_levels():
|
|
|
|
options.add_item(level)
|
|
|
|
options.connect("id_pressed", self, "load_level")
|
|
|
|
|
|
|
|
# Initialize TCP server for fake editor.
|
|
|
|
server = TCP_Server.new()
|
|
|
|
server.listen(1234)
|
|
|
|
|
|
|
|
# Load first level.
|
|
|
|
load_level(0)
|
|
|
|
input.grab_focus()
|
|
|
|
|
2020-09-01 19:20:51 +02:00
|
|
|
func list_levels():
|
2020-09-04 14:57:37 +02:00
|
|
|
var levels = []
|
|
|
|
var dir = Directory.new()
|
2020-09-08 16:27:36 +02:00
|
|
|
dir.open("res://levels")
|
2020-09-04 14:57:37 +02:00
|
|
|
dir.list_dir_begin()
|
2020-09-01 19:20:51 +02:00
|
|
|
|
2020-09-04 14:57:37 +02:00
|
|
|
while true:
|
|
|
|
var file = dir.get_next()
|
|
|
|
if file == "":
|
|
|
|
break
|
|
|
|
elif not file.begins_with("."):
|
|
|
|
levels.append(file)
|
2020-09-01 19:20:51 +02:00
|
|
|
|
2020-09-04 14:57:37 +02:00
|
|
|
dir.list_dir_end()
|
|
|
|
levels.sort()
|
|
|
|
return levels
|
2020-09-01 19:20:51 +02:00
|
|
|
|
|
|
|
func load_level(id):
|
2020-09-04 14:57:37 +02:00
|
|
|
var levels = list_levels()
|
|
|
|
|
|
|
|
var level = levels[id]
|
2020-09-08 16:27:36 +02:00
|
|
|
var level_prefix = "res://levels/"
|
2020-09-04 14:57:37 +02:00
|
|
|
|
2020-09-09 17:59:56 +02:00
|
|
|
var goal_repository_path = "/tmp/goal/"
|
|
|
|
var active_repository_path = "/tmp/active/"
|
2020-09-04 14:57:37 +02:00
|
|
|
var goal_script = level_prefix+level+"/goal"
|
|
|
|
var active_script = level_prefix+level+"/start"
|
|
|
|
|
|
|
|
var description = game.read_file(level_prefix+level+"/description")
|
|
|
|
$LevelDescription.bbcode_text = description
|
|
|
|
|
2020-09-08 16:36:52 +02:00
|
|
|
# We're actually destroying stuff here.
|
2020-09-08 16:00:18 +02:00
|
|
|
# Make sure that active_repository is in a temporary directory.
|
|
|
|
var expected_prefix = "/tmp"
|
|
|
|
if active_repository_path.substr(0,4) != expected_prefix:
|
|
|
|
push_error("Refusing to delete a directory that does not start with %s" % expected_prefix)
|
|
|
|
get_tree().quit()
|
|
|
|
if goal_repository_path.substr(0,4) != expected_prefix:
|
|
|
|
push_error("Refusing to delete a directory that does not start with %s" % expected_prefix)
|
|
|
|
get_tree().quit()
|
|
|
|
|
2020-09-08 16:36:52 +02:00
|
|
|
# Danger zone!
|
2020-09-08 16:46:12 +02:00
|
|
|
game.global_shell.run("rm -rf '%s'" % active_repository_path)
|
|
|
|
game.global_shell.run("rm -rf '%s'" % goal_repository_path)
|
2020-09-08 16:00:18 +02:00
|
|
|
|
2020-09-04 14:57:37 +02:00
|
|
|
construct_repo(goal_script, goal_repository_path)
|
|
|
|
construct_repo(active_script, active_repository_path)
|
|
|
|
|
|
|
|
goal_repository.path = goal_repository_path
|
|
|
|
active_repository.path = active_repository_path
|
|
|
|
|
2020-09-10 12:03:46 +02:00
|
|
|
var win_script = level_prefix+level+"/win"
|
|
|
|
var win_script_target = game.tmp_prefix+"/win"
|
|
|
|
var dir = Directory.new()
|
|
|
|
dir.copy(win_script, win_script_target)
|
|
|
|
|
2020-09-01 19:20:51 +02:00
|
|
|
func construct_repo(script, path):
|
2020-09-08 16:27:36 +02:00
|
|
|
# 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)
|
2020-09-09 17:59:56 +02:00
|
|
|
var script_path_outside = game.tmp_prefix+"/git-hydra-script"
|
|
|
|
var script_path = "/tmp/git-hydra-script"
|
|
|
|
game.write_file(script_path_outside, content)
|
2020-09-08 16:27:36 +02:00
|
|
|
|
2020-09-09 11:48:42 +02:00
|
|
|
game.global_shell.run("mkdir " + path)
|
|
|
|
game.global_shell.cd(path)
|
|
|
|
game.global_shell.run("git init")
|
2020-09-10 12:03:46 +02:00
|
|
|
var o = game.global_shell.run("sh "+script_path)
|
2020-09-09 11:48:42 +02:00
|
|
|
|
2020-09-08 20:13:49 +02:00
|
|
|
if game.debug:
|
2020-09-08 20:26:14 +02:00
|
|
|
print(o)
|
2020-09-04 14:57:37 +02:00
|
|
|
|
2020-09-08 20:26:14 +02:00
|
|
|
func _process(_delta):
|
2020-09-04 14:57:37 +02:00
|
|
|
if server.is_connection_available():
|
2020-09-09 13:25:00 +02:00
|
|
|
print("Client connected")
|
2020-09-04 14:57:37 +02:00
|
|
|
client_connection = server.take_connection()
|
|
|
|
read_commit_message()
|
|
|
|
|
2020-09-01 15:14:01 +02:00
|
|
|
func read_commit_message():
|
2020-09-04 14:57:37 +02:00
|
|
|
$CommitMessage.show()
|
|
|
|
input.editable = false
|
2020-09-09 18:32:57 +02:00
|
|
|
var fixme_path = game.tmp_prefix+"/active"
|
|
|
|
$CommitMessage.text = game.read_file(fixme_path+"/.git/COMMIT_EDITMSG")
|
2020-09-04 14:57:37 +02:00
|
|
|
$CommitMessage.grab_focus()
|
2020-09-01 15:14:01 +02:00
|
|
|
|
|
|
|
func save_commit_message():
|
2020-09-09 18:32:57 +02:00
|
|
|
var fixme_path = game.tmp_prefix+"/active"
|
|
|
|
game.write_file(fixme_path+"/.git/COMMIT_EDITMSG", $CommitMessage.text)
|
2020-09-04 14:57:37 +02:00
|
|
|
print("disconnect")
|
|
|
|
client_connection.disconnect_from_host()
|
|
|
|
input.editable = true
|
|
|
|
$CommitMessage.text = ""
|
|
|
|
$CommitMessage.hide()
|
|
|
|
input.grab_focus()
|