-
Notifications
You must be signed in to change notification settings - Fork 0
/
title.gd
104 lines (74 loc) · 2.52 KB
/
title.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
extends Node
const MAX_STARS = 15
const FILE_DIALOG_SIZE = Vector2(600,400)
const CLASSIC_MANIFEST = "res://levels/classic/manifest.json"
# Called when the node enters the scene tree for the first time.
func _ready():
if not OS.has_feature("web"):
$CanvasLayer/PanelContainer/MarginContainer/VBoxContainer/MainButtons/Quit.show()
var classic_progress = Saving.get_level_completion("classic")
if classic_progress.has("1-5"):
%Stars/Star1.show()
var total_coins = 0
for lvl in classic_progress.values():
for coin in lvl:
if coin:
total_coins += 1
if total_coins >= MAX_STARS * 0.5:
%Stars/Star2.show()
if total_coins >= MAX_STARS:
%Stars/Star3.show()
$Level.load_level("res://levels/title/1-title.lvl")
var manifests = Saving.get_all_files("res://levels", "manifest.json")
manifests.append_array(Saving.get_all_files("user://", "manifest.json"))
for m in manifests:
if m!=CLASSIC_MANIFEST:
var loaded = Globals.load_manifest(m)
var button = Button.new()
button.text = loaded.name
%BonusOptions.add_child(button)
%BonusOptions.move_child(button, 0)
button.pressed.connect(load_manifest.bind(m))
func load_manifest(path: String):
var manifest = Globals.load_manifest(path)
if manifest.mode == "classic":
if Saving.get_level_completion(manifest.id).size():
%MainButtons.hide()
%BonusOptions.hide()
%GameOptions.show()
else:
_on_from_start_pressed()
elif manifest.mode == "bonus":
_on_level_select_pressed()
func _on_editor_pressed():
Globals.current_level = null
get_tree().change_scene_to_file("res://editor.tscn")
func _on_classic_pressed():
load_manifest(CLASSIC_MANIFEST)
func _on_credits_pressed():
get_tree().change_scene_to_file("res://ui/credits.tscn")
func _on_level_select_pressed():
await $Level.fade_out()
get_tree().change_scene_to_file("res://ui/level_select/level_select.tscn")
func _on_from_start_pressed():
Globals.start_game(Globals.GAME_MODE.CLASSIC)
func _on_bonus_levels_pressed():
%MainButtons.hide()
%BonusOptions.show()
func _on_load_level_pressed():
$CanvasLayer/LoadLevelDialog.popup_centered(FILE_DIALOG_SIZE)
func _on_load_level_dialog_file_selected(path):
Globals.clear_manifest()
Globals.current_level = path
Globals.start_game(Globals.GAME_MODE.SINGLE_STAGE)
func _on_bonus_back_pressed():
%MainButtons.show()
%BonusOptions.hide()
func _on_options_pressed():
%MainButtons.hide()
%ActualOptions.show()
func _on_actual_options_confirmed():
%MainButtons.show()
%ActualOptions.hide()
func _on_quit_pressed():
get_tree().quit()