79 lines
4.1 KiB
GDScript
79 lines
4.1 KiB
GDScript
extends SceneTree
|
|
|
|
## M76-C machine gate: the runtime audio service maps contract events to the
|
|
## right buses, honours cooldown and priority, switches music families without
|
|
## restarting the same family, and keeps dispatching (journalled) while muted.
|
|
|
|
const AudioServiceScript = preload("res://presentation/audio_service.gd")
|
|
|
|
var failures: Array[String] = []
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("_run")
|
|
|
|
|
|
func _run() -> void:
|
|
root.size = Vector2i(1280, 720)
|
|
var host := Node.new()
|
|
host.name = "AudioServiceHost"
|
|
root.add_child(host)
|
|
var service: Node = AudioServiceScript.new()
|
|
host.add_child(service)
|
|
await process_frame
|
|
|
|
_expect(service.load_manifest(), "manifest loads")
|
|
_expect(service.events.size() == 144, "144 contract events mapped, got %d" % service.events.size())
|
|
_expect(service.music_families.size() == 7, "7 music families mapped, got %d" % service.music_families.size())
|
|
|
|
service.apply_settings({"master_muted": false, "music_volume": 0.5, "ambience_volume": 0.8, "sfx_volume": 0.9, "voice_volume": 0.8})
|
|
var music_bus := AudioServer.get_bus_index(&"Music")
|
|
_expect(absf(AudioServer.get_bus_volume_db(music_bus) - linear_to_db(0.5)) < 0.01, "music bus volume follows settings")
|
|
for bus_name in ["Ambience", "SFX", "Voice", "SFXUI", "SFXCritical", "SFXPlayerCommit", "SFXWorld", "MusicBed", "Accessibility"]:
|
|
_expect(AudioServer.get_bus_index(StringName(bus_name)) >= 0, "bus exists: %s" % bus_name)
|
|
|
|
_expect(service.play_sfx("focus_move"), "focus_move dispatches")
|
|
_expect(String(service.last_record().get("bus", "")) == "SFXUI", "focus_move rides SFXUI")
|
|
_expect(not service.play_sfx("focus_move"), "second focus_move inside cooldown is suppressed")
|
|
_expect(String(service.last_record().get("suppressed", "")) == "cooldown", "suppression is journalled as cooldown")
|
|
_expect(service.play_sfx("recruit_hire_commit"), "recruit commit dispatches")
|
|
_expect(String(service.last_record().get("bus", "")) == "SFXPlayerCommit", "recruit commit rides SFXPlayerCommit")
|
|
_expect(String(service.last_record().get("priority", "")) == "P2", "recruit commit is P2")
|
|
_expect(service.play_sfx("battle_victory"), "battle_victory dispatches")
|
|
_expect(String(service.last_record().get("bus", "")) == "SFXCritical", "battle_victory rides SFXCritical")
|
|
_expect(not service.play_sfx("no_such_event"), "unknown event is refused")
|
|
|
|
_expect(service.set_music("guild"), "guild family starts")
|
|
var switches: int = int(service.music_switches)
|
|
_expect(not service.set_music("guild"), "same family does not restart")
|
|
_expect(service.music_switches == switches, "same-family switch is a no-op")
|
|
_expect(service.music_restarts == 0, "no restart counted for the same family")
|
|
_expect(service.set_music("market"), "market family switches")
|
|
_expect(service.music_switches == 2 and service.music_restarts == 1, "switch counters track family changes")
|
|
_expect(not service.set_music("unknown_family"), "unknown family refused")
|
|
|
|
var before: int = int(service.journal_size())
|
|
service.apply_settings({"master_muted": true, "music_volume": 0.5, "ambience_volume": 0.8, "sfx_volume": 0.9, "voice_volume": 0.8})
|
|
_expect(not service.play_sfx("recruit_hire_commit"), "muted play does not open a voice")
|
|
_expect(service.journal_size() == before + 1, "muted play still journals the semantic event")
|
|
_expect(String(service.last_record().get("suppressed", "")) == "muted", "muted dispatch is marked")
|
|
var master := AudioServer.get_bus_index(&"Master")
|
|
_expect(AudioServer.is_bus_mute(master), "master mute reaches the mixer")
|
|
service.apply_settings({"master_muted": false, "music_volume": 0.8, "ambience_volume": 0.8, "sfx_volume": 0.9, "voice_volume": 0.8})
|
|
_expect(not AudioServer.is_bus_mute(master), "master mute is reversible")
|
|
service.dispose()
|
|
|
|
if failures.is_empty():
|
|
print("ABG_M76_AUDIO_SERVICE_OK events=%d families=%d buses=9 cooldown=ok priority=ok mute=ok" % [service.events.size(), service.music_families.size()])
|
|
quit(0)
|
|
return
|
|
for failure in failures:
|
|
push_error("audio service failure: %s" % failure)
|
|
print("ABG_M76_AUDIO_SERVICE_FAIL failures=%d" % failures.size())
|
|
quit(1)
|
|
|
|
|
|
func _expect(condition: bool, label: String) -> void:
|
|
if not condition:
|
|
failures.append(label)
|