-
Notifications
You must be signed in to change notification settings - Fork 8
/
global.gd
192 lines (147 loc) · 5.52 KB
/
global.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
extends Node
var survived = false
var camera_is_shaking = false
var overload_timer = Timer.new()
var current_scene = null
signal code_binder_acquired
signal code_page_acquired
signal planet_database_acquired
signal tablet_acquired
signal shake_camera (intensity, is_final)
signal gameplay_started
signal player_died
signal player_escaped
signal escape_door_available
signal start_opening_escape_door
signal escape_door_open
# These signals continue to disappear from normal scenes (bug), co I've put them here
signal drawer_unlocked
signal power_panel_unlocked
signal emergency_screen_closed
# Settings flags
onready var env = load(ProjectSettings.get_setting('rendering/environment/default_environment'))
const settings_file_path = "user://Intrepid_settings.cfg"
var settings_file = null
var shadows_enabled = true
var fullscreen_enabled = true
var glow_enabled = true
var reflections_enabled = true
var music_volume = 0
var effects_volume = 0
var mouse_sensitivity = 0.3
signal mouse_sensitivity_changed (value)
signal music_volume_changed (value)
signal effects_volume_changed (value)
signal fullscreen_changed (value)
signal glow_changed (value)
signal reflections_changed (value)
signal shadows_changed (value)
func _ready():
var root = get_tree().get_root()
current_scene = root.get_child(root.get_child_count() -1)
overload_timer.wait_time = 60 * 60
overload_timer.one_shot = true
overload_timer.autostart = false
add_child(overload_timer)
connect('shake_camera', global, 'disable_player_interaction')
connect('gameplay_started', global, 'start_overload_timer')
connect('escape_door_available', global, 'stop_overload_timer')
connect('mouse_sensitivity_changed', global, '_on_mouse_sensitivity_changed')
connect('music_volume_changed', global, '_on_music_volume_changed')
connect('effects_volume_changed', global, '_on_effects_volume_changed')
connect('fullscreen_changed', global, '_on_fullscreen_changed')
connect('glow_changed', global, '_on_glow_changed')
connect('reflections_changed', global, '_on_reflections_changed')
connect('shadows_changed', global, '_on_shadows_changed')
settings_file = ConfigFile.new()
var err = settings_file.load(settings_file_path)
if err != OK:
print('Settings file not found!')
fullscreen_enabled = settings_file.get_value('graphics', 'fullscreen', true)
glow_enabled = settings_file.get_value('graphics', 'glow', true)
reflections_enabled = settings_file.get_value('graphics', 'reflections', true)
shadows_enabled = settings_file.get_value('graphics', 'shadows', true)
music_volume = settings_file.get_value('sound', 'music', 0)
effects_volume = settings_file.get_value('sound', 'effects', 0)
mouse_sensitivity = settings_file.get_value('controls', 'mouse_sensitivity', 0.3)
if err != OK:
save_settings()
_on_fullscreen_changed(fullscreen_enabled)
_on_glow_changed(glow_enabled)
_on_reflections_changed(reflections_enabled)
_on_music_volume_changed(music_volume)
_on_effects_volume_changed(effects_volume)
_on_mouse_sensitivity_changed(mouse_sensitivity)
func save_settings():
settings_file.set_value('graphics', 'fullscreen', fullscreen_enabled)
settings_file.set_value('graphics', 'glow', glow_enabled)
settings_file.set_value('graphics', 'reflections', reflections_enabled)
settings_file.set_value('graphics', 'shadows', shadows_enabled)
settings_file.set_value('sound', 'music', music_volume)
settings_file.set_value('sound', 'effects', effects_volume)
settings_file.set_value('controls', 'mouse_sensitivity', mouse_sensitivity)
settings_file.save(settings_file_path)
func _on_mouse_sensitivity_changed(value):
mouse_sensitivity = value
save_settings()
func _on_music_volume_changed(value):
var bus_id = AudioServer.get_bus_index('Music')
AudioServer.set_bus_volume_db(bus_id, value)
music_volume = value
save_settings()
func _on_effects_volume_changed(value):
var bus_id = AudioServer.get_bus_index('Effects')
AudioServer.set_bus_volume_db(bus_id, value)
effects_volume = value
save_settings()
func _on_shadows_changed(value):
shadows_enabled = value
var lamps = get_tree().get_nodes_in_group('lamps')
for lamp in lamps:
lamp.shadow_enabled = shadows_enabled
lamp.light_specular = 0.5 if shadows_enabled else 0.0
save_settings()
func _on_glow_changed(value):
glow_enabled = value
env.glow_enabled = glow_enabled
save_settings()
func _on_reflections_changed(value):
reflections_enabled = value
env.ss_reflections_enabled = reflections_enabled
save_settings()
func _on_fullscreen_changed(value):
fullscreen_enabled = value
OS.window_fullscreen = fullscreen_enabled
if not OS.window_fullscreen:
OS.window_size = Vector2(
ProjectSettings.get_setting('display/window/size/width'),
ProjectSettings.get_setting('display/window/size/height')
)
save_settings()
func disable_player_interaction(intensity, is_final):
camera_is_shaking = true
var popups = get_tree().get_nodes_in_group('popups')
var popups_visible = false
for popup in popups:
if popup.visible:
popups_visible = true
break
if popups_visible:
for popup in popups:
popup.hide_with_cursor()
func start_overload_timer(camera):
overload_timer.start()
func stop_overload_timer():
overload_timer.stop()
func hide_all_popups():
var popups = get_tree().get_nodes_in_group('popups')
for popup in popups:
popup.hide()
func goto_scene(path):
call_deferred('_deferred_goto_scene', path)
func _deferred_goto_scene(path):
current_scene.free()
var s = ResourceLoader.load(path)
current_scene = s.instance()
get_tree().get_root().add_child(current_scene)
get_tree().set_current_scene(current_scene)