Implement audio management system with effects and music players; add settings for sound and music volume
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
extends SceneTree
|
||||
|
||||
var checks: int = 0
|
||||
var failures: int = 0
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
call_deferred("run")
|
||||
|
||||
|
||||
func check(condition: bool, message: String) -> void:
|
||||
checks += 1
|
||||
if not condition:
|
||||
failures += 1
|
||||
push_error(message)
|
||||
|
||||
|
||||
func run() -> void:
|
||||
var player := OwniverseEffectsPlayer.new()
|
||||
root.add_child(player)
|
||||
|
||||
check(player.play_effect("select"), "Known effect starts")
|
||||
check(player.stream == player._effects.select and player.playing, "Selected effect is playing")
|
||||
var selected_stream: AudioStream = player.stream
|
||||
check(not player.play_effect("select"), "Playing effect is not restarted")
|
||||
check(player.stream == selected_stream and player.playing, "Rejected duplicate keeps current playback")
|
||||
player.stop()
|
||||
check(not player.play_effect("select"), "Named effect is rejected during its two-second cooldown")
|
||||
check(player.play_effect("blast"), "Different effect starts without waiting for another name")
|
||||
player.stop()
|
||||
player._last_played_msec.select -= player.EFFECT_COOLDOWN_MSEC
|
||||
check(player.play_effect("select"), "Named effect starts after its cooldown")
|
||||
check(not player.play_effect("missing_effect"), "Unknown effect is rejected")
|
||||
check(player.stream == player._effects.select, "Unknown effect does not interrupt playback")
|
||||
|
||||
player.set_enabled(false)
|
||||
check(player.stream_paused, "Disabling effects pauses current playback")
|
||||
check(not player.play_effect("blast") and player.stream == player._effects.select, "Disabled player rejects new effects")
|
||||
player.set_enabled(true)
|
||||
check(not player.stream_paused, "Enabling effects resumes current playback")
|
||||
|
||||
player.stop()
|
||||
player.stream = null
|
||||
player.free()
|
||||
await process_frame
|
||||
print("Effects player: %d checks, %d failures" % [checks, failures])
|
||||
quit(0 if failures == 0 else 1)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cj2kk1vx5umtc
|
||||
@@ -0,0 +1,54 @@
|
||||
extends SceneTree
|
||||
|
||||
var checks: int = 0
|
||||
var failures: int = 0
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
call_deferred("run")
|
||||
|
||||
|
||||
func check(condition: bool, message: String) -> void:
|
||||
checks += 1
|
||||
if not condition:
|
||||
failures += 1
|
||||
push_error(message)
|
||||
|
||||
|
||||
func run() -> void:
|
||||
var player := OwniverseMusicPlayer.new()
|
||||
root.add_child(player)
|
||||
await process_frame
|
||||
|
||||
check(player.last_track == "", "Music player starts with silence")
|
||||
check(player._pause_timer.time_left >= player.MIN_PAUSE_SECONDS and player._pause_timer.time_left <= player.MAX_PAUSE_SECONDS, "Initial pause is between two and five minutes")
|
||||
player._pause_timer.stop()
|
||||
player._play_next()
|
||||
check(player.last_track != "", "Music player selects an initial track")
|
||||
check(player.last_track != player.EXCLUDED_TRACK, "Normal playlist excludes apocalypse")
|
||||
var previous: String = player.last_track
|
||||
player._play_next()
|
||||
check(player.last_track != previous, "Consecutive tracks do not repeat")
|
||||
check(player.last_track != player.EXCLUDED_TRACK, "Subsequent tracks exclude apocalypse")
|
||||
|
||||
var last_normal_track: String = player.last_track
|
||||
player.play_apocalypse()
|
||||
check(player.stream == player._music[player.EXCLUDED_TRACK] and player.playing, "Apocalypse music starts immediately")
|
||||
check(player.last_track == last_normal_track, "Apocalypse does not replace the last normal track")
|
||||
|
||||
player._schedule_pause()
|
||||
check(player._pause_timer.time_left >= player.MIN_PAUSE_SECONDS and player._pause_timer.time_left <= player.MAX_PAUSE_SECONDS, "Pause is between two and five minutes")
|
||||
player.set_enabled(false)
|
||||
check(player.stream_paused and player._pause_timer.paused, "Disabling music pauses playback and scheduling")
|
||||
var disabled_stream: AudioStream = player.stream
|
||||
player.play_apocalypse()
|
||||
check(player.stream == disabled_stream, "Apocalypse does not start while music is disabled")
|
||||
player.set_enabled(true)
|
||||
check(not player.stream_paused and not player._pause_timer.paused, "Enabling music resumes playback and scheduling")
|
||||
|
||||
player.stop()
|
||||
player.stream = null
|
||||
player.free()
|
||||
await process_frame
|
||||
print("Music player: %d checks, %d failures" % [checks, failures])
|
||||
quit(0 if failures == 0 else 1)
|
||||
@@ -0,0 +1 @@
|
||||
uid://nue2ifdplt25
|
||||
Reference in New Issue
Block a user