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.
31 lines
982 B
GDScript
31 lines
982 B
GDScript
class_name AudioFile
|
|
extends RefCounted
|
|
## Reads songs from files: the songs downloaded from the server, and the songs in a music
|
|
## folder.
|
|
|
|
## The file types Godot can play from a file while the game runs.
|
|
const PLAYABLE_EXTENSIONS: Array[String] = ["mp3", "ogg", "wav"]
|
|
|
|
|
|
## Whether [param path] is a file type the game can play.
|
|
static func is_playable(path: String) -> bool:
|
|
return path.get_extension().to_lower() in PLAYABLE_EXTENSIONS
|
|
|
|
|
|
## Reads the song in [param path]. Returns null if the file is missing, is not a playable
|
|
## type, or is broken.
|
|
static func load(path: String) -> AudioStream:
|
|
if !FileAccess.file_exists(path):
|
|
return null
|
|
var stream: AudioStream = null
|
|
match path.get_extension().to_lower():
|
|
"mp3":
|
|
stream = AudioStreamMP3.load_from_file(path)
|
|
"ogg":
|
|
stream = AudioStreamOggVorbis.load_from_file(path)
|
|
"wav":
|
|
stream = AudioStreamWAV.load_from_file(path)
|
|
if stream == null || stream.get_length() <= 0.0:
|
|
return null
|
|
return stream
|