Follow the GDScript style guide in every script

- Types on every parameter, return value and variable, and snake_case names
  (the player name limit is the constant MAX_NAME_LENGTH).
- Spelling fixes: *_triggered, character_selected, separator, caught_errors.
  The server's catched_errors key stays as the server sends it.
- Signals are connected with signal.connect() instead of by name.
- Code is ordered signals, constants, exported vars, vars, @onready vars,
  functions, with @onready on one line and two blank lines between functions.
- Every script starts with a ## description. Template comments, old LOC notes
  and commented-out code are gone, apart from the local play code.
- Lines are at most 100 characters, apart from the local play path.
- The screenshot tour turns off the blinking text cursor so pictures match.
This commit is contained in:
Sansan committed 2026-10-06 11:53:26 +02:00
1 parent 674604425f
commit a0428e3475
45 files changed
+580 -589

No files matched your search

+23 -19
View File
@@ -1,40 +1,42 @@
extends RefCounted
class_name PlayerObject
extends RefCounted
## A player in the quiz: name, score and character. The players are kept in
## [code]Settings.player_array[/code].
signal first_point_triggerd
signal match_point_triggerd
signal winner_triggerd
signal first_point_triggered
signal match_point_triggered
signal winner_triggered
signal point_given_sound
signal player_point_given
signal player_point_taken
## Unique id that never changes, unlike the player's position in Settings.player_array.
var id: String = _generate_uuid()
@export
var player_name: String
@export
var player_score: int
var is_first_point: bool = true
## Picture shown until the player picks a character.
const NO_CHARACTER_PATH: String = "res://noCharacter.png"
@export var player_name: String
@export var player_score: int
## Unique id that never changes, unlike the player's position in Settings.player_array.
var id: String = _generate_uuid()
var is_first_point: bool = true
var character: Texture = load(NO_CHARACTER_PATH)
func _init(new_name: String) -> void:
player_name = new_name
player_score = 0
## Returns a random version 4 UUID, e.g. "3f2b8c1e-9a4d-4e7f-b2c6-5d8e1f0a7b93".
static func _generate_uuid() -> String:
var bytes: PackedByteArray = Crypto.new().generate_random_bytes(16)
bytes[6] = (bytes[6] & 0x0f) | 0x40
bytes[8] = (bytes[8] & 0x3f) | 0x80
var hex: String = bytes.hex_encode()
return "%s-%s-%s-%s-%s" % [hex.substr(0, 8), hex.substr(8, 4), hex.substr(12, 4), hex.substr(16, 4), hex.substr(20, 12)]
return "%s-%s-%s-%s-%s" % [hex.substr(0, 8), hex.substr(8, 4), hex.substr(12, 4),
hex.substr(16, 4), hex.substr(20, 12)]
func add_point() -> void:
if player_score < Settings.winning_score:
@@ -46,14 +48,15 @@ func add_point() -> void:
# With a low winning score the first point can also be match point or the win,
# so the more important event is checked first
if player_score == Settings.winning_score:
winner_triggerd.emit()
winner_triggered.emit()
elif player_score == Settings.winning_score - 1:
match_point_triggerd.emit()
match_point_triggered.emit()
elif first_point:
first_point_triggerd.emit()
first_point_triggered.emit()
else:
point_given_sound.emit()
func minus_point() -> void:
if player_score > 0:
player_score -= 1
@@ -61,6 +64,7 @@ func minus_point() -> void:
if player_score == 0:
is_first_point = true
func reset_points() -> void:
player_score = 0
is_first_point = true