-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.gd
93 lines (63 loc) · 2.02 KB
/
Main.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
extends Control
@onready var _load_dialog: FileDialog = get_node("LoadDialog")
var _load_dialog_used: bool = false;
@onready var _tree: SceneTree = get_tree()
func _ready() -> void:
# Load or initialize preferences
Globals.preferences.load_(Preferences.P_PREFS)
# If an image has been loaded before, then default image is gone
Globals.tiles_default_image = true if Globals.preferences.last_image == "" else false
# Queue call to auto start if desired
call_deferred("check_auto_start")
func _unhandled_input(ev: InputEvent) -> void:
if ev.is_action_pressed("quit"):
accept_event()
quit()
elif ev.is_action_pressed("new"):
accept_event()
new_game()
elif ev.is_action_pressed("load"):
accept_event()
load_()
elif ev.is_action_pressed("prefs"):
accept_event()
prefs()
func _on_load_dialog_file_selected(path: String) -> void:
# Save path if different than last loaded game
if Globals.preferences.last_game != path:
Globals.preferences.last_game = path
Globals.preferences.save(Preferences.P_PREFS)
load_game(path)
func _on_load_pressed():
load_()
func _on_new_pressed():
new_game()
func _on_prefs_pressed():
prefs()
func _on_quit_pressed():
quit()
func check_auto_start() -> void:
if Globals.preferences.auto_load and not Globals.auto_started:
if FileAccess.file_exists(Globals.preferences.auto_path):
Globals.auto_started = true
load_game(Globals.preferences.auto_path)
func load_() -> void:
Globals.auto_started = false
if _load_dialog_used:
_load_dialog.popup()
else:
_load_dialog_used = true
if Globals.preferences.last_game != "":
_load_dialog.current_path = Globals.preferences.last_game
_load_dialog.popup_centered()
func load_game(path: String) -> void:
Globals.tiles_loading = true
Globals.tiles_load_path = path
_tree.change_scene_to_file("res://Game.tscn")
func new_game() -> void:
Globals.auto_started = false
_tree.change_scene_to_file("res://NewGame.tscn")
func prefs() -> void:
_tree.change_scene_to_file("res://Prefs.tscn")
func quit() -> void:
_tree.quit()