Files
MusicPlayer/quiz/inspiration_list.gd
T
Sansan 222d231b1b
Build / test (push) Successful in 1m2s
Build / build (push) Successful in 1m12s
Add offline mode: play from a music folder instead of the server
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.
2026-10-07 23:07:47 +02:00

73 lines
2.1 KiB
GDScript

class_name InspirationList
extends ScrollContainer
## The list of every soundtrack, shown for inspiration. It scrolls slowly up and down
## by itself, at the speed set in the settings.
## The soundtracks shown, in order.
var soundtracks: Array = []
# Scroll direction: 1 = down, -1 = up
var scroll_direction: int = 1
@onready var _rows: VBoxContainer = $VBoxContainer
func _ready() -> void:
scroll_direction = 1
func _process(delta: float) -> void:
var speed_pixels_per_second: float = float(Settings.inspiration_list_speed) * 60.0
var scroll_amount: float = speed_pixels_per_second * delta * float(scroll_direction)
var scroll_bar: VScrollBar = get_v_scroll_bar()
# Don't scroll if list is empty or too short
if scroll_bar.max_value <= 0:
return
var current_pos: float = scroll_bar.value
if scroll_direction == 1:
# Scrolling down
if current_pos + scroll_bar.page < scroll_bar.max_value:
scroll_bar.value = minf(current_pos + scroll_amount,
scroll_bar.max_value - scroll_bar.page)
else:
# Reached bottom, reverse direction
scroll_direction = -1
scroll_bar.value = scroll_bar.max_value - scroll_bar.page
else:
# Scrolling up
if current_pos > 0:
scroll_bar.value = maxf(current_pos + scroll_amount, 0)
else:
# Reached top, reverse direction
scroll_direction = 1
scroll_bar.value = 0
## Shows every soundtrack: the music folder's soundtracks when one is picked, otherwise
## the server's.
func load_soundtracks() -> void:
GameLog.debug("load_soundtracks")
if Settings.is_offline():
show_soundtracks(Settings.music_folder.soundtrack_names())
return
var populate_list: Callable = func populate_list(array: Variant) -> void:
if typeof(array) == TYPE_ARRAY:
show_soundtracks(array)
else:
GameLog.warning("Unexpected data")
MusicServerClient.fetch_all_soundtracks(populate_list)
## Shows [param list] instead of the soundtracks shown now.
func show_soundtracks(list: Array) -> void:
soundtracks = []
soundtracks.append_array(list)
Settings.delete_children(_rows)
for i: int in soundtracks.size():
_rows.add_child(ListRow.create(soundtracks[i], i, &"TextLarge"))