feat: add audio library and visual verification

This commit is contained in:
goose
2026-10-01 08:48:38 -04:00
parent ea4bbf15fa
commit 0615f5b89d
15 changed files with 363 additions and 26 deletions
@@ -0,0 +1 @@
uid://7xniiqw7cch4
+30
View File
@@ -0,0 +1,30 @@
extends GutTest
const GameScene = preload("res://scenes/Game.tscn")
var empty_audio_home := ""
var game: Game
func before_each() -> void:
empty_audio_home = ProjectSettings.globalize_path("user://s4-empty-audio-home")
DirAccess.make_dir_recursive_absolute(empty_audio_home)
OS.set_environment("DCW_AUDIO_HOME", empty_audio_home)
game = GameScene.instantiate()
add_child_autofree(game)
await get_tree().process_frame
func after_each() -> void:
OS.set_environment("DCW_AUDIO_HOME", "")
func test_real_game_resolves_combat_with_empty_audio_home() -> void:
var audio = game.get_node("AudioLibrary")
game.submit_test_action(Vector2i.RIGHT)
var first_melee := game.submit_test_action(Vector2i.RIGHT)
var lethal_melee := game.submit_test_action(Vector2i.RIGHT)
assert_eq(first_melee[0].kind, &"melee")
assert_eq(lethal_melee[1].kind, &"enemy_defeated")
assert_false(game.get_game_state().enemies.has(&"goblin"))
assert_eq(audio.current_ambience_context, "combat")
assert_eq(audio.get_last_ambience_path(), "")
assert_eq(audio.get_last_sfx_path(), "")
@@ -0,0 +1 @@
uid://bf8f080ly7oa4
+44
View File
@@ -0,0 +1,44 @@
extends GutTest
const AudioLibrary = preload("res://scripts/infrastructure/audio_library.gd")
func test_missing_audio_directories_are_silent_for_known_requests() -> void:
var library := AudioLibrary.new("res://tests/fixtures/missing-dcwascii")
add_child_autofree(library)
library.set_ambience_context("exploration")
library.play_sfx("attack_given")
assert_eq(library.current_ambience_context, "exploration")
assert_eq(library.get_last_ambience_path(), "")
assert_eq(library.get_last_sfx_path(), "")
func test_unknown_requests_are_silent() -> void:
var library := AudioLibrary.new("res://tests/fixtures/missing-dcwascii")
add_child_autofree(library)
library.set_ambience_context("exploration")
library.set_ambience_context("unknown")
library.play_sfx("unknown")
assert_eq(library.current_ambience_context, "exploration")
assert_eq(library.get_last_ambience_path(), "")
assert_eq(library.get_last_sfx_path(), "")
func test_admitted_wav_file_is_discovered() -> void:
var root := ProjectSettings.globalize_path("user://s4-audio-library")
var sample_path := root.path_join("audio/exploration/silence.wav")
DirAccess.make_dir_recursive_absolute(sample_path.get_base_dir())
var sample := FileAccess.open(sample_path, FileAccess.WRITE)
sample.store_buffer(PackedByteArray([
82, 73, 70, 70, 36, 0, 0, 0, 87, 65, 86, 69, 102, 109, 116, 32,
16, 0, 0, 0, 1, 0, 1, 0, 68, 172, 0, 0, 136, 88, 1, 0,
2, 0, 16, 0, 100, 97, 116, 97, 0, 0, 0, 0,
]))
sample.close()
var library := AudioLibrary.new(root)
add_child_autofree(library)
library.set_ambience_context("exploration")
assert_eq(library.get_last_ambience_path(), sample_path)
+1
View File
@@ -0,0 +1 @@
uid://dso6tpksr7kjr
+1
View File
@@ -0,0 +1 @@
uid://k86b33m2hesr