-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.gd
More file actions
337 lines (279 loc) · 9.48 KB
/
script.gd
File metadata and controls
337 lines (279 loc) · 9.48 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
extends Control
# Constants
const BLUR_STRENGTH_FACTOR = 10.0
const BLUR_MIX_FACTOR = 0.5
const MAX_RECENT_VIDEOS = 10
# State variables
var concentration_time_setting = 0
var inspection_time_setting = 0
var is_launched = false
var is_outro = false
var is_stopping = false
var is_paused = false
var has_water = false
var time_elapsed = 0.0
var next_inspection_duration = 0
var total_time = 0.0
var need_resume_animation = false
var need_resume_player = false
# Visual effects
@export var blur_alpha = 1.0
var prev_blur_alpha = 1.0
var blur_shader_material
# Video management
var video_paths = [
"res://vid/stare/0.ogv",
"res://vid/stare/1.ogv",
"res://vid/stare/2.ogv",
"res://vid/stare/3.ogv",
"res://vid/stare/4.ogv",
"res://vid/stare/5.ogv",
"res://vid/stare/6.ogv",
"res://vid/stare/7.ogv",
"res://vid/stare/8.ogv",
"res://vid/stare/9.ogv",
"res://vid/stare/10.ogv",
"res://vid/stare/11.ogv",
"res://vid/stare/12.ogv",
"res://vid/stare/13.ogv",
"res://vid/stare/14.ogv",
"res://vid/stare/15.ogv",
"res://vid/stare/16.ogv",
"res://vid/stare/17.ogv",
"res://vid/stare/18.ogv",
"res://vid/stare/19.ogv",
"res://vid/stare/20.ogv",
"res://vid/stare/21.ogv",
"res://vid/stare/22.ogv",
"res://vid/stare/23.ogv",
"res://vid/stare/24.ogv",
"res://vid/stare/25.ogv",
"res://vid/stare/26.ogv",
"res://vid/stare/27.ogv"
]
var recent_videos = []
var last_windowed_size: Vector2
var last_windowed_position: Vector2
func _ready() -> void:
blur_shader_material = $"%Blur".material as ShaderMaterial
last_windowed_size = get_window().size
last_windowed_position = get_window().position
func _process(delta: float) -> void:
if not(is_paused):
if is_launched:
total_time += delta
# Check if we need to start new inspection cycle
if not $"%Player".is_playing() and not $"%Animator".is_playing():
time_elapsed += delta
if total_time > concentration_time_setting * 60:
print("End!")
is_outro = true
reset_session()
$"%Skip".visible = true
$"%Player".stream = load("res://vid/outro.ogv")
$"%Player".play()
$"%Animator".play("in")
elif time_elapsed > next_inspection_duration:
time_elapsed = 0
var rand = randi_range(0, 7)
if rand == 0:
print("Water time!")
if not(has_water):
has_water = true
$"%Player".stream = load("res://vid/water/add" + str(randi_range(0, 2)) + ".ogv")
else:
has_water = false
$"%Player".stream = load("res://vid/water/delete" + str(randi_range(0, 2)) + ".ogv")
$"%Player".play()
$"%Animator".play("in")
else:
print("Inspection time! (" + str(rand) + ")")
play_random_video()
update_inspection_duration()
# Update blur effect if value changed
if prev_blur_alpha != blur_alpha:
blur_shader_material.set_shader_parameter("strength", blur_alpha * BLUR_STRENGTH_FACTOR)
blur_shader_material.set_shader_parameter("mix_percentage", blur_alpha * BLUR_MIX_FACTOR)
prev_blur_alpha = blur_alpha
# Update time
$"%Time".text = str(int((concentration_time_setting * 60 - total_time) / 60)) + ":" + str(int(concentration_time_setting * 60 - total_time) % 60).pad_zeros(2) + " "
$"%Time".visible = $"%ShowTime".button_pressed
# Debug output
if $"%Debug".visible:
var debug = "DEBUG:\nTime elapsed: " + str(snapped(time_elapsed, 0.01))
debug = debug + "\nNext inspection: " + str(next_inspection_duration)
debug = debug + "\nTime before inspection: " + str(snapped(next_inspection_duration - time_elapsed, 0.01))
debug = debug + "\nBlur alpha: " + str(snapped(blur_alpha, 0.01))
debug = debug + "\nTotal time elapsed: " + str(snapped(total_time, 0.01))
debug = debug + "\nTime before end: " + str(snapped(concentration_time_setting * 60 - total_time, 0.01))
debug = debug + "\nHas water: " + str(has_water)
debug = debug + "\nPlayer playing: " + str($"%Player".is_playing())
debug = debug + "\nAnimator playing: " + str($"%Animator".is_playing())
$"%Debug".text = debug
# When %Player is finished
# (I named it stupidly XD)
func _on_animation_end() -> void:
$"%Skip".visible = false # Hide the cutscene skip button
if is_outro:
# At the end of concentration
$"%Animator".play("ended")
is_outro = false
else:
$"%Animator".play("out")
# Opening links from copyright
func _on_copyright_meta_clicked(meta: Variant) -> void:
OS.shell_open(str(meta))
# Input validation for concentration time
func _on_concentration_changed(new_text: String) -> void:
var regex = RegEx.new()
regex.compile("[^0-9 ]")
var filtered = regex.sub(new_text, "", true)
if filtered != new_text:
$"%ConcetrationLineEdit".text = filtered
$"%ConcetrationLineEdit".caret_column = filtered.length()
# Input validation for inspection time
func _on_checks_text_changed(new_text: String) -> void:
var regex = RegEx.new()
regex.compile("[^0-9 ]")
var filtered = regex.sub(new_text, "", true)
if filtered != new_text:
$"%ChecksLineEdit".text = filtered
$"%ChecksLineEdit".caret_column = filtered.length()
# Launch button handler
func _on_launch_pressed() -> void:
# YOU SHALL NOT PASS!
if $"%Animator".is_playing():
return
# Validate inputs
var conc_text = $"%ConcetrationLineEdit".text
var check_text = $"%ChecksLineEdit".text
if conc_text.is_empty() or check_text.is_empty():
show_notification("Please fill in all fields correctly!")
return # Don't launch with empty inputs
# Parse and validate numbers
concentration_time_setting = conc_text.to_int()
inspection_time_setting = check_text.to_int()
if concentration_time_setting > 1440:
show_notification("Your concentration time is over 24 hours! You're not planning on working that much, are you?")
return # Don't launch
if inspection_time_setting / 60 > concentration_time_setting:
show_notification("You've indicated a check time longer than your concentration time! The officer will never inspect you :(")
return # Don't launch
if inspection_time_setting < 60:
show_notification("You've set too short a time for inspections! The officer will get so tired of walking back and forth.")
return # Don't launch
# Initialize inspection timer
update_inspection_duration()
# Start intro video
$"%Player".stream = load("res://vid/intro.ogv")
$"%Player".play()
$"%Animator".play("launched")
$"%Skip".visible = true
is_stopping = false
is_launched = true
print("Launched!")
# Update inspection duration with random variation
func update_inspection_duration() -> void:
# Random variation between -15s to +15s
var variation = randi_range(-15, 15)
next_inspection_duration = inspection_time_setting + variation
# Play random video from available options
func play_random_video() -> void:
# Find valid video (not in recent list)
var selected_path = ""
var attempts = 0
const MAX_ATTEMPTS = 10
while attempts < MAX_ATTEMPTS:
selected_path = video_paths[randi() % video_paths.size()]
if not recent_videos.has(selected_path):
break
attempts += 1
# Fallback if all videos in recent list
if attempts >= MAX_ATTEMPTS:
selected_path = video_paths[randi() % video_paths.size()]
# Update recent videos list
recent_videos.append(selected_path)
if recent_videos.size() > MAX_RECENT_VIDEOS:
recent_videos.pop_front()
# Play the selected video
$"%Player".stream = load(selected_path)
$"%Player".play()
$"%Animator".play("in")
# When %Animator is finished
func _on_animator_animation_finished(anim_name: StringName) -> void:
if anim_name == "launched":
$"%Player".play()
# When you press the pause button
func _on_pause_pressed() -> void:
if is_paused:
if need_resume_player:
$"%Player".paused = false
if need_resume_animation:
$"%Animator".play()
$"%Pause".text = "⏸️"
is_paused = false
else:
need_resume_player = false
need_resume_animation = false
if $"%Player".is_playing():
need_resume_player = true
$"%Player".paused = true
if $"%Animator".is_playing():
need_resume_animation = true
$"%Animator".pause()
$"%Pause".text = "⏺️"
is_paused = true
# When you press the stop button
func _on_stop_pressed() -> void:
# YOU SHALL NOT PASS!
if is_stopping:
return
if $"%Player".is_playing():
$"%Player".stop()
if $"%Animator".is_playing():
$"%Animator".stop()
is_outro = false
is_stopping = true
reset_session()
$"%Animator".play("ended")
# When you press the skip button
func _on_skip_pressed() -> void:
if $"%Player".is_playing():
$"%Player".stop()
_on_animation_end()
# Show notification at bottom left
func show_notification(text: String) -> void:
if ($"%NotificationAnimation".is_playing()):
$"%NotificationAnimation".stop()
$"%NotificationText".text = text
$"%NotificationAnimation".play("show")
# Reset all information
func reset_session():
is_launched = false
has_water = false
total_time = 0
concentration_time_setting = 0
inspection_time_setting = 0
time_elapsed = 0
next_inspection_duration = 0
blur_alpha = 0
func _on_about_application_pressed() -> void:
if $"%AboutApp".visible:
$"%AboutApp".visible = false
$"%AboutApp".popup_centered()
func _on_about_app_close_requested() -> void:
$"%AboutApp".visible = false
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("fullscreen"):
toggle_fullscreen()
func toggle_fullscreen():
var window = get_window()
var current_mode = window.get_mode()
if current_mode == Window.MODE_FULLSCREEN:
window.set_mode(Window.MODE_WINDOWED)
window.size = last_windowed_size
window.position = last_windowed_position
else:
last_windowed_size = window.size
last_windowed_position = window.position
window.set_mode(Window.MODE_FULLSCREEN)