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-10-27 15:48:23 +01:00
|
|
|
onready var terminal = $Rows/Controls/Terminal
|
2020-09-14 19:36:58 +02:00
|
|
|
onready var input = terminal.input
|
|
|
|
onready var output = terminal.output
|
2020-10-14 14:48:38 +02:00
|
|
|
onready var repositories_node = $Rows/Columns/Repositories
|
2020-09-30 21:36:11 +02:00
|
|
|
var repositories = {}
|
2021-01-19 11:13:40 +01:00
|
|
|
onready var next_level_button = $Menu/NextLevelButton
|
2020-10-27 17:32:41 +01:00
|
|
|
onready var level_name = $Rows/Columns/RightSide/LevelInfo/LevelPanel/LevelName
|
|
|
|
onready var level_description = $Rows/Columns/RightSide/LevelInfo/LevelPanel/Text/LevelDescription
|
|
|
|
onready var level_congrats = $Rows/Columns/RightSide/LevelInfo/LevelPanel/Text/LevelCongrats
|
2020-10-27 15:48:23 +01:00
|
|
|
onready var cards = $Rows/Controls/Cards
|
2020-10-27 17:32:41 +01:00
|
|
|
onready var file_browser = $Rows/Columns/RightSide/FileBrowser
|
2021-01-08 13:54:37 +01:00
|
|
|
onready var goals = $Rows/Columns/RightSide/LevelInfo/LevelPanel/Goals
|
2020-09-01 21:25:24 +02:00
|
|
|
|
2020-12-22 16:05:35 +01:00
|
|
|
var _hint_server
|
|
|
|
var _hint_client_connection
|
|
|
|
|
2020-03-18 15:23:38 +01:00
|
|
|
func _ready():
|
2020-12-22 16:05:35 +01:00
|
|
|
_hint_server = TCP_Server.new()
|
|
|
|
_hint_server.listen(1235)
|
|
|
|
|
2020-09-29 17:52:31 +02:00
|
|
|
var args = helpers.parse_args()
|
|
|
|
|
|
|
|
if args.has("sandbox"):
|
2020-10-26 19:15:47 +01:00
|
|
|
var err = get_tree().change_scene("res://scenes/sandbox.tscn")
|
2020-09-29 17:52:31 +02:00
|
|
|
if err != OK:
|
|
|
|
helpers.crash("Could not change to sandbox scene")
|
|
|
|
return
|
|
|
|
|
2020-09-04 14:57:37 +02:00
|
|
|
# Initialize level select.
|
2021-01-19 11:13:40 +01:00
|
|
|
# level_select.connect("item_selected", self, "load_level")
|
|
|
|
# repopulate_levels()
|
|
|
|
# level_select.select(game.current_level)
|
2020-09-04 14:57:37 +02:00
|
|
|
|
2021-01-19 11:13:40 +01:00
|
|
|
# # Initialize chapter select.
|
|
|
|
# chapter_select.connect("item_selected", self, "load_chapter")
|
|
|
|
# repopulate_chapters()
|
|
|
|
# chapter_select.select(game.current_chapter)
|
2020-09-28 18:40:41 +02:00
|
|
|
|
2020-12-23 12:01:07 +01:00
|
|
|
# Load current level.
|
|
|
|
load_level(game.current_level)
|
2020-09-04 14:57:37 +02:00
|
|
|
input.grab_focus()
|
2020-12-22 16:05:35 +01:00
|
|
|
|
2023-05-16 13:59:21 +02:00
|
|
|
func _process(_delta):
|
2020-12-22 16:05:35 +01:00
|
|
|
if _hint_server.is_connection_available():
|
|
|
|
_hint_client_connection = _hint_server.take_connection()
|
|
|
|
var length = _hint_client_connection.get_u32()
|
|
|
|
var message = _hint_client_connection.get_string(length)
|
|
|
|
game.notify(message)
|
2021-02-18 16:44:04 +01:00
|
|
|
# if game.used_cards:
|
|
|
|
# $Menu/CLIBadge.impossible = true
|
2021-02-18 15:45:39 +01:00
|
|
|
|
|
|
|
# Magic height number to fix a weird rescaling bug that affected
|
|
|
|
# the Rows height.
|
|
|
|
$Rows.rect_size.y = 1064
|
2020-09-01 19:20:51 +02:00
|
|
|
|
2020-09-28 18:40:41 +02:00
|
|
|
func load_chapter(id):
|
2020-12-23 12:01:07 +01:00
|
|
|
game.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-21 15:25:54 +02:00
|
|
|
next_level_button.hide()
|
|
|
|
level_congrats.hide()
|
|
|
|
level_description.show()
|
2020-12-23 12:01:07 +01:00
|
|
|
game.current_level = level_id
|
2021-01-21 15:08:59 +01:00
|
|
|
game.used_cards = false
|
2020-09-04 14:57:37 +02:00
|
|
|
|
2021-02-04 16:11:56 +01:00
|
|
|
AudioServer.set_bus_mute(AudioServer.get_bus_index("SFX"), true)
|
2020-09-29 20:01:25 +02:00
|
|
|
|
2020-12-23 12:01:07 +01:00
|
|
|
levels.chapters[game.current_chapter].levels[game.current_level].construct()
|
2020-09-29 19:40:17 +02:00
|
|
|
|
2020-12-23 12:01:07 +01:00
|
|
|
var level = levels.chapters[game.current_chapter].levels[game.current_level]
|
2020-12-22 17:53:16 +01:00
|
|
|
level_description.bbcode_text = level.description[0]
|
2020-09-29 19:40:17 +02:00
|
|
|
level_congrats.bbcode_text = level.congrats
|
2020-10-12 20:09:51 +02:00
|
|
|
level_name.text = level.title
|
2021-02-18 16:44:04 +01:00
|
|
|
|
|
|
|
var slug = levels.chapters[game.current_chapter].slug + "/" + level.slug
|
|
|
|
$Menu/CLIBadge.active = slug in game.state["cli_badge"]
|
|
|
|
$Menu/CLIBadge.sparkling = false
|
|
|
|
|
2021-01-07 12:57:31 +01:00
|
|
|
#if levels.chapters[game.current_chapter].levels[game.current_level].cards.size() == 0:
|
|
|
|
# cards.redraw_all_cards()
|
|
|
|
#else:
|
|
|
|
cards.draw(levels.chapters[game.current_chapter].levels[game.current_level].cards)
|
2020-09-04 14:57:37 +02:00
|
|
|
|
2020-09-30 21:36:11 +02:00
|
|
|
for r in repositories_node.get_children():
|
|
|
|
r.queue_free()
|
|
|
|
repositories = {}
|
|
|
|
|
2020-10-12 18:57:25 +02:00
|
|
|
var repo_names = level.repos.keys()
|
|
|
|
repo_names.invert()
|
|
|
|
|
|
|
|
for r in repo_names:
|
2020-09-30 21:36:11 +02:00
|
|
|
var repo = level.repos[r]
|
2020-10-26 19:15:47 +01:00
|
|
|
var new_repo = preload("res://scenes/repository.tscn").instance()
|
2020-09-30 21:36:11 +02:00
|
|
|
new_repo.path = repo.path
|
|
|
|
new_repo.label = repo.slug
|
|
|
|
new_repo.size_flags_horizontal = SIZE_EXPAND_FILL
|
2020-10-27 16:53:19 +01:00
|
|
|
new_repo.size_flags_vertical = SIZE_EXPAND_FILL
|
2020-10-27 17:38:41 +01:00
|
|
|
if new_repo.label == "yours":
|
2021-01-06 17:04:23 +01:00
|
|
|
file_browser.repository = new_repo
|
2020-10-27 17:32:41 +01:00
|
|
|
file_browser.update()
|
2020-09-30 21:36:11 +02:00
|
|
|
repositories_node.add_child(new_repo)
|
|
|
|
repositories[r] = new_repo
|
|
|
|
|
2020-10-12 19:00:51 +02:00
|
|
|
terminal.repository = repositories[repo_names[repo_names.size()-1]]
|
2020-09-14 15:35:30 +02:00
|
|
|
terminal.clear()
|
2020-10-22 16:19:22 +02:00
|
|
|
terminal.find_node("TextEditor").close()
|
2020-09-29 20:01:25 +02:00
|
|
|
|
2021-01-13 16:26:48 +01:00
|
|
|
update_repos()
|
2020-12-22 12:44:07 +01:00
|
|
|
|
2020-09-29 20:01:25 +02: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 18:05:25 +02:00
|
|
|
t.wait_time = 1
|
2020-09-29 20:01:25 +02:00
|
|
|
add_child(t)
|
|
|
|
t.start()
|
|
|
|
yield(t, "timeout")
|
2021-02-04 16:11:56 +01:00
|
|
|
AudioServer.set_bus_mute(AudioServer.get_bus_index("SFX"), false)
|
2020-09-29 20:01:25 +02:00
|
|
|
# FIXME: Need to clean these up when switching levels somehow.
|
2020-10-29 16:17:04 +01:00
|
|
|
|
2021-01-19 11:13:40 +01:00
|
|
|
# chapter_select.select(game.current_chapter)
|
|
|
|
# level_select.select(game.current_level)
|
2021-01-19 12:48:16 +01:00
|
|
|
#game.notify("These are your cards!", cards)
|
2020-09-10 12:47:18 +02:00
|
|
|
|
2020-09-13 21:55:24 +02:00
|
|
|
func reload_level():
|
2021-01-05 13:08:43 +01:00
|
|
|
cards.load_card_store()
|
2020-09-30 21:36:11 +02:00
|
|
|
levels.reload()
|
2020-12-23 12:01:07 +01:00
|
|
|
load_level(game.current_level)
|
2020-09-13 21:55:24 +02:00
|
|
|
|
2020-09-10 12:47:18 +02:00
|
|
|
func load_next_level():
|
2021-01-12 12:48:06 +01:00
|
|
|
game.current_level += 1
|
|
|
|
if game.current_level >= levels.chapters[game.current_chapter].levels.size():
|
|
|
|
|
|
|
|
back()
|
|
|
|
else:
|
|
|
|
load_level(game.current_level)
|
|
|
|
|
2020-09-10 12:03:46 +02:00
|
|
|
|
2020-12-22 12:44:07 +01:00
|
|
|
func show_win_status(win_states):
|
|
|
|
var all_won = true
|
|
|
|
var win_text = "\n\n"
|
2021-01-08 13:54:37 +01:00
|
|
|
for child in goals.get_children():
|
|
|
|
child.queue_free()
|
2020-12-22 12:44:07 +01:00
|
|
|
for state in win_states:
|
2021-01-08 13:54:37 +01:00
|
|
|
var b = Label.new()
|
|
|
|
b.text = state
|
|
|
|
b.align = HALIGN_LEFT
|
|
|
|
var bg = StyleBoxFlat.new()
|
|
|
|
if win_states[state]:
|
|
|
|
bg.bg_color = Color(0.1, 0.5, 0.1)
|
|
|
|
else:
|
|
|
|
bg.bg_color = Color(0.5, 0.1, 0.1)
|
|
|
|
bg.corner_radius_bottom_left = 8
|
|
|
|
bg.corner_radius_bottom_right = 8
|
|
|
|
bg.corner_radius_top_left = 8
|
|
|
|
bg.corner_radius_top_right = 8
|
|
|
|
bg.content_margin_bottom = 8
|
|
|
|
bg.content_margin_top = 8
|
|
|
|
bg.content_margin_left = 8
|
|
|
|
bg.content_margin_right = 8
|
|
|
|
b.set("custom_styles/normal", bg)
|
|
|
|
#b.connect("pressed", self, "load", [chapter_id, level_id])
|
|
|
|
#var slug = chapter.slug + "/" + level.slug
|
|
|
|
|
|
|
|
goals.add_child(b)
|
|
|
|
b.autowrap = true
|
2020-12-22 12:44:07 +01:00
|
|
|
if not win_states[state]:
|
|
|
|
all_won = false
|
2020-12-23 12:01:07 +01:00
|
|
|
var level = levels.chapters[game.current_chapter].levels[game.current_level]
|
2020-12-22 17:53:16 +01:00
|
|
|
level_description.bbcode_text = level.description[0] + win_text
|
|
|
|
for i in range(1,level.tipp_level+1):
|
|
|
|
level_description.bbcode_text += level.description[i]
|
2020-12-22 12:44:07 +01:00
|
|
|
|
|
|
|
if not level_congrats.visible and all_won and win_states.size() > 0:
|
2020-10-22 16:19:22 +02:00
|
|
|
next_level_button.show()
|
|
|
|
level_description.hide()
|
|
|
|
level_congrats.show()
|
|
|
|
$SuccessSound.play()
|
2021-01-07 11:36:11 +01:00
|
|
|
var slug = levels.chapters[game.current_chapter].slug + "/" + level.slug
|
|
|
|
if not slug in game.state["solved_levels"]:
|
|
|
|
game.state["solved_levels"].push_back(slug)
|
|
|
|
game.save_state()
|
2021-01-21 15:08:59 +01:00
|
|
|
if not game.used_cards and not slug in game.state["cli_badge"]:
|
|
|
|
game.state["cli_badge"].push_back(slug)
|
|
|
|
game.save_state()
|
2021-02-18 16:44:04 +01:00
|
|
|
$Menu/CLIBadge.active = true
|
2021-01-21 15:08:59 +01:00
|
|
|
$Menu/CLIBadge.sparkling = true
|
2020-09-15 16:31:41 +02:00
|
|
|
|
2021-01-19 11:13:40 +01:00
|
|
|
#func repopulate_levels():
|
|
|
|
# levels.reload()
|
|
|
|
# level_select.clear()
|
|
|
|
# for level in levels.chapters[game.current_chapter].levels:
|
|
|
|
# level_select.add_item(level.title)
|
|
|
|
# level_select.select(game.current_level)
|
2020-09-28 18:40:41 +02:00
|
|
|
|
2021-01-19 11:13:40 +01:00
|
|
|
#func repopulate_chapters():
|
|
|
|
# levels.reload()
|
|
|
|
# chapter_select.clear()
|
|
|
|
# for c in levels.chapters:
|
|
|
|
# chapter_select.add_item(c.slug)
|
|
|
|
# chapter_select.select(game.current_chapter)
|
2020-09-29 20:01:25 +02:00
|
|
|
|
2020-09-30 21:36:11 +02:00
|
|
|
func update_repos():
|
2020-12-23 12:01:07 +01:00
|
|
|
var win_states = levels.chapters[game.current_chapter].levels[game.current_level].check_win()
|
2020-12-22 17:52:15 +01:00
|
|
|
show_win_status(win_states)
|
|
|
|
|
2020-09-30 21:36:11 +02:00
|
|
|
for r in repositories:
|
|
|
|
var repo = repositories[r]
|
|
|
|
repo.update_everything()
|
2020-10-27 17:32:41 +01:00
|
|
|
file_browser.update()
|
2021-02-04 16:11:56 +01:00
|
|
|
|
|
|
|
input.grab_focus()
|
2020-10-14 14:52:29 +02:00
|
|
|
|
|
|
|
func toggle_cards():
|
|
|
|
cards.visible = not cards.visible
|
2020-12-22 17:53:16 +01:00
|
|
|
|
|
|
|
func new_tip():
|
2020-12-23 12:01:07 +01:00
|
|
|
var level = levels.chapters[game.current_chapter].levels[game.current_level]
|
2020-12-22 17:53:16 +01:00
|
|
|
if level.description.size() - 1 > level.tipp_level :
|
|
|
|
level.tipp_level += 1
|
|
|
|
level_description.bbcode_text += level.description[level.tipp_level]
|
2020-12-23 12:01:07 +01:00
|
|
|
|
|
|
|
func back():
|
|
|
|
get_tree().change_scene("res://scenes/level_select.tscn")
|