2023-01-07 11:03:21 +00:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
signal play_pressed()
|
|
|
|
|
|
|
|
|
2023-01-14 21:49:58 +00:00
|
|
|
var username_regex
|
|
|
|
|
|
|
|
|
|
|
|
var username: String:
|
|
|
|
get:
|
|
|
|
return Singletons.username
|
|
|
|
set(value):
|
|
|
|
value = value.strip_escapes()
|
|
|
|
value = value.to_lower()
|
|
|
|
value = username_regex.sub(value, "-", true)
|
|
|
|
Singletons.username = value
|
|
|
|
var caret = $Content/Inputs/NameInput.caret_column
|
|
|
|
$Content/Inputs/NameInput.text = value
|
|
|
|
$Content/Inputs/NameInput.caret_column = caret
|
|
|
|
%PlayButton.disabled = len(value) <= 0
|
|
|
|
|
|
|
|
|
2023-01-07 11:03:21 +00:00
|
|
|
func play():
|
2023-01-09 19:41:22 +00:00
|
|
|
print("Player ", Singletons.username, " started playing!")
|
2023-01-07 11:03:21 +00:00
|
|
|
emit_signal("play_pressed")
|
2023-01-09 14:15:59 +00:00
|
|
|
|
|
|
|
|
2023-01-14 21:49:58 +00:00
|
|
|
func _on_name_input_text_changed(new_text):
|
|
|
|
if username != $Content/Inputs/NameInput.text:
|
|
|
|
username = $Content/Inputs/NameInput.text
|
2023-01-14 21:31:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_fetched_scores():
|
|
|
|
$Content/Buttons/HBoxContainer/ScoresButton.disabled = false
|
|
|
|
$Content/Buttons/HBoxContainer/ScoresButton.connect("pressed", $"/root/BaseScene/ScoreboardContainer".show_scores)
|
|
|
|
|
|
|
|
|
|
|
|
func _ready():
|
2023-01-14 21:49:58 +00:00
|
|
|
username_regex = RegEx.new()
|
|
|
|
username_regex.compile("[^a-z0-9]")
|
2023-01-14 21:31:02 +00:00
|
|
|
$"/root/BaseScene/ScoreboardContainer".connect("fetched_scores", _on_fetched_scores)
|
|
|
|
$"/root/BaseScene/ScoreboardContainer".fetch_scores(false)
|