-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartup.gd
356 lines (295 loc) · 11 KB
/
Startup.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
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
extends CanvasLayer
# Declare member variables
var twitch_url: String
var config_ = Config.new()
var node_triggered_new_line = {}
var file_path: String
var word_file: bool
# Called when the node enters the scene tree for the first time.
func _ready():
if File.new().file_exists("user://config.tres"):
get_tree().change_scene("res://Main.tscn")
return
$HTTPRequest.connect("request_completed", self, "_on_request_completed")
# just so pressing an inline url works
func _on_RichTextLabel_meta_clicked(meta):
# `meta` is not guaranteed to be a String, so convert it to a String
# to avoid script errors at run-time.
OS.shell_open(str(meta))
# continue button for the first three slides
func _on_Continue_pressed():
var children = $Panel.get_children()
for child_index in children.size():
if children[child_index].visible:
children[child_index].visible = false
children[child_index + 1].visible = true
return
# second slide
func _on_Submit_pressed():
config_.url = $Panel/Server_URL.text
if not ("http://" in $Panel/Server_URL.text or "https://" in $Panel/Server_URL.text):
config_.url = "http://" + config_.url
var local_url = config_.url
if not "/setup" in $Panel/Server_URL.text:
local_url = local_url + "/setup"
else:
config_.url = config_.url.trim_suffix("/setup")
$HTTPRequest.request(local_url + "?client_key=" + $Panel/Server_URL/Key.text)
func _on_request_completed(result, response_code, headers, body):
var json = JSON.parse(body.get_string_from_utf8())
if json.error:
$ErrorDialog.dialog_text = "The server did not return a json response. Are you sure you entered the correct URL?"
$ErrorDialog.popup()
return
if response_code != 200:
$ErrorDialog.dialog_text = $ErrorDialog.dialog_text + json.result["description"]
$ErrorDialog.popup()
return
if not json.result["version"].begins_with("0.0"):
$ErrorDialog.dialog_text = "The server is on a higher version than this client. Please update this client."
$ErrorDialog.popup()
return
config_.client_key = $Panel/Server_URL/Key.text
$Panel/Server_URL/Label.visible = true
$Panel/Server_URL/Button.disabled = false
func _on_text_entered(_new_text):
_on_Submit_pressed()
func _on_ErrorDialog_popup_hide():
$ErrorDialog.dialog_text = "The server returned the following error:\n\n"
# fourth slide
func _on_BuildHangman_toggled(button_pressed):
if button_pressed:
$Panel/TypeHangman/GuessHangman.pressed = false
func _on_GuessHangman_toggled(button_pressed):
if button_pressed:
$Panel/TypeHangman/BuildHangman.pressed = false
func _on_ContinueType_pressed():
$Panel/TypeHangman.visible = false
if $Panel/TypeHangman/BuildHangman.pressed:
$Panel/AmountGuesses.visible = true
config_.build_hangman = true
else:
$Panel/WordSource.visible = true
config_.build_hangman = false
# fifth slide
func _on_RandomWords_toggled(button_pressed):
if button_pressed:
$Panel/WordSource/OwnWords.pressed = false
func _on_OwnWords_toggled(button_pressed):
if button_pressed:
$Panel/WordSource/RandomWords.pressed = false
func _on_ContinueWordSource_pressed():
$Panel/WordSource.visible = false
if $Panel/WordSource/RandomWords.pressed:
config_.random_words = true
$Panel/ShowGuesses.visible = true
else:
config_.random_words = false
$Panel/InputWord.visible = true
func _on_BackWordSource_pressed():
$Panel/WordSource.visible = false
$Panel/TypeHangman.visible = true
# sixth slide
func _on_VBoxContainer_ready():
for child in $Panel/InputWord/ScrollContainer/VBoxContainer.get_children():
child.connect("text_changed", self, "_on_LineEdit_text_changed", [child])
node_triggered_new_line[child.name] = false
func _on_LineEdit_text_changed(new_text, child):
if node_triggered_new_line[child.name]:
return
# if not lines_generated
var new_line = LineEdit.new()
new_line.name = "LineEdit" + String($Panel/InputWord/ScrollContainer/VBoxContainer.get_child_count())
new_line.max_length = 11
new_line.placeholder_text = "More-Words"
var dynamic_font = load("res://Fonts/30Font.tres")
new_line.add_font_override("font", dynamic_font)
new_line.connect("text_changed", self, "_on_LineEdit_text_changed", [new_line])
$Panel/InputWord/ScrollContainer/VBoxContainer.add_child(new_line)
node_triggered_new_line[new_line.name] = false
node_triggered_new_line[child.name] = true
func _on_TextureRect_gui_input(event):
if (event is InputEventMouseButton && event.pressed && event.button_index == 1):
$Panel/InputWord/HintDialog.popup()
func _on_OpenCsvFile_pressed():
$Panel/InputWord/OpenCsvFile/FileDialog.popup()
func _on_FileDialog_file_selected(path):
var file = File.new()
var err = file.open(path, 1)
if err:
$ErrorDialog.dialog_text = "I encountered an error while opening the file, error number " + err
$ErrorDialog.popup()
else:
file_path = path
$Panel/InputWord/OpenCsvFile.text = "File succesfully set"
file.close()
func _on_BackInputWord_pressed():
$Panel/InputWord.visible = false
$Panel/WordSource.visible = true
func _on_ContinueInputWord_pressed():
config_.random_words = $Panel/InputWord/AppendRandom.pressed
var temp_words: = []
for child in $Panel/InputWord/ScrollContainer/VBoxContainer.get_children():
if child.text:
temp_words.append(PoolStringArray([child.text, "0"]))
if file_path:
var file = File.new()
var err = file.open(file_path, 1)
var line: int = 0
while true:
line += 1
var temp_word = file.get_csv_line()
if not temp_word[0]:
break
if temp_word.size() < 2:
$ErrorDialog.dialog_text = "The line " + String(line) + " is broken, it doesn't have enough elements in it."
$ErrorDialog.popup()
return
if temp_word[0].length() > 11:
$ErrorDialog.dialog_text = "The word " + temp_word[0] + " at line " + String(line) + " is " + String(temp_word[0].length() - 11) + " characters too long."
$ErrorDialog.popup()
return
temp_words.append(PoolStringArray([temp_word[0], int(temp_word[1])]))
file.close()
if not (config_.random_words || temp_words.size() != 0):
$ErrorDialog.dialog_text = "You did not supply any words and did not activate adding random ones, so there is no way to guess..."
$ErrorDialog.popup()
return
word_file = false
if temp_words.size() != 0:
var file = File.new()
file.open("user://words.csv", File.WRITE)
for word in temp_words:
file.store_csv_line(word)
file.close()
word_file = true
$Panel/InputWord.visible = false
$Panel/ShowGuesses.visible = true
# seventh slide
func _on_ContinueShowGuesses_pressed():
config_.show_guess = $Panel/ShowGuesses/GuessedLetters.pressed
config_.show_wrong = $Panel/ShowGuesses/WrongLetters.pressed
config_.count_already = $Panel/ShowGuesses/CountAlreadyGuessed.pressed
$Panel/ShowGuesses.visible = false
$Panel/AmountGuesses.visible = true
func _on_BackShowGuesses_pressed():
$Panel/ShowGuesses.visible = false
if word_file:
$Panel/InputWord.visible = true
else:
$Panel/WordSource.visible = true
# eigth slide
func _on_BackAmountGuesses_pressed():
$Panel/AmountGuesses.visible = false
if config_.build_hangman:
$Panel/TypeHangman.visible = true
else:
$Panel/ShowGuesses.visible = true
func _on_ContinueAmountGuesses_pressed():
config_.amount_guess = int($Panel/AmountGuesses/SpinBox.value)
$Panel/AmountGuesses.visible = false
$Panel/TypeGuesses.visible = true
# ninth slide
func _on_BackTypeGuesses_pressed():
$Panel/TypeGuesses.visible = false
$Panel/AmountGuesses.visible = true
func _on_TypeCheckbox_pressed():
if ($Panel/TypeGuesses/CheeringBits.pressed || $Panel/TypeGuesses/Subscribing.pressed || $Panel/TypeGuesses/ChatCommand.pressed):
$Panel/TypeGuesses/ContinueTypeGuesses.disabled = false
else:
$Panel/TypeGuesses/ContinueTypeGuesses.disabled = true
func _on_ContinueTypeGuesses_pressed():
if $Panel/TypeGuesses/CheeringBits.pressed:
config_.amount_bits = $Panel/TypeGuesses/CheeringBits/AmountBits.value
else:
config_.amount_bits = 0
if $Panel/TypeGuesses/Subscribing.pressed:
config_.amount_tier = $Panel/TypeGuesses/Subscribing/TierRequired.value
config_.amount_months = $Panel/TypeGuesses/Subscribing/MonthsRequired.value
else:
config_.amount_tier = 0
config_.amount_months = 0
if $Panel/TypeGuesses/ChatCommand.pressed:
config_.amount_timeout = $Panel/TypeGuesses/ChatCommand/Timeout.value
else:
config_.amount_timeout = 0
$Panel/TypeGuesses.visible = false
if (config_.amount_bits || config_.amount_tier):
$Panel/Multitude.visible = true
else:
$Panel/Chat.visible = true
var temp_limits = []
if $Panel/TypeGuesses/Streamer.pressed:
temp_limits.append("broadcaster")
if $Panel/TypeGuesses/Moderators.pressed:
temp_limits.append("moderator")
if $Panel/TypeGuesses/VIPs.pressed:
temp_limits.append("vip")
config_.dont_limit = PoolStringArray(temp_limits)
# tenth slide
func _on_BackMultitude_pressed():
$Panel/Multitude.visible = false
$Panel/TypeGuesses.visible = true
func _on_ContinueMultitude_pressed():
config_.multitude = $Panel/Multitude/MultitudeBox.pressed
$Panel/Multitude.visible = false
$Panel/Chat.visible = true
# eleventh slide
func _on_Chat_draw():
if config_.build_hangman:
$Panel/Chat/Commands/GuessedLettersRight.disabled = true
$Panel/Chat/Commands/GuessedLettersRight/LettersRightCommand.editable = false
$Panel/Chat/Commands/GuessedLettersWrong.disabled = true
$Panel/Chat/Commands/GuessedLettersWrong/LettersWrongCommand.editable = false
else:
if not config_.show_guess:
$Panel/Chat/Commands/GuessedLettersRight/ShowingRightLetters.visible = true
else:
$Panel/Chat/Commands/GuessedLettersRight/ShowingRightLetters.visible = false
if not config_.show_wrong:
$Panel/Chat/Commands/GuessedLettersWrong/ShowingWrongLetters.visible = true
else:
$Panel/Chat/Commands/GuessedLettersWrong/ShowingWrongLetters.visible = false
func _on_BackChat_pressed():
$Panel/Chat.visible = false
if (config_.amount_bits || config_.amount_tier):
$Panel/Multitude.visible = true
else:
$Panel/TypeGuesses.visible = true
func _on_ContinueChat_pressed():
for child in $Panel/Chat/Commands.get_children():
if child.pressed:
var text = child.get_child(0).text
if not text:
$ErrorDialog.dialog_text = "The command at " + child.text + " is empty, which can not work..."
$ErrorDialog.popup()
return
if text in config_.commands:
$ErrorDialog.dialog_text = "The command at " + child.text + " was already used, which can not work..."
$ErrorDialog.popup()
return
config_.commands[text] = child.name.to_lower()
$Panel/Chat.visible = false
$Panel/Finish.visible = true
# twelfth slide
func _on_BackFinish_pressed():
$Panel/Finish.visible = false
$Panel/Chat.visible = true
func _on_ContinueFinish_pressed():
var words = {}
if word_file:
var file = File.new()
file.open("user://words.csv", File.READ)
var line = 0
while true:
line += 1
var temp_word = file.get_csv_line()
if not temp_word[0]:
break
if temp_word.size() < 2:
$ErrorDialog.dialog_text = "The line " + String(line) + " of the words.csv is broken, it doesn't have enough elements in it."
$ErrorDialog.popup()
return
words[temp_word[0].to_lower()] = int(temp_word[1])
file.close()
SceneSwitcher.change_scene("res://Main.tscn", {"config": config_, "words": words})