2020-01-29 20:25:13 +01:00
|
|
|
extends Node
|
|
|
|
|
2020-10-26 19:56:52 +01:00
|
|
|
var tmp_prefix = OS.get_user_data_dir() + "/tmp/"
|
2020-09-08 16:36:52 +02:00
|
|
|
var global_shell
|
2020-09-09 11:48:42 +02:00
|
|
|
var fake_editor
|
2020-01-29 20:25:13 +01:00
|
|
|
|
2020-10-13 14:16:36 +02:00
|
|
|
var dragged_object
|
2020-10-15 15:22:38 +02:00
|
|
|
var energy = 2
|
2020-10-13 14:16:36 +02:00
|
|
|
|
2020-09-28 16:18:06 +02:00
|
|
|
var _file = "user://savegame.json"
|
|
|
|
var state = {}
|
|
|
|
|
2020-01-29 20:25:13 +01:00
|
|
|
func _ready():
|
2020-09-08 16:36:52 +02:00
|
|
|
global_shell = Shell.new()
|
2020-10-26 21:29:11 +01:00
|
|
|
|
2020-10-29 17:23:12 +01:00
|
|
|
create_file_in_game_env(".gitconfig", helpers.read_file("res://scripts/gitconfig"))
|
|
|
|
|
2020-12-22 16:05:35 +01:00
|
|
|
copy_script_to_game_env("fake-editor")
|
|
|
|
copy_script_to_game_env("hint")
|
2020-10-26 21:29:11 +01:00
|
|
|
|
2020-09-28 16:18:06 +02:00
|
|
|
load_state()
|
2020-12-22 16:05:35 +01:00
|
|
|
|
|
|
|
func copy_script_to_game_env(name):
|
|
|
|
create_file_in_game_env(name, helpers.read_file("res://scripts/%s" % name))
|
|
|
|
global_shell.run("chmod u+x '%s'" % (tmp_prefix + name))
|
2020-09-28 16:18:06 +02:00
|
|
|
|
|
|
|
func _initial_state():
|
|
|
|
return {"history": []}
|
|
|
|
|
2020-09-29 17:52:31 +02:00
|
|
|
func save_state():
|
2020-09-28 16:18:06 +02:00
|
|
|
var savegame = File.new()
|
|
|
|
|
|
|
|
savegame.open(_file, File.WRITE)
|
|
|
|
savegame.store_line(to_json(state))
|
|
|
|
savegame.close()
|
|
|
|
|
2020-09-29 17:52:31 +02:00
|
|
|
func load_state():
|
2020-09-28 16:18:06 +02:00
|
|
|
var savegame = File.new()
|
|
|
|
if not savegame.file_exists(_file):
|
|
|
|
save_state()
|
|
|
|
|
|
|
|
savegame.open(_file, File.READ)
|
|
|
|
|
|
|
|
state = _initial_state()
|
|
|
|
var new_state = parse_json(savegame.get_line())
|
|
|
|
for key in new_state:
|
|
|
|
state[key] = new_state[key]
|
|
|
|
savegame.close()
|
2020-09-22 13:15:36 +02:00
|
|
|
|
2020-10-26 21:29:11 +01:00
|
|
|
# filename is relative to the tmp directory!
|
|
|
|
func create_file_in_game_env(filename, content):
|
|
|
|
global_shell.cd(tmp_prefix)
|
|
|
|
# Quoted HERE doc doesn't do any substitutions inside.
|
|
|
|
global_shell.run("cat > '%s' <<'HEREHEREHERE'\n%s\nHEREHEREHERE" % [filename, content])
|
2020-12-22 15:38:43 +01:00
|
|
|
|
|
|
|
func notify(text):
|
|
|
|
print(text)
|
|
|
|
var notification = preload("res://scenes/notification.tscn").instance()
|
|
|
|
notification.text = text
|
|
|
|
get_tree().root.call_deferred("add_child", notification)
|