2020-01-29 20:25:13 +01:00
|
|
|
extends Node
|
|
|
|
|
2022-08-18 12:19:13 +02:00
|
|
|
var languages = {"en": tr("English"), "it": tr("Italian")} # Localizations allowed
|
2022-09-13 14:40:40 +02:00
|
|
|
var os_lang = OS.get_locale_language() # Variable for game localization (it, en, ecc...)
|
|
|
|
var levels_dir = "res://levels/" + os_lang
|
2021-09-08 17:00:51 +02:00
|
|
|
|
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
|
2021-01-21 15:08:59 +01:00
|
|
|
var used_cards = false
|
2020-10-13 14:16:36 +02:00
|
|
|
|
2020-12-23 12:01:07 +01:00
|
|
|
var current_chapter = 0
|
|
|
|
var current_level = 0
|
2021-01-28 12:08:12 +01:00
|
|
|
var skipped_title = false
|
2020-12-23 12:01:07 +01:00
|
|
|
|
2020-09-28 16:18:06 +02:00
|
|
|
var _file = "user://savegame.json"
|
|
|
|
var state = {}
|
|
|
|
|
2021-02-26 12:14:07 +01:00
|
|
|
var mutex
|
|
|
|
|
2020-01-29 20:25:13 +01:00
|
|
|
func _ready():
|
2022-08-17 20:19:42 +02:00
|
|
|
# Check if language traslation exist otherwise use the default language
|
|
|
|
if not languages.keys().has(os_lang):
|
|
|
|
os_lang = "en"
|
|
|
|
|
2021-02-26 12:14:07 +01:00
|
|
|
mutex = Mutex.new()
|
|
|
|
load_state()
|
|
|
|
|
2021-01-28 11:55:53 +01:00
|
|
|
if OS.has_feature("standalone"):
|
|
|
|
get_tree().set_auto_accept_quit(false)
|
2021-02-11 10:48:36 +01:00
|
|
|
else:
|
|
|
|
game.toggle_music()
|
2021-03-05 14:17:48 +01:00
|
|
|
|
|
|
|
if OS.get_name() == "Windows":
|
|
|
|
start_remote_shell()
|
2021-03-04 14:49:16 +01:00
|
|
|
global_shell = new_shell()
|
2021-02-26 12:14:07 +01:00
|
|
|
|
|
|
|
# var cmd = global_shell.run("echo hi")
|
|
|
|
# print(cmd)
|
|
|
|
# cmd = global_shell.run("seq 1 10")
|
|
|
|
# print(cmd)
|
|
|
|
# cmd = global_shell.run("ls")
|
|
|
|
# print(cmd)
|
|
|
|
# helpers.crash(":)")
|
2021-02-11 11:54:09 +01:00
|
|
|
|
|
|
|
if global_shell.run("command -v git &>/dev/null && echo yes || echo no") == "no\n":
|
|
|
|
game.skipped_title = true
|
|
|
|
get_tree().change_scene("res://scenes/no_git.tscn")
|
|
|
|
else:
|
|
|
|
create_file_in_game_env(".gitconfig", helpers.read_file("res://scripts/gitconfig"))
|
|
|
|
|
|
|
|
copy_script_to_game_env("fake-editor")
|
|
|
|
copy_script_to_game_env("hint")
|
2021-02-23 13:06:58 +01:00
|
|
|
|
|
|
|
func start_remote_shell():
|
|
|
|
var user_dir = ProjectSettings.globalize_path("user://")
|
|
|
|
var script_content = helpers.read_file("res://scripts/net-test")
|
|
|
|
var target_filename = user_dir + "net-test"
|
|
|
|
var target_file = File.new()
|
|
|
|
target_file.open(target_filename, File.WRITE)
|
|
|
|
target_file.store_string(script_content)
|
|
|
|
target_file.close()
|
2021-02-23 17:12:23 +01:00
|
|
|
helpers.exec_async(_perl_executable(), [target_filename, _bash_executable()])
|
2021-02-23 13:06:58 +01:00
|
|
|
|
|
|
|
func _perl_executable():
|
|
|
|
if OS.get_name() == "Windows":
|
|
|
|
return "dependencies/windows/git/usr/bin/perl.exe"
|
|
|
|
else:
|
|
|
|
return "perl"
|
|
|
|
|
2021-02-23 17:12:23 +01:00
|
|
|
func _bash_executable():
|
|
|
|
if OS.get_name() == "Windows":
|
|
|
|
return "dependencies/windows/git/usr/bin/bash.exe"
|
|
|
|
else:
|
|
|
|
return "bash"
|
|
|
|
|
2021-02-23 13:06:58 +01:00
|
|
|
func shell_received(text):
|
|
|
|
print(text)
|
|
|
|
|
2021-01-28 11:55:53 +01:00
|
|
|
func _notification(what):
|
|
|
|
if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
|
|
|
|
#get_tree().quit() # default behavio
|
|
|
|
get_tree().change_scene("res://scenes/survey.tscn")
|
|
|
|
|
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():
|
2021-02-18 18:06:17 +01:00
|
|
|
return {"history": [], "solved_levels": [], "received_hints": [], "cli_badge": [], "played_cards": []}
|
2020-09-28 16:18:06 +02:00
|
|
|
|
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
|
|
|
|
2021-01-19 12:48:16 +01:00
|
|
|
func notify(text, target=null, hint_slug=null):
|
|
|
|
if hint_slug:
|
|
|
|
if not state.has("received_hints"):
|
|
|
|
state["received_hints"] = []
|
|
|
|
if hint_slug in state["received_hints"]:
|
|
|
|
return
|
|
|
|
|
2020-12-22 15:38:43 +01:00
|
|
|
var notification = preload("res://scenes/notification.tscn").instance()
|
2021-09-15 18:15:10 +02:00
|
|
|
notification.text = tr(text)
|
2021-01-19 12:48:16 +01:00
|
|
|
if not target:
|
|
|
|
target = get_tree().root
|
|
|
|
target.call_deferred("add_child", notification)
|
|
|
|
|
|
|
|
if hint_slug:
|
|
|
|
state["received_hints"].push_back(hint_slug)
|
|
|
|
save_state()
|
2021-01-28 11:55:53 +01:00
|
|
|
|
|
|
|
func open_survey():
|
|
|
|
OS.shell_open("https://docs.google.com/forms/d/e/1FAIpQLSehHVcYfELT59h6plcn2ilbuqBcmDX3TH0qzB4jCgFIFOy_qg/viewform")
|
2021-02-11 10:46:08 +01:00
|
|
|
|
|
|
|
func toggle_music():
|
|
|
|
var music = game.find_node("Music")
|
|
|
|
if music.volume_db > -20:
|
|
|
|
music.volume_db -= 100
|
|
|
|
else:
|
|
|
|
music.volume_db += 100
|
2021-02-23 13:06:58 +01:00
|
|
|
|
|
|
|
func shell_test(command):
|
2021-02-26 12:14:07 +01:00
|
|
|
mutex.lock()
|
2021-02-27 15:07:35 +01:00
|
|
|
#print("go")
|
2021-03-05 14:17:48 +01:00
|
|
|
#print(command)
|
2021-02-27 15:07:35 +01:00
|
|
|
var before = OS.get_ticks_msec()
|
2021-03-05 14:17:48 +01:00
|
|
|
|
|
|
|
while not $ShellServer._connected:
|
|
|
|
$ShellServer._process(0.1)
|
|
|
|
|
2021-02-26 12:14:07 +01:00
|
|
|
var response = $ShellServer.send(command)
|
2021-02-27 15:07:35 +01:00
|
|
|
var after = OS.get_ticks_msec()
|
2021-03-05 14:17:48 +01:00
|
|
|
#print("took " + str(after-before)+" ms")
|
2021-02-27 15:07:35 +01:00
|
|
|
#print("stop")
|
2021-02-26 12:14:07 +01:00
|
|
|
mutex.unlock()
|
|
|
|
return response
|
2021-03-04 14:49:16 +01:00
|
|
|
|
|
|
|
func new_shell():
|
|
|
|
if OS.get_name() == "Windows":
|
|
|
|
return BetterShell.new()
|
|
|
|
else:
|
|
|
|
return Shell.new()
|