-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerminalManager.gd
More file actions
450 lines (370 loc) · 14.5 KB
/
TerminalManager.gd
File metadata and controls
450 lines (370 loc) · 14.5 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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
extends Control
var terminals : Array = []
var term_idx : int = 0
var texture_path : String = ""
enum States{
UNFINISHED,
FINISHED,
SUCCESS,
FAILURE
}
# Input file format :
# Terminal Blocks
# The number for the terminal being currently defined is set with the #TERMINAL and #ENDTERMINAL commands. These are formed as:
# #TERMINAL number
# #ENDTERMINAL number
# For example, defining a terminal numbered "1" would be:
# #TERMINAL 1
# ; terminal's contents here
# #ENDTERMINAL 1
# Sections
# There are four possible sections in a terminal, which are between the #TERMINAL and #ENDTERMINAL blocks:
# #UNFINISHED
# #FINISHED
# #FAILURE
# #SUCCESS
# These all mark the start of where the terminal will display, depending on the current status of your mission.
# Name Will display when
# UNFINISHED your objective has not been met or no other block exists
# FINISHED you have succeeded or failed
# FAILURE you have failed your objective
# SUCCESS you have succeeded in your objective
# Sections must have an end, which is defined with:
# #END
# Between sections may be any amount of regular commands. There are two kinds of these normal commands: Text commands, and interactive commands.
# Text Commands
# All text commands may have (but do not require) text following them, which may be formatted.
# Line breaks will break in-game, but unbroken lines will automatically wrap. It is generally best to just put all of your text onto one line, even if this destroys your sanity. Use a text editor with line wrapping for this.
# Example:
# #PICT 10007
# ~text interface terminal malfunction error ~2992dud
# welcome to mabmap i am durandal the most pretty ai in ever i made the pfhor ded and won all the everything you should go shoot some things I put here because reasons
# Formatting
# Text effects are designated by a '$' and then one of the following:
# $-code Effect
# I/i enables/disables italic text
# B/b enables/disables bold text
# U/u enables/disables underlined text
# Cn changes the text color, where "n" is a number 0 through 9
# For more information on colors, see section ENUMERATIONS, Terminal Color.
# Example:
# $C1$BoOooO$IooOOoo$i$b$C0 ... $C6did I $Uspook$u you?$C0
# Text Command Overview
# Text commands include:
# #PICT pict_id alignment
# #LOGON pict_id
# #LOGOFF pict_id
# #INFORMATION
# #CHECKPOINT goal_id
# #BRIEFING level_number
# #PICT
# #PICT pict_id alignment
# #PICT is the most basic and most used command throughout M2 and Infinity.
# It displays a picture to the specified alignment and text to the other side.
# It will:
# Wait for input before proceeding.
# Display 45 characters per line, and display up to 22 lines on one page.
# Display text aligned to the left on the right side of the screen.
# If alignment is specified as RIGHT, text is aligned to the right on the left of the screen. If alignment is specified as CENTER, no text may be displayed, only an image. If no alignment is specified, it will default to an image on the left and text on the right.
# Example:
# #PICT 10007
# ~text interface terminal malfunction error ~2992dud
# hellote this is example text from durnadle prettiest ai in ever thank u for reading goodbye
# #LOGON, #LOGOFF
# #LOGON pict_id
# #LOGOFF pict_id
# #LOGON and #LOGOFF are generally used first and last in a terminal.
# These two display a PICT in the middle of the screen and text below the image if you supply it. They both do things to the screen borders.
# They will:
# Automatically continue, an input will interrupt it.
# Only display one line of text, at most 72 characters.
# Display text aligned to the center in the middle of the screen.
# Example:
# #LOGON 1600
# <CMND PRAMA &681g1>
# ; ... content ...
# #LOGOFF 1600
# ehhg.431.4122//<PFGR ZNE6 &49c2>
# #INFORMATION
# #INFORMATION
# #INFORMATION will just display text, and is mostly used in Marathon 1.
# It will:
# Wait for input before proceeding.
# Display 72 characters per line, and display up to 22 lines on one page.
# Display text aligned to the left on the left side of the screen.
# Example:
# #INFORMATION
# you suck at videogames love durandal
# p.s. if you don't win i'm erasing your home planet from existence
# #CHECKPOINT
# #CHECKPOINT goal_id
# #CHECKPOINT may only be used in M1, unless you're using Aleph One 1.1+.
# This shows a map centered on the specified goal point, with the goal circled, on the left of the screen.
# The map will only show polygons connected to the polygon the goal is in, so if you have a separated area where the goal point is, it will only display that. It will also not display secret areas and any polygons proceding them.
# It will:
# Wait for input before proceeding.
# Display 45 characters per line, and display up to 22 lines on one page.
# Display text aligned to the left on the right side of the screen.
# Example:
# #CHECKPOINT 7
# go shoot these things so i can claim this victory as mine forever and tell you about the things that i totally shot for approximately 200 years
# #BRIEFING
# #BRIEFING level_number
# BRIEFING may only be used in Marathon 1. It is identical to INFORMATION, but after you're done reading, it will teleport you to the specified level.
# Interactive Commands
# Interactive commands are all actions carried out by the game that do not all effect the active terminal.
# Interactive Command Overview
# Interactive commands include:
# #INTERLEVEL TELEPORT level_number
# #INTRALEVEL TELEPORT polygon_tag
# #TAG tag
# #SOUND sound_number
# #STATIC duration
# #INTERLEVEL TELEPORT
# #INTERLEVEL TELEPORT level_number
# #INTERLEVEL TELEPORT exits the terminal and teleports you to the specified level. If the level number is "256", this ends the game.
# Example:
# #INTERLEVEL TELEPORT 7
# #INTRALEVEL TELEPORT
# #INTRALEVEL TELEPORT polygon_tag
# #INTRALEVEL TELEPORT exits the terminal and teleports you to the centroid of the specified polygon within the map.
# Example:
# #INTRALEVEL TELEPORT 77
# #TAG
# #TAG tag
# #TAG activates all lights and platforms with the specified tag.
# Example:
# #TAG 77
# #SOUND
# #SOUND sound_number
# #SOUND plays the specified sound from the Sounds file or from the Scenario/Map file.
# Example:
# #SOUND 77
# #STATIC
# #STATIC duration
# #STATIC fills the terminal with TV static for the specified duration in 1/30ths seconds. Aleph One only.
# Example:
# #STATIC 60
@export_file("*.txt") var terminal_file : String = "res://respict/terminals.txt"
# Output file format :
# {
# "level_name" : "Level 1",
# "terminals" : [
# [
# {
# "UNFINISHED" :[{ # can be UNFINISHED, FINISHED, SUCCESS, FAILURE
# "mode" : "right", #left, right, logon, logoff, information, unfinished, finished, success, failure
# "text" : "Hello World",
# "image" : "res://icon.png",
# "command" : "INTERLEVEL TELEPORT", # can be INTERLEVEL TELEPORT, INTRALEVEL TELEPORT, SOUND, STATIC
# },
# {
# "mode" : "right", #left, right, logon, logoff, information, unfinished, finished, success, failure
# "text" : "Hello World",
# "image" : "res://icon.png",
# "command" : "INTERLEVEL TELEPORT", # can be INTERLEVEL TELEPORT, INTRALEVEL TELEPORT, SOUND, STATIC
# }...
# ],
# [
# {
# "mode" : "right", #left, right, logon, logoff, information, unfinished, finished, success, failure
# "text" : "Hello World",
# "image" : "res://icon.png",
# "command" : "INTERLEVEL TELEPORT", # can be INTERLEVEL TELEPORT, INTRALEVEL TELEPORT, SOUND, STATIC
# },
# {
# "mode" : "right", #left, right, logon, logoff, information, unfinished, finished, success, failure
# "text" : "Hello World",
# "image" : "res://icon.png",
# "command" : "INTERLEVEL TELEPORT", # can be INTERLEVEL TELEPORT, INTRALEVEL TELEPORT, SOUND, STATIC
# }...
# ]
# ]
# ],
# "FINISHED" : [{
# "mode" : "right", #left, right, logon, logoff, information, unfinished, finished, success, failure
# "text" : "Hello World",
# "image" : "res://icon.png",
# "command" : "INTERLEVEL TELEPORT", # can be INTERLEVEL TELEPORT, INTRALEVEL TELEPORT, SOUND, STATIC
# },
#...
# ],...
# }
func _ready():
load_terminals()
display_terminals(States.UNFINISHED)
get_node("%Content").display_page()
func load_terminals():
var file = FileAccess.open(terminal_file, FileAccess.READ)
if file:
var content = file.get_as_text()
file.close()
content = content.replace("#ENDTERMINAL", "#NDTERM") #Replace #ENDTERMINAL with #NDTERM to split the terminal blocks
var terminal_blocks = content.split("#TERMINAL")
for terminal in terminal_blocks:
var terminal_dict = {
"UNFINISHED" : [],
"FINISHED" : [],
"SUCCESS" : [],
"FAILURE" : []
}
# We define a block as a section of the terminal that is either UNFINISHED, FINISHED, SUCCESS, FAILURE
# it starts with the block name and ends with #END
for block in terminal.split("#END"):
var block_name = ""
for line in block.split("\n"):
if line.find("#UNFINISHED")!=-1:
block_name = "UNFINISHED"
elif line.find("#FINISHED")!=-1:
block_name = "FINISHED"
elif line.find("#SUCCESS")!=-1:
block_name = "SUCCESS"
elif line.find("#FAILURE")!=-1:
block_name = "FAILURE"
if block_name != "":
#Split terminal into pages, determine type of page and respect the limits of the page
#as per the terminal format
# Pages are determined by the #PICT, #LOGON, #LOGOFF, #INFORMATION, #CHECKPOINT, #BRIEFING
# commands and how many lines they can display per page and how many characters per line
# #PICT, #CHECKPOINT, can display 45 characters per line and 22 lines per page, includes image
# #LOGON, #LOGOFF can display 72 characters per line and 1 line per page, includes image
# #INFORMATION, #BRIEFING can display 72 characters per line and 22 lines per page, no image
var pages = []
var page_dict = {
"mode" : "",
"text" : "",
"image" : "",
"command" : "",
"arg" : ""
}
for line in block.split("\n"):
if page_dict["mode"] != "" and (line.find("#PICT")!=-1 or line.find("#LOGON")!=-1 or line.find("#LOGOFF")!=-1 or line.find("#INFORMATION")!=-1 or line.find("#CHECKPOINT")!=-1 or line.find("#BRIEFING")!=-1):
pages.append(page_dict)
print("Page added", page_dict)
page_dict = {
"mode" : "",
"text" : "",
"image" : "",
"command" : "",
"arg" : ""
}
if line.find("#PICT")!=-1:
if line.find("RIGHT")!=-1:
page_dict["mode"] = "right"
page_dict["mode"] = "left"
page_dict["image"] = use_texture_set(line.split(" ")[1])
elif line.find("#LOGON")!=-1:
page_dict["mode"] = "logon"
page_dict["image"] = use_texture_set(line.split(" ")[1])
elif line.find("#LOGOFF")!=-1:
page_dict["mode"] = "logoff"
page_dict["image"] = use_texture_set(line.split(" ")[1])
elif line.find("#INFORMATION")!=-1:
page_dict["mode"] = "information"
page_dict["image"] = ""
elif line.find("#CHECKPOINT")!=-1:
page_dict["mode"] = "left"
page_dict["image"] = ""
elif line.find("#BRIEFING")!=-1:
page_dict["mode"] = "information"
page_dict["image"] = ""
page_dict["command"] = "INTERLEVEL TELEPORT"
page_dict["arg"] = line.split(" ")[1]
elif line.find("#NDTERM")!=-1:
pass
elif line.begins_with(";"):
#Do nothing, just a comment
pass
else:
if page_dict["mode"] == "right" or page_dict["mode"] == "left":
if len(page_dict["text"]) > 45*22:
pages.append(page_dict)
page_dict = {
"mode" : page_dict["mode"], #Use the same mode as the previous page if the text is too long
"text" : "",
"image" : "",
"command" : "",
"arg" : ""
}
page_dict["text"] += line + "\n"
elif page_dict["mode"] == "information":
if len(page_dict["text"]) > 72*22:
pages.append(page_dict)
page_dict = {
"mode" : page_dict["mode"], #Use the same mode as the previous page if the text is too long
"text" : "",
"image" : "",
"command" : "",
"arg" : ""
}
page_dict["text"] += line + "\n"
elif page_dict["mode"] == "logon" or page_dict["mode"] == "logoff":
if len(page_dict["text"]) > 72:
pages.append(page_dict)
page_dict = {
"mode" : page_dict["mode"], #Use the same mode as the previous page if the text is too long
"text" : "",
"image" : "",
"command" : "",
"arg" : ""
}
page_dict["text"] += line + "\n"
if page_dict["mode"] != "":
pages.append(page_dict)
terminal_dict[block_name].append(pages)
terminals.append(terminal_dict)
term_idx = 0
for term in terminals:
if term["UNFINISHED"].size() < 1 and term["FINISHED"].size() < 1 and term["SUCCESS"].size() < 1 and term["FAILURE"].size() < 1:
terminals.erase(term)
func display_terminals(state : int):
term_idx = 0
var state_text = ""
match state:
States.UNFINISHED:
state_text = "UNFINISHED"
States.FINISHED:
state_text = "FINISHED"
States.SUCCESS:
state_text = "SUCCESS"
States.FAILURE:
state_text = "FAILURE"
print(terminals)
get_node("%Content").load_terminals(terminals[term_idx][state_text])
get_node("%Content").display_terminal(term_idx)
func use_texture_set(pic_name : String):
var new_pic_name = int(pic_name)
if new_pic_name < 10:
new_pic_name = "00000"+str(new_pic_name)
elif new_pic_name < 100:
new_pic_name = "0000"+str(new_pic_name)
elif new_pic_name < 1000:
new_pic_name = "00"+str(new_pic_name)
elif new_pic_name < 10000:
new_pic_name = "0"+str(new_pic_name)
return "res://respict/MARATHON/"+str(new_pic_name)+".png"
func _input(_event):
#press right arrow key to go to next terminal
if Input.is_action_pressed("ui_right"):
_on_Next_pressed()
#press left arrow key to go to previous terminal
if Input.is_action_pressed("ui_left"):
_on_Prev_pressed()
func _on_Prev_pressed():
get_node("%Content").previous_page()
get_node("%Content").display_page()
func _on_Next_pressed():
get_node("%Content").next_page()
get_node("%Content").display_page()
func _on_Prev_term_pressed():
if term_idx > 0:
term_idx-=1
get_node("%Content").display_terminal(term_idx)
func _on_Next_term_pressed():
if term_idx < terminals.size()-1:
term_idx+=1
get_node("%Content").display_terminal(term_idx)
func _on_Prev_scale_pressed():
$CenterContainer.scale /= 1.2
func _on_Next_scale_pressed():
$CenterContainer.scale *= 1.2