-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.gd
executable file
·154 lines (121 loc) · 3.46 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
var vm
var telon
var menu_layer
var wait_timer
var wait_level
var current
var menu_stack = []
var vm_size = Vector2(0, 0)
var game_size
var screen_ofs = Vector2(0, 0)
func set_input_catch(p_catch):
telon.set_input_catch(p_catch)
func clear_scene():
if current == null:
return
var root = get_tree().get_root()
root.remove_child(current)
current.free()
current = null
func set_scene(p_scene):
if current != null:
clear_scene()
if !p_scene:
return
var root = get_tree().get_root()
root.add_child(p_scene)
set_current_scene(p_scene)
func get_current_scene():
return current
func menu_open(menu):
menu_stack.push_back(menu)
if menu_stack.size() == 1:
get_tree().call_group(0, "game", "menu_opened")
vm.set_pause(true)
#get_tree().set_pause(true)
pass
func menu_close(p_menu):
if menu_stack.size() == 0 || menu_stack[menu_stack.size()-1] != p_menu:
print("***** warning! closing unknown menu?")
menu_stack.remove(menu_stack.size() - 1)
if menu_stack.size() == 0:
vm.set_pause(false)
get_tree().call_group(0, "game", "menu_closed")
#get_tree().set_pause(false)
pass
func load_menu(path):
if path == "":
printt("error: loading empty menu")
return
var menu = load(path)
if menu == null:
printt("error loading menu ", path)
return
printt("************* loding menu ", path, menu)
menu = menu.instance()
menu_layer.add_child(menu)
return menu
func menu_collapse():
var i = menu_stack.size()
while i > 0:
i -= 1
menu_stack[i].menu_collapsed()
func set_current_scene(p_scene):
#print_stack()
current = p_scene
var root = get_tree().get_root()
root.move_child(p_scene, 0)
func wait_finished():
vm.finished(wait_level)
func wait(time, level):
wait_level = level
wait_timer.set_wait_time(time)
wait_timer.set_one_shot(true)
wait_timer.start()
func check_screen():
var vs = OS.get_video_mode_size()
if vs == vm_size:
return
vm_size = vs
var rate = float(vs.x)/float(vs.y)
var height = int(game_size.x / rate)
get_tree().get_root().set_size_override(true,Vector2(game_size.x,height))
get_tree().get_root().set_size_override_stretch(true)
var m = Matrix32()
var ofs = Vector2(0, (height - game_size.y) / 2)
m[2] = ofs
get_tree().get_root().set_global_canvas_transform(m)
screen_ofs = ofs
printt("**** screen ofs is ", screen_ofs)
#get_tree().set_auto_accept_quit(false)
get_tree().call_group(0, "game", "set_camera_limits")
func _process(time):
check_screen()
func _input(event):
if (event.type==InputEvent.KEY and event.pressed and event.control and event.scancode==KEY_F12):
OS.print_all_textures_by_size()
if menu_stack.size() > 0:
menu_stack[menu_stack.size() - 1].input(event)
elif current != null:
if current.has_node("game"):
current.get_node("game").scene_input(event)
func load_telon():
var tpath = Globals.get("platform/telon")
var tres = vm.res_cache.get_resource(tpath)
get_node("layers/telon/telon").replace_by_instance(tres)
telon = get_node("layers/telon/telon")
func _ready():
printt("main ready")
get_node("/root").set_render_target_clear_on_new_frame(true)
game_size = Vector2()
game_size.x = Globals.get("display/game_width")
game_size.y = Globals.get("display/game_height")
vm = get_tree().get_root().get_node("vm")
wait_timer = get_node("layers/wait_timer")
wait_timer.connect("timeout", self, "wait_finished")
add_to_group("game")
menu_layer = get_node("layers/menu")
set_process_input(true)
set_process(true)
Globals.load_resource_pack("res://scripts.zip")
call_deferred("load_telon")