2020-09-21 16:25:54 +03:00
|
|
|
extends Control
|
2020-03-18 17:23:38 +03:00
|
|
|
|
2020-03-18 22:03:17 +03:00
|
|
|
var dragged = null
|
|
|
|
|
2020-09-29 20:40:17 +03:00
|
|
|
var current_chapter
|
|
|
|
var current_level
|
2020-09-01 16:14:01 +03:00
|
|
|
|
2020-10-27 17:48:23 +03:00
|
|
|
onready var terminal = $Rows/Controls/Terminal
|
2020-09-14 20:36:58 +03:00
|
|
|
onready var input = terminal.input
|
|
|
|
onready var output = terminal.output
|
2020-10-14 15:48:38 +03:00
|
|
|
onready var repositories_node = $Rows/Columns/Repositories
|
2020-09-30 22:36:11 +03:00
|
|
|
var repositories = {}
|
2020-10-27 17:48:23 +03:00
|
|
|
onready var level_select = $Rows/Columns/LevelInfo/Menu/LevelSelect
|
|
|
|
onready var chapter_select = $Rows/Columns/LevelInfo/Menu/ChapterSelect
|
|
|
|
onready var next_level_button = $Rows/Columns/LevelInfo/Menu/NextLevelButton
|
|
|
|
onready var level_name = $Rows/Columns/LevelInfo/LevelPanel/LevelName
|
|
|
|
onready var level_description = $Rows/Columns/LevelInfo/LevelPanel/Text/LevelDescription
|
|
|
|
onready var level_congrats = $Rows/Columns/LevelInfo/LevelPanel/Text/LevelCongrats
|
|
|
|
onready var cards = $Rows/Controls/Cards
|
2020-09-01 22:25:24 +03:00
|
|
|
|
2020-03-18 17:23:38 +03:00
|
|
|
func _ready():
|
2020-09-29 18:52:31 +03:00
|
|
|
var args = helpers.parse_args()
|
|
|
|
|
|
|
|
if args.has("sandbox"):
|
2020-10-26 21:15:47 +03:00
|
|
|
var err = get_tree().change_scene("res://scenes/sandbox.tscn")
|
2020-09-29 18:52:31 +03:00
|
|
|
if err != OK:
|
|
|
|
helpers.crash("Could not change to sandbox scene")
|
|
|
|
return
|
2020-09-29 20:40:17 +03:00
|
|
|
|
2020-10-22 15:01:08 +03:00
|
|
|
current_chapter = 0
|
2020-09-29 20:40:17 +03:00
|
|
|
current_level = 0
|
2020-09-29 18:52:31 +03:00
|
|
|
|
2020-09-04 15:57:37 +03:00
|
|
|
# Initialize level select.
|
2020-09-28 20:02:12 +03:00
|
|
|
level_select.connect("item_selected", self, "load_level")
|
|
|
|
repopulate_levels()
|
2020-10-06 11:38:31 +03:00
|
|
|
level_select.select(current_level)
|
2020-09-04 15:57:37 +03:00
|
|
|
|
2020-09-28 19:40:41 +03:00
|
|
|
# Initialize chapter select.
|
2020-09-28 20:02:12 +03:00
|
|
|
chapter_select.connect("item_selected", self, "load_chapter")
|
|
|
|
repopulate_chapters()
|
2020-10-06 11:38:31 +03:00
|
|
|
chapter_select.select(current_chapter)
|
2020-09-28 19:40:41 +03:00
|
|
|
|
2020-09-29 20:40:17 +03:00
|
|
|
# Load first chapter.
|
2020-10-06 11:38:31 +03:00
|
|
|
load_chapter(current_chapter)
|
2020-09-04 15:57:37 +03:00
|
|
|
input.grab_focus()
|
2020-09-01 20:20:51 +03:00
|
|
|
|
2020-09-28 19:40:41 +03:00
|
|
|
func load_chapter(id):
|
2020-09-29 20:40:17 +03:00
|
|
|
current_chapter = id
|
2020-09-29 20:50:58 +03:00
|
|
|
repopulate_levels()
|
2020-09-28 20:02:12 +03:00
|
|
|
load_level(0)
|
2020-09-28 19:40:41 +03:00
|
|
|
|
2020-09-29 20:40:17 +03:00
|
|
|
func load_level(level_id):
|
2020-09-21 16:25:54 +03:00
|
|
|
next_level_button.hide()
|
|
|
|
level_congrats.hide()
|
|
|
|
level_description.show()
|
2020-09-29 20:40:17 +03:00
|
|
|
current_level = level_id
|
2020-09-04 15:57:37 +03:00
|
|
|
|
2020-09-29 21:01:25 +03:00
|
|
|
AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), true)
|
|
|
|
|
2020-09-29 20:50:58 +03:00
|
|
|
levels.chapters[current_chapter].levels[current_level].construct()
|
2020-09-29 20:40:17 +03:00
|
|
|
|
|
|
|
var level = levels.chapters[current_chapter].levels[current_level]
|
|
|
|
level_description.bbcode_text = level.description
|
|
|
|
level_congrats.bbcode_text = level.congrats
|
2020-10-12 21:09:51 +03:00
|
|
|
level_name.text = level.title
|
2020-10-27 14:16:33 +03:00
|
|
|
cards.draw(levels.chapters[current_chapter].levels[current_level].cards)
|
2020-09-04 15:57:37 +03:00
|
|
|
|
2020-09-30 22:36:11 +03:00
|
|
|
for r in repositories_node.get_children():
|
|
|
|
r.queue_free()
|
|
|
|
repositories = {}
|
|
|
|
|
2020-10-12 19:57:25 +03:00
|
|
|
var repo_names = level.repos.keys()
|
|
|
|
repo_names.invert()
|
|
|
|
|
|
|
|
for r in repo_names:
|
2020-09-30 22:36:11 +03:00
|
|
|
var repo = level.repos[r]
|
2020-10-26 21:15:47 +03:00
|
|
|
var new_repo = preload("res://scenes/repository.tscn").instance()
|
2020-09-30 22:36:11 +03:00
|
|
|
new_repo.path = repo.path
|
|
|
|
new_repo.label = repo.slug
|
|
|
|
new_repo.size_flags_horizontal = SIZE_EXPAND_FILL
|
|
|
|
repositories_node.add_child(new_repo)
|
|
|
|
repositories[r] = new_repo
|
|
|
|
|
2020-10-12 20:00:51 +03:00
|
|
|
terminal.repository = repositories[repo_names[repo_names.size()-1]]
|
2020-09-14 16:35:30 +03:00
|
|
|
terminal.clear()
|
2020-10-22 17:19:22 +03:00
|
|
|
terminal.find_node("TextEditor").close()
|
2020-09-29 21:01:25 +03:00
|
|
|
|
|
|
|
# Unmute the audio after a while, so that player can hear pop sounds for
|
|
|
|
# nodes they create.
|
|
|
|
var t = Timer.new()
|
2020-10-22 19:05:25 +03:00
|
|
|
t.wait_time = 1
|
2020-09-29 21:01:25 +03:00
|
|
|
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 13:47:18 +03:00
|
|
|
|
2020-09-13 22:55:24 +03:00
|
|
|
func reload_level():
|
2020-09-30 22:36:11 +03:00
|
|
|
levels.reload()
|
2020-09-13 22:55:24 +03:00
|
|
|
load_level(current_level)
|
|
|
|
|
2020-09-10 13:47:18 +03:00
|
|
|
func load_next_level():
|
2020-09-29 20:50:58 +03:00
|
|
|
current_level = (current_level + 1) % levels.chapters[current_chapter].levels.size()
|
2020-09-10 13:47:18 +03:00
|
|
|
load_level(current_level)
|
2020-09-10 13:03:46 +03:00
|
|
|
|
2020-09-11 14:12:12 +03:00
|
|
|
func show_win_status():
|
2020-10-22 17:19:22 +03:00
|
|
|
if not level_congrats.visible:
|
|
|
|
next_level_button.show()
|
|
|
|
level_description.hide()
|
|
|
|
level_congrats.show()
|
|
|
|
$SuccessSound.play()
|
2020-09-15 17:31:41 +03:00
|
|
|
|
|
|
|
func repopulate_levels():
|
2020-09-29 20:40:17 +03:00
|
|
|
levels.reload()
|
2020-09-28 20:02:12 +03:00
|
|
|
level_select.clear()
|
2020-09-29 20:40:17 +03:00
|
|
|
for level in levels.chapters[current_chapter].levels:
|
|
|
|
level_select.add_item(level.slug)
|
2020-10-01 15:56:24 +03:00
|
|
|
level_select.select(current_level)
|
2020-09-28 19:40:41 +03:00
|
|
|
|
|
|
|
func repopulate_chapters():
|
2020-09-29 20:40:17 +03:00
|
|
|
levels.reload()
|
2020-09-28 20:02:12 +03:00
|
|
|
chapter_select.clear()
|
2020-09-29 20:40:17 +03:00
|
|
|
for c in levels.chapters:
|
|
|
|
chapter_select.add_item(c.slug)
|
2020-10-01 15:56:24 +03:00
|
|
|
chapter_select.select(current_chapter)
|
2020-09-29 21:01:25 +03:00
|
|
|
|
2020-09-30 22:36:11 +03:00
|
|
|
func update_repos():
|
|
|
|
for r in repositories:
|
|
|
|
var repo = repositories[r]
|
|
|
|
repo.update_everything()
|
|
|
|
|
2020-09-29 21:01:25 +03:00
|
|
|
if levels.chapters[current_chapter].levels[current_level].check_win():
|
|
|
|
show_win_status()
|
2020-10-14 15:52:29 +03:00
|
|
|
|
|
|
|
func toggle_cards():
|
|
|
|
cards.visible = not cards.visible
|