2020-09-21 15:25:54 +02:00
|
|
|
extends Control
|
2020-03-18 15:23:38 +01:00
|
|
|
|
2020-03-18 20:03:17 +01:00
|
|
|
var dragged = null
|
|
|
|
|
2020-09-29 19:40:17 +02:00
|
|
|
var current_chapter
|
|
|
|
var current_level
|
2020-09-01 15:14:01 +02:00
|
|
|
|
2020-09-29 14:26:20 +02:00
|
|
|
onready var terminal = $Columns/RightSide/Terminal
|
2020-09-14 19:36:58 +02:00
|
|
|
onready var input = terminal.input
|
|
|
|
onready var output = terminal.output
|
2020-09-29 14:26:20 +02:00
|
|
|
onready var goal_repository = $Columns/Repositories/GoalRepository
|
|
|
|
onready var active_repository = $Columns/Repositories/ActiveRepository
|
|
|
|
onready var level_select = $Columns/RightSide/TopStuff/Menu/LevelSelect
|
|
|
|
onready var chapter_select = $Columns/RightSide/TopStuff/Menu/ChapterSelect
|
|
|
|
onready var next_level_button = $Columns/RightSide/TopStuff/Menu/NextLevelButton
|
|
|
|
onready var level_name = $Columns/RightSide/TopStuff/LevelPanel/LevelName
|
|
|
|
onready var level_description = $Columns/RightSide/TopStuff/LevelPanel/Text/LevelDescription
|
|
|
|
onready var level_congrats = $Columns/RightSide/TopStuff/LevelPanel/Text/LevelCongrats
|
2020-09-01 21:25:24 +02:00
|
|
|
|
2020-03-18 15:23:38 +01:00
|
|
|
func _ready():
|
2020-09-29 17:52:31 +02:00
|
|
|
var args = helpers.parse_args()
|
|
|
|
|
|
|
|
if args.has("sandbox"):
|
|
|
|
var err = get_tree().change_scene("res://sandbox.tscn")
|
|
|
|
if err != OK:
|
|
|
|
helpers.crash("Could not change to sandbox scene")
|
|
|
|
return
|
2020-09-29 19:40:17 +02:00
|
|
|
|
|
|
|
current_chapter = 0
|
|
|
|
current_level = 0
|
2020-09-29 17:52:31 +02:00
|
|
|
|
2020-09-04 14:57:37 +02:00
|
|
|
# Initialize level select.
|
2020-09-28 19:02:12 +02:00
|
|
|
level_select.connect("item_selected", self, "load_level")
|
|
|
|
repopulate_levels()
|
|
|
|
level_select.select(0)
|
2020-09-04 14:57:37 +02:00
|
|
|
|
2020-09-28 18:40:41 +02:00
|
|
|
# Initialize chapter select.
|
2020-09-28 19:02:12 +02:00
|
|
|
chapter_select.connect("item_selected", self, "load_chapter")
|
|
|
|
repopulate_chapters()
|
|
|
|
chapter_select.select(0)
|
2020-09-28 18:40:41 +02:00
|
|
|
|
2020-09-29 19:40:17 +02:00
|
|
|
# Load first chapter.
|
|
|
|
load_chapter(0)
|
2020-09-04 14:57:37 +02:00
|
|
|
input.grab_focus()
|
2020-09-01 19:20:51 +02:00
|
|
|
|
2020-09-28 18:40:41 +02:00
|
|
|
func load_chapter(id):
|
2020-09-29 19:40:17 +02:00
|
|
|
current_chapter = id
|
2020-09-28 19:02:12 +02:00
|
|
|
load_level(0)
|
2020-09-28 18:40:41 +02:00
|
|
|
|
2020-09-29 19:40:17 +02:00
|
|
|
func load_level(level_id):
|
2020-09-24 10:52:58 +02:00
|
|
|
AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), true)
|
|
|
|
|
2020-09-21 15:25:54 +02:00
|
|
|
next_level_button.hide()
|
|
|
|
level_congrats.hide()
|
|
|
|
level_description.show()
|
2020-09-29 19:40:17 +02:00
|
|
|
current_level = level_id
|
2020-09-04 14:57:37 +02:00
|
|
|
|
2020-09-29 16:12:58 +02:00
|
|
|
var goal_repository_path = game.tmp_prefix_inside+"/repos/goal/"
|
|
|
|
var active_repository_path = game.tmp_prefix_inside+"/repos/active/"
|
2020-09-29 19:40:17 +02:00
|
|
|
|
|
|
|
var level = levels.chapters[current_chapter].levels[current_level]
|
|
|
|
level_description.bbcode_text = level.description
|
|
|
|
level_congrats.bbcode_text = level.congrats
|
|
|
|
level_name.text = level.slug
|
2020-09-04 14:57:37 +02:00
|
|
|
|
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.
|
2020-09-29 18:21:39 +02:00
|
|
|
helpers.careful_delete(active_repository_path)
|
|
|
|
helpers.careful_delete(goal_repository_path)
|
2020-09-15 12:36:22 +02:00
|
|
|
|
2020-09-29 19:40:17 +02:00
|
|
|
|
|
|
|
construct_repo(level.start_commands +"\n"+ level.goal_commands, goal_repository_path)
|
|
|
|
construct_repo(level.start_commands, active_repository_path)
|
2020-09-04 14:57:37 +02:00
|
|
|
|
|
|
|
goal_repository.path = goal_repository_path
|
|
|
|
active_repository.path = active_repository_path
|
|
|
|
|
2020-09-29 16:12:58 +02:00
|
|
|
var win_script_target = game.tmp_prefix_outside+"/win"
|
2020-09-29 19:40:17 +02:00
|
|
|
helpers.write_file(win_script_target, level.win_commands)
|
2020-09-14 15:35:30 +02:00
|
|
|
|
|
|
|
terminal.clear()
|
2020-09-24 10:52:58 +02:00
|
|
|
|
|
|
|
# Unmute the audio after a while, so that player can hear pop sounds for
|
|
|
|
# nodes they create.
|
|
|
|
var t = Timer.new()
|
|
|
|
t.wait_time = 3
|
|
|
|
add_child(t)
|
|
|
|
t.start()
|
|
|
|
yield(t, "timeout")
|
|
|
|
AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), false)
|
|
|
|
# FIXME: Need to clean these up when switching levels somehow.
|
2020-09-10 12:47:18 +02:00
|
|
|
|
2020-09-13 21:55:24 +02:00
|
|
|
func reload_level():
|
|
|
|
load_level(current_level)
|
|
|
|
|
2020-09-10 12:47:18 +02:00
|
|
|
func load_next_level():
|
2020-09-29 19:40:17 +02:00
|
|
|
current_level = (current_level + 1) % levels.chapters[current_chapter].size()
|
2020-09-10 12:47:18 +02:00
|
|
|
load_level(current_level)
|
2020-09-10 12:03:46 +02:00
|
|
|
|
2020-09-15 12:36:22 +02:00
|
|
|
func construct_repo(script_content, 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.
|
2020-09-15 12:36:22 +02:00
|
|
|
|
2020-09-29 16:12:58 +02:00
|
|
|
var script_path_outside = game.tmp_prefix_outside+"/git-hydra-script"
|
|
|
|
var script_path_inside = game.tmp_prefix_inside+"/git-hydra-script"
|
2020-09-29 14:53:00 +02:00
|
|
|
helpers.write_file(script_path_outside, script_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-15 12:36:22 +02:00
|
|
|
game.global_shell.run("git symbolic-ref HEAD refs/heads/main")
|
2020-09-24 10:25:38 +02:00
|
|
|
# Read stdin from /dev/null so that interactive commands don't block.
|
2020-09-29 16:12:58 +02:00
|
|
|
game.global_shell.run("bash "+script_path_inside+" </dev/null")
|
2020-09-04 14:57:37 +02:00
|
|
|
|
2020-09-11 13:12:12 +02:00
|
|
|
func show_win_status():
|
2020-09-21 15:25:54 +02:00
|
|
|
next_level_button.show()
|
|
|
|
level_description.hide()
|
|
|
|
level_congrats.show()
|
2020-09-15 16:31:41 +02:00
|
|
|
|
|
|
|
func repopulate_levels():
|
2020-09-29 19:40:17 +02:00
|
|
|
levels.reload()
|
2020-09-28 19:02:12 +02:00
|
|
|
level_select.clear()
|
2020-09-29 19:40:17 +02:00
|
|
|
for level in levels.chapters[current_chapter].levels:
|
|
|
|
level_select.add_item(level.slug)
|
2020-09-28 18:40:41 +02:00
|
|
|
|
|
|
|
func repopulate_chapters():
|
2020-09-29 19:40:17 +02:00
|
|
|
levels.reload()
|
2020-09-28 19:02:12 +02:00
|
|
|
chapter_select.clear()
|
2020-09-29 19:40:17 +02:00
|
|
|
for c in levels.chapters:
|
|
|
|
chapter_select.add_item(c.slug)
|