Settings has a Music folder row. A folder with subfolders is played as soundtracks: Next picks a random subfolder and a random song in it, the subfolder is the answer's soundtrack and the file name without its type the song. The inspiration list and Search show the subfolders. A folder with songs and no subfolders is a prepared quiz, played once in order (natural sort) or at random, showing only the song title. It has no winning score: after the last song Next becomes Show winner, and the players with the most points win, ties included. While a folder is used nothing but the characters is asked from the server: Sync, QR, Statistics, the update check and play counting are off. Characters fall back to the cached pictures when the server can't be reached. mp3, ogg and wav play; other files and broken ones are skipped. The old local playback code, the hidden Open button and the hidden Local toggle are removed. Next now waits for the song to start before preparing the next one.
56 lines
1.6 KiB
GDScript
56 lines
1.6 KiB
GDScript
class_name SongControls
|
|
extends Control
|
|
## The buttons for the song that is playing: show the answer, and go to the next song.
|
|
|
|
signal show_answer_pressed
|
|
signal next_pressed
|
|
## Emitted when Next is pressed at the end of a prepared quiz, where it reads
|
|
## "Show winner".
|
|
signal show_winner_pressed
|
|
|
|
const NEXT_TEXT: String = "Randomize new track"
|
|
const SHOW_WINNER_TEXT: String = "Show winner"
|
|
|
|
## True while Next reads "Show winner", after the last song of a prepared quiz.
|
|
var shows_winner: bool = false
|
|
|
|
@onready var show_answer_button: Button = $ShowAnswerButton
|
|
@onready var next_button: Button = $NextButton
|
|
|
|
|
|
func _ready() -> void:
|
|
show_answer_button.pressed.connect(show_answer_pressed.emit)
|
|
next_button.pressed.connect(_on_next_button_pressed)
|
|
|
|
|
|
## Enables Next while there is a downloaded song to play next.
|
|
func set_next_enabled(enabled: bool) -> void:
|
|
_set_shows_winner(false)
|
|
next_button.disabled = !enabled
|
|
|
|
|
|
## Turns Next into "Show winner", for when the last song of a prepared quiz has played.
|
|
func show_winner_button() -> void:
|
|
_set_shows_winner(true)
|
|
next_button.disabled = false
|
|
|
|
|
|
## Disables both buttons, e.g. while the server syncs the song list. Unlocking enables
|
|
## Show answer again; Next comes back when the next song has been downloaded.
|
|
func set_locked(locked: bool) -> void:
|
|
show_answer_button.disabled = locked
|
|
if locked:
|
|
next_button.disabled = true
|
|
|
|
|
|
func _set_shows_winner(on: bool) -> void:
|
|
shows_winner = on
|
|
next_button.text = SHOW_WINNER_TEXT if on else NEXT_TEXT
|
|
|
|
|
|
func _on_next_button_pressed() -> void:
|
|
if shows_winner:
|
|
show_winner_pressed.emit()
|
|
else:
|
|
next_pressed.emit()
|