oh-my-git/scenes/main.gd

187 lines
5.8 KiB
GDScript3
Raw Normal View History

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
var repositories = {}
2020-10-27 17:32:41 +01:00
onready var level_select = $Rows/Columns/RightSide/LevelInfo/Menu/LevelSelect
onready var chapter_select = $Rows/Columns/RightSide/LevelInfo/Menu/ChapterSelect
onready var next_level_button = $Rows/Columns/RightSide/LevelInfo/Menu/NextLevelButton
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
2020-09-01 21:25:24 +02:00
var _hint_server
var _hint_client_connection
2020-03-18 15:23:38 +01:00
func _ready():
_hint_server = TCP_Server.new()
_hint_server.listen(1235)
var args = helpers.parse_args()
if args.has("sandbox"):
var err = get_tree().change_scene("res://scenes/sandbox.tscn")
if err != OK:
helpers.crash("Could not change to sandbox scene")
return
2020-09-04 14:57:37 +02:00
# Initialize level select.
level_select.connect("item_selected", self, "load_level")
repopulate_levels()
level_select.select(game.current_level)
2020-09-04 14:57:37 +02:00
2020-09-28 18:40:41 +02: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
# Load current level.
load_level(game.current_level)
2020-09-04 14:57:37 +02:00
input.grab_focus()
func _process(delta):
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)
2020-09-28 18:40:41 +02:00
func load_chapter(id):
game.current_chapter = id
repopulate_levels()
load_level(0)
2020-09-28 18:40:41 +02:00
2020-09-29 19:40:17 +02:00
func load_level(level_id):
next_level_button.hide()
level_congrats.hide()
level_description.show()
game.current_level = level_id
2020-09-04 14:57:37 +02:00
AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), true)
levels.chapters[game.current_chapter].levels[game.current_level].construct()
2020-09-29 19:40:17 +02: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
level_name.text = level.title
#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
for r in repositories_node.get_children():
r.queue_free()
repositories = {}
var repo_names = level.repos.keys()
repo_names.invert()
for r in repo_names:
var repo = level.repos[r]
var new_repo = preload("res://scenes/repository.tscn").instance()
new_repo.path = repo.path
new_repo.label = repo.slug
new_repo.size_flags_horizontal = SIZE_EXPAND_FILL
new_repo.size_flags_vertical = SIZE_EXPAND_FILL
2020-10-27 17:38:41 +01:00
if new_repo.label == "yours":
file_browser.repository = new_repo
2020-10-27 17:32:41 +01:00
file_browser.update()
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]]
terminal.clear()
2020-10-22 16:19:22 +02:00
terminal.find_node("TextEditor").close()
2020-12-22 12:44:07 +01:00
update_repos()
# Unmute the audio after a while, so that player can hear pop sounds for
# nodes they create.
var t = Timer.new()
t.wait_time = 1
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-10-29 16:17:04 +01:00
chapter_select.select(game.current_chapter)
level_select.select(game.current_level)
2020-12-22 12:44:07 +01:00
2020-09-13 21:55:24 +02:00
func reload_level():
cards.load_card_store()
levels.reload()
load_level(game.current_level)
2020-09-13 21:55:24 +02:00
func load_next_level():
game.current_level = (game.current_level + 1) % levels.chapters[game.current_chapter].levels.size()
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"
for state in win_states:
win_text += "%s: %s\n" % [state, win_states[state]]
if not win_states[state]:
all_won = false
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
if not game.state.has("solved_levels"):
game.state["solved_levels"] = []
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()
func repopulate_levels():
2020-09-29 19:40:17 +02:00
levels.reload()
level_select.clear()
for level in levels.chapters[game.current_chapter].levels:
2020-10-29 16:17:04 +01:00
level_select.add_item(level.title)
level_select.select(game.current_level)
2020-09-28 18:40:41 +02:00
func repopulate_chapters():
2020-09-29 19:40:17 +02:00
levels.reload()
chapter_select.clear()
2020-09-29 19:40:17 +02:00
for c in levels.chapters:
chapter_select.add_item(c.slug)
chapter_select.select(game.current_chapter)
func update_repos():
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)
for r in repositories:
var repo = repositories[r]
repo.update_everything()
2020-10-27 17:32:41 +01:00
file_browser.update()
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():
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]
func back():
get_tree().change_scene("res://scenes/level_select.tscn")