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-01 19:20:51 +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")
|
2020-09-01 15:14:01 +02:00
|
|
|
|
2020-09-01 19:20:51 +02:00
|
|
|
# Initialize TCP server for fake editor.
|
2020-09-01 15:14:01 +02:00
|
|
|
server = TCP_Server.new()
|
|
|
|
server.listen(1234)
|
|
|
|
|
2020-09-01 19:32:33 +02:00
|
|
|
# Load first level.
|
|
|
|
load_level(0)
|
2020-09-01 21:25:24 +02:00
|
|
|
input.grab_focus()
|
2020-09-01 19:32:33 +02:00
|
|
|
|
2020-09-01 19:20:51 +02:00
|
|
|
func list_levels():
|
|
|
|
var levels = []
|
|
|
|
var dir = Directory.new()
|
|
|
|
dir.open("levels")
|
|
|
|
dir.list_dir_begin()
|
|
|
|
|
|
|
|
while true:
|
|
|
|
var file = dir.get_next()
|
|
|
|
if file == "":
|
|
|
|
break
|
|
|
|
elif not file.begins_with("."):
|
|
|
|
levels.append(file)
|
|
|
|
|
|
|
|
dir.list_dir_end()
|
2020-09-03 19:22:46 +02:00
|
|
|
levels.sort()
|
2020-09-01 19:20:51 +02:00
|
|
|
return levels
|
|
|
|
|
|
|
|
func load_level(id):
|
|
|
|
var levels = list_levels()
|
|
|
|
|
|
|
|
var level = levels[id]
|
|
|
|
var cwd = game.run("pwd")
|
|
|
|
var tmp_prefix = "/tmp/"
|
|
|
|
var level_prefix = cwd+"/levels/"
|
|
|
|
|
|
|
|
var goal_repository_path = tmp_prefix+"goal/"
|
|
|
|
var active_repository_path = tmp_prefix+"active/"
|
|
|
|
var goal_script = level_prefix+level+"/goal"
|
|
|
|
var active_script = level_prefix+level+"/start"
|
|
|
|
|
2020-09-03 19:22:46 +02:00
|
|
|
var description = game.read_file(level_prefix+level+"/description")
|
|
|
|
$LevelDescription.bbcode_text = description
|
|
|
|
|
2020-09-01 19:20:51 +02:00
|
|
|
OS.execute("rm", ["-r", active_repository_path], true)
|
|
|
|
OS.execute("rm", ["-r", goal_repository_path], true)
|
|
|
|
construct_repo(goal_script, goal_repository_path)
|
|
|
|
construct_repo(active_script, active_repository_path)
|
|
|
|
|
2020-09-03 17:50:03 +02:00
|
|
|
goal_repository.path = goal_repository_path
|
|
|
|
active_repository.path = active_repository_path
|
2020-09-01 19:20:51 +02:00
|
|
|
|
|
|
|
func construct_repo(script, path):
|
|
|
|
print(path)
|
|
|
|
game.sh("mkdir "+path)
|
|
|
|
game.sh("git init", path)
|
|
|
|
var commands = game.read_file(script).split("\n")
|
|
|
|
print(commands)
|
|
|
|
for command in commands:
|
|
|
|
print(command)
|
|
|
|
game.sh(command, path)
|
|
|
|
|
2020-03-18 20:03:17 +01:00
|
|
|
func _process(delta):
|
2020-09-01 15:14:01 +02:00
|
|
|
if server.is_connection_available():
|
|
|
|
client_connection = server.take_connection()
|
|
|
|
read_commit_message()
|
2020-09-01 17:24:21 +02:00
|
|
|
# if true or get_global_mouse_position().x < get_viewport_rect().size.x*0.7:
|
|
|
|
# if Input.is_action_just_pressed("click"):
|
|
|
|
# var mindist = 9999999
|
|
|
|
# for o in objects.values():
|
|
|
|
# var d = o.position.distance_to(get_global_mouse_position())
|
|
|
|
# if d < mindist:
|
|
|
|
# mindist = d
|
|
|
|
# dragged = o
|
|
|
|
# if Input.is_action_just_released("click"):
|
|
|
|
# dragged = null
|
|
|
|
# if dragged:
|
|
|
|
# dragged.position = get_global_mouse_position()
|
2020-09-01 18:26:43 +02:00
|
|
|
|
|
|
|
#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])
|
2020-08-24 16:48:30 +02:00
|
|
|
|
2020-09-01 15:14:01 +02:00
|
|
|
func read_commit_message():
|
|
|
|
$CommitMessage.show()
|
2020-09-01 21:25:24 +02:00
|
|
|
input.editable = false
|
2020-09-03 17:50:03 +02:00
|
|
|
$CommitMessage.text = game.read_file(active_repository.path+"/.git/COMMIT_EDITMSG")
|
2020-09-01 19:59:07 +02:00
|
|
|
$CommitMessage.grab_focus()
|
2020-09-01 15:14:01 +02:00
|
|
|
|
|
|
|
func save_commit_message():
|
2020-09-03 17:50:03 +02:00
|
|
|
game.write_file(active_repository.path+"/.git/COMMIT_EDITMSG", $CommitMessage.text)
|
2020-09-01 15:14:01 +02:00
|
|
|
print("disconnect")
|
|
|
|
client_connection.disconnect_from_host()
|
2020-09-01 21:25:24 +02:00
|
|
|
input.editable = true
|
2020-09-01 15:14:01 +02:00
|
|
|
$CommitMessage.text = ""
|
|
|
|
$CommitMessage.hide()
|
2020-09-01 21:25:24 +02:00
|
|
|
input.grab_focus()
|