Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
efcaef181b | ||
|
|
d3c417fb91 |
@@ -0,0 +1,54 @@
|
||||
class_name AudioImportManifest
|
||||
extends Resource
|
||||
|
||||
## A deliberately small, Godot-native audio catalog.
|
||||
##
|
||||
## AudioLibrary only consumes AudioStream instances registered here. It never
|
||||
## searches a user directory or asks an arbitrary file path to be decoded.
|
||||
## A setup tool may construct this resource from assets already imported by
|
||||
## Godot, then save it at USER_MANIFEST_PATH for the game to load.
|
||||
|
||||
const AMBIENCE_CONTEXTS := [&"exploration", &"combat", &"danger"]
|
||||
const SFX_EVENTS := [&"attack_given", &"attack_received", &"menu_select", &"menu_cancel", &"item_use", &"death"]
|
||||
const USER_AUDIO_DIRECTORY := "user://audio"
|
||||
const USER_MANIFEST_PATH := "user://audio/audio_import_manifest.tres"
|
||||
|
||||
var ambience_streams: Dictionary = {}
|
||||
var sfx_streams: Dictionary = {}
|
||||
|
||||
func register_ambience(context: StringName, stream: AudioStream) -> bool:
|
||||
if not context in AMBIENCE_CONTEXTS or stream == null:
|
||||
return false
|
||||
ambience_streams[context] = stream
|
||||
return true
|
||||
|
||||
func register_sfx(event: StringName, stream: AudioStream) -> bool:
|
||||
if not event in SFX_EVENTS or stream == null:
|
||||
return false
|
||||
sfx_streams[event] = stream
|
||||
return true
|
||||
|
||||
func ambience_for(context: StringName) -> AudioStream:
|
||||
return ambience_streams.get(context) as AudioStream
|
||||
|
||||
func sfx_for(event: StringName) -> AudioStream:
|
||||
return sfx_streams.get(event) as AudioStream
|
||||
|
||||
static func ensure_user_audio_directory() -> Error:
|
||||
return DirAccess.make_dir_recursive_absolute(ProjectSettings.globalize_path(USER_AUDIO_DIRECTORY))
|
||||
|
||||
static func save_user_manifest(manifest: AudioImportManifest) -> Error:
|
||||
if manifest == null:
|
||||
return ERR_INVALID_PARAMETER
|
||||
var directory_result := ensure_user_audio_directory()
|
||||
if directory_result != OK:
|
||||
return directory_result
|
||||
return ResourceSaver.save(manifest, USER_MANIFEST_PATH)
|
||||
|
||||
static func load_user_manifest() -> AudioImportManifest:
|
||||
if not FileAccess.file_exists(USER_MANIFEST_PATH):
|
||||
return AudioImportManifest.new()
|
||||
var resource := ResourceLoader.load(USER_MANIFEST_PATH, "AudioImportManifest", ResourceLoader.CACHE_MODE_IGNORE)
|
||||
if resource is AudioImportManifest:
|
||||
return resource as AudioImportManifest
|
||||
return AudioImportManifest.new()
|
||||
@@ -0,0 +1 @@
|
||||
uid://bpu2ji542yhob
|
||||
@@ -1,30 +1,58 @@
|
||||
class_name AudioLibrary
|
||||
extends Node
|
||||
|
||||
const AudioImportManifestType = preload("res://scripts/infrastructure/audio_import_manifest.gd")
|
||||
|
||||
const AMBIENCE_CONTEXTS := ["exploration", "combat", "danger"]
|
||||
const SFX_EVENTS := ["attack_given", "attack_received", "menu_select", "menu_cancel", "item_use", "death"]
|
||||
const ADMITTED_EXTENSIONS := ["mp3", "ogg", "oga", "wav", "flac", "m4a", "opus"]
|
||||
const DEFAULT_AUDIO_HOME := ".local/share/dcwascii"
|
||||
const AMBIENCE_BUS := &"Ambience"
|
||||
const SFX_BUS := &"SFX"
|
||||
const DEFAULT_VOLUME_PERCENT := 100
|
||||
const VOLUME_STEP_PERCENT := 10
|
||||
|
||||
var current_ambience_context := ""
|
||||
var _audio_home_override := ""
|
||||
var _manifest: AudioImportManifest
|
||||
var _ambience_player: AudioStreamPlayer
|
||||
var _sfx_player: AudioStreamPlayer
|
||||
var _ambience_volume_percent := DEFAULT_VOLUME_PERCENT
|
||||
var _sfx_volume_percent := DEFAULT_VOLUME_PERCENT
|
||||
var _last_ambience_path := ""
|
||||
var _last_sfx_path := ""
|
||||
|
||||
func _init(audio_home_override: String = "") -> void:
|
||||
_audio_home_override = audio_home_override
|
||||
func _init(manifest_or_legacy_root: Variant = null) -> void:
|
||||
# The former API accepted an external directory override. Intentionally ignore
|
||||
# it for compatibility: external paths are not a safe playback source.
|
||||
if manifest_or_legacy_root is AudioImportManifest:
|
||||
_manifest = manifest_or_legacy_root as AudioImportManifest
|
||||
else:
|
||||
_manifest = AudioImportManifestType.load_user_manifest()
|
||||
|
||||
func _ready() -> void:
|
||||
_ensure_players()
|
||||
|
||||
func set_manifest(manifest: AudioImportManifest) -> void:
|
||||
_manifest = manifest if manifest != null else AudioImportManifestType.new()
|
||||
if current_ambience_context.is_empty():
|
||||
_last_ambience_path = ""
|
||||
else:
|
||||
_set_ambience_stream(_manifest.ambience_for(StringName(current_ambience_context)))
|
||||
|
||||
func set_ambience_context(context: String) -> void:
|
||||
if not context in AMBIENCE_CONTEXTS:
|
||||
return
|
||||
current_ambience_context = context
|
||||
_last_ambience_path = _find_first_audio_file("audio", current_ambience_context)
|
||||
_last_ambience_path = ""
|
||||
_set_ambience_stream(_manifest.ambience_for(StringName(context)))
|
||||
|
||||
func play_sfx(event: String) -> void:
|
||||
_last_sfx_path = ""
|
||||
if not event in SFX_EVENTS:
|
||||
return
|
||||
_last_sfx_path = _find_first_audio_file("sfx", event)
|
||||
_ensure_players()
|
||||
var stream := _manifest.sfx_for(StringName(event))
|
||||
_sfx_player.stream = stream
|
||||
if stream != null:
|
||||
_sfx_player.play()
|
||||
|
||||
func get_last_ambience_path() -> String:
|
||||
return _last_ambience_path
|
||||
@@ -32,34 +60,78 @@ func get_last_ambience_path() -> String:
|
||||
func get_last_sfx_path() -> String:
|
||||
return _last_sfx_path
|
||||
|
||||
func get_ambience_stream() -> AudioStream:
|
||||
_ensure_players()
|
||||
return _ambience_player.stream
|
||||
|
||||
func get_sfx_stream() -> AudioStream:
|
||||
_ensure_players()
|
||||
return _sfx_player.stream
|
||||
|
||||
func get_ambience_player() -> AudioStreamPlayer:
|
||||
_ensure_players()
|
||||
return _ambience_player
|
||||
|
||||
func get_sfx_player() -> AudioStreamPlayer:
|
||||
_ensure_players()
|
||||
return _sfx_player
|
||||
|
||||
func has_playable_ambience() -> bool:
|
||||
return false
|
||||
return get_ambience_stream() != null
|
||||
|
||||
func has_playable_sfx() -> bool:
|
||||
return false
|
||||
return get_sfx_stream() != null
|
||||
|
||||
func _audio_roots() -> Array[String]:
|
||||
if not _audio_home_override.is_empty():
|
||||
return [_audio_home_override]
|
||||
var roots: Array[String] = []
|
||||
var environment_root := OS.get_environment("DCW_AUDIO_HOME")
|
||||
if not environment_root.is_empty():
|
||||
roots.append(environment_root)
|
||||
roots.append(OS.get_environment("HOME").path_join(DEFAULT_AUDIO_HOME))
|
||||
return roots
|
||||
func set_ambience_volume_percent(percent: int) -> void:
|
||||
_ambience_volume_percent = clampi(percent, 0, 100)
|
||||
_apply_volume(AMBIENCE_BUS, _ambience_volume_percent)
|
||||
|
||||
func _find_first_audio_file(kind: String, name: String) -> String:
|
||||
for root in _audio_roots():
|
||||
var directory_path := root.path_join(kind).path_join(name)
|
||||
var directory := DirAccess.open(directory_path)
|
||||
if directory == null:
|
||||
continue
|
||||
directory.list_dir_begin()
|
||||
var entry := directory.get_next()
|
||||
while not entry.is_empty():
|
||||
if not directory.current_is_dir() and entry.get_extension().to_lower() in ADMITTED_EXTENSIONS:
|
||||
directory.list_dir_end()
|
||||
return directory_path.path_join(entry)
|
||||
entry = directory.get_next()
|
||||
directory.list_dir_end()
|
||||
return ""
|
||||
func set_sfx_volume_percent(percent: int) -> void:
|
||||
_sfx_volume_percent = clampi(percent, 0, 100)
|
||||
_apply_volume(SFX_BUS, _sfx_volume_percent)
|
||||
|
||||
func get_ambience_volume_percent() -> int:
|
||||
return _ambience_volume_percent
|
||||
|
||||
func get_sfx_volume_percent() -> int:
|
||||
return _sfx_volume_percent
|
||||
|
||||
func _set_ambience_stream(stream: AudioStream) -> void:
|
||||
_ensure_players()
|
||||
_ambience_player.stream = stream
|
||||
if stream != null:
|
||||
_ambience_player.play()
|
||||
|
||||
func _ensure_players() -> void:
|
||||
if _ambience_player == null:
|
||||
_ambience_player = AudioStreamPlayer.new()
|
||||
_ambience_player.name = "AmbiencePlayer"
|
||||
_ambience_player.bus = AMBIENCE_BUS
|
||||
_ambience_player.finished.connect(_restart_ambience)
|
||||
add_child(_ambience_player)
|
||||
if _sfx_player == null:
|
||||
_sfx_player = AudioStreamPlayer.new()
|
||||
_sfx_player.name = "SfxPlayer"
|
||||
_sfx_player.bus = SFX_BUS
|
||||
add_child(_sfx_player)
|
||||
_apply_volume(AMBIENCE_BUS, _ambience_volume_percent)
|
||||
_apply_volume(SFX_BUS, _sfx_volume_percent)
|
||||
|
||||
func _restart_ambience() -> void:
|
||||
if _ambience_player.stream != null:
|
||||
_ambience_player.play()
|
||||
|
||||
func _apply_volume(bus_name: StringName, percent: int) -> void:
|
||||
var bus_index := AudioServer.get_bus_index(bus_name)
|
||||
if bus_index == -1:
|
||||
bus_index = _ensure_bus(bus_name)
|
||||
AudioServer.set_bus_volume_db(bus_index, linear_to_db(float(percent) / 100.0) if percent > 0 else -80.0)
|
||||
|
||||
func _ensure_bus(bus_name: StringName) -> int:
|
||||
var existing_index := AudioServer.get_bus_index(bus_name)
|
||||
if existing_index != -1:
|
||||
return existing_index
|
||||
AudioServer.add_bus()
|
||||
var bus_index := AudioServer.bus_count - 1
|
||||
AudioServer.set_bus_name(bus_index, bus_name)
|
||||
return bus_index
|
||||
|
||||
@@ -10,6 +10,7 @@ var ui_scale := 1.0
|
||||
var _selected_index := 0
|
||||
var _waiting_for_rebind := false
|
||||
var _bindings: Dictionary[StringName, Key] = {}
|
||||
var _audio_library: AudioLibrary
|
||||
|
||||
var waiting_for_rebind: bool:
|
||||
get:
|
||||
@@ -24,6 +25,7 @@ func _ready() -> void:
|
||||
func present() -> void:
|
||||
visible = true
|
||||
_waiting_for_rebind = false
|
||||
_audio_library = get_node_or_null("../../AudioLibrary") as AudioLibrary
|
||||
refresh()
|
||||
|
||||
func dismiss() -> void:
|
||||
@@ -44,7 +46,15 @@ func handle_key(event: InputEventKey) -> bool:
|
||||
_waiting_for_rebind = false
|
||||
refresh()
|
||||
return true
|
||||
if event.keycode == KEY_UP:
|
||||
if event.keycode == KEY_A and _audio_library != null:
|
||||
_audio_library.set_ambience_volume_percent(_audio_library.get_ambience_volume_percent() - AudioLibrary.VOLUME_STEP_PERCENT)
|
||||
elif event.keycode == KEY_Z and _audio_library != null:
|
||||
_audio_library.set_ambience_volume_percent(_audio_library.get_ambience_volume_percent() + AudioLibrary.VOLUME_STEP_PERCENT)
|
||||
elif event.keycode == KEY_S and _audio_library != null:
|
||||
_audio_library.set_sfx_volume_percent(_audio_library.get_sfx_volume_percent() - AudioLibrary.VOLUME_STEP_PERCENT)
|
||||
elif event.keycode == KEY_X and _audio_library != null:
|
||||
_audio_library.set_sfx_volume_percent(_audio_library.get_sfx_volume_percent() + AudioLibrary.VOLUME_STEP_PERCENT)
|
||||
elif event.keycode == KEY_UP:
|
||||
_selected_index = posmod(_selected_index - 1, 3)
|
||||
elif event.keycode == KEY_DOWN:
|
||||
_selected_index = posmod(_selected_index + 1, 3)
|
||||
@@ -67,7 +77,9 @@ func refresh() -> void:
|
||||
return
|
||||
var cursor := func(index: int) -> String: return "> " if index == _selected_index else " "
|
||||
var contrast := "Renforcé" if _selected_index == 1 else "Standard"
|
||||
body.text = "%sÉchelle UI : %d%%\n%sMarqueurs color-blind : %s\n%sRemapper Inventaire : %s\n\nFlèches — ajuster Entrée — sélectionner Échap / O — fermer" % [cursor.call(0), int(ui_scale * 100.0), cursor.call(1), contrast, cursor.call(2), OS.get_keycode_string(binding_for(&"inventory"))]
|
||||
var ambience_volume := _audio_library.get_ambience_volume_percent() if _audio_library != null else 100
|
||||
var sfx_volume := _audio_library.get_sfx_volume_percent() if _audio_library != null else 100
|
||||
body.text = "%sÉchelle UI : %d%%\n%sMarqueurs color-blind : %s\n%sRemapper Inventaire : %s\n\nAmbiance : %d%% Effets sonores : %d%%\nA / Z — volume ambiance S / X — volume effets\nFlèches — ajuster Entrée — sélectionner Échap / O — fermer" % [cursor.call(0), int(ui_scale * 100.0), cursor.call(1), contrast, cursor.call(2), OS.get_keycode_string(binding_for(&"inventory")), ambience_volume, sfx_volume]
|
||||
|
||||
func _adjust_selected(direction: int) -> void:
|
||||
if _selected_index == 0:
|
||||
@@ -75,6 +87,7 @@ func _adjust_selected(direction: int) -> void:
|
||||
ui_scale = SCALE_STEPS[clampi(index + direction, 0, SCALE_STEPS.size() - 1)]
|
||||
_apply_scale()
|
||||
|
||||
|
||||
func _apply_scale() -> void:
|
||||
var hud := get_parent() as CanvasLayer
|
||||
if hud == null:
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
# Task G3 — Safe Optional Audio Playback and Settings
|
||||
|
||||
## Scope
|
||||
|
||||
Implemented G3 exclusively in the Godot port worktree. No DCWASCII files were changed.
|
||||
|
||||
- Added `AudioImportManifest`, a typed Godot `Resource` catalog for the three supported ambience contexts and six supported SFX events. It provides the optional `user://audio` setup directory and accepts only registered `AudioStream` objects.
|
||||
- Replaced `AudioLibrary`'s arbitrary external directory scan with manifest-only playback. The library now owns ambient/SFX `AudioStreamPlayer`s, routes them through separately named `Ambience` and `SFX` buses, loops available ambience, and remains silent when no registered stream exists.
|
||||
- Preserved the old constructor's external-directory argument only as a harmless ignored compatibility value; it is no longer an audio decoding input. No runtime call inspects or loads arbitrary external audio files.
|
||||
- Added keyboard-accessible volume controls to the existing Options panel: `A`/`Z` lower/raise ambience and `S`/`X` lower/raise SFX in ten-percent steps. Existing three-row arrow-key navigation and inventory rebinding behavior remains unchanged.
|
||||
- Added manifest/playback unit coverage, external-file fail-closed coverage, safe directory-setup coverage, a real Game/Options E2E for volumes/buses/manifest playback, and updated prior no-audio tests to assert external WAV files stay ignored.
|
||||
|
||||
## Strict TDD evidence
|
||||
|
||||
1. Added `test_audio_playback.gd` and `test_audio_settings_e2e.gd` before production code.
|
||||
2. After the normal Godot import prerequisite, both RED invocations failed at parse/collection time because `audio_import_manifest.gd`, `AudioLibrary.AMBIENCE_BUS`, and `AudioLibrary.SFX_BUS` did not exist. This establishes the requested missing-manifest/settings contract was red before implementation.
|
||||
3. Implemented the manifest, manifest-only player path, audio buses, and option controls. Focused green verification passed:
|
||||
- Audio unit suites: **6 / 6**, **33** assertions.
|
||||
- Audio/no-audio/settings E2E suites: **3 / 3**, **25** assertions.
|
||||
|
||||
## Root-cause fixes found during verification
|
||||
|
||||
The original `AudioLibrary` enumerated files under an external home, retained their raw paths, and deliberately reported them unplayable. This neither implemented playback nor safely bounded decoder input. The fix removes that discovery route rather than adding a secondary guard: the only playback assignment is a typed `AudioStream` retrieved from `AudioImportManifest`; arbitrary user paths are ignored and no longer reported as discovered.
|
||||
|
||||
The first full verification also exposed a G2 navigation regression: adding two rows to the arrow-navigated option list changed the established two-Down/Enter sequence that opens inventory rebinding. The root cause was changing an existing navigation contract, not audio itself. The final UI keeps the original three-row navigation and adds audio controls as dedicated displayed keys (`A/Z`, `S/X`); the focused audio-settings and pre-existing full UI navigation E2E tests both pass.
|
||||
|
||||
## Final verification
|
||||
|
||||
`./scripts/verify.sh` completed successfully with Godot 4.5.0:
|
||||
|
||||
- Unit: **185 / 185** tests passed, **1,407** assertions.
|
||||
- Integration: **11 / 11** tests passed, **59,470** assertions.
|
||||
- E2E: **57 / 57** tests passed, **571** assertions, including safe no-audio and audio-settings end-to-end paths.
|
||||
- Visual capture: passed.
|
||||
- `artifacts/visual-check.png`: `dungeon_non_black_pixels=489308`, `visible_pixels=17524`, `explored_pixels=10438`, `explored_luminance=0.012`, `unknown_pixels=365325`, `unknown_luminance=0.001`.
|
||||
- `artifacts/visual-check-exit.png`: `dungeon_non_black_pixels=489252`, `visible_pixels=17404`, `explored_pixels=17146`, `explored_luminance=0.012`, `unknown_pixels=439497`, `unknown_luminance=0.001`.
|
||||
|
||||
The standard GUT invalid-UID and Godot cleanup/resource warnings were emitted. There were no application parse errors, script errors, test failures, or visual verification failures.
|
||||
|
||||
## Git
|
||||
|
||||
All G3 sources, generated UIDs, tests, and this root report are committed locally in one commit. No push and no pull request were created.
|
||||
@@ -0,0 +1,50 @@
|
||||
extends GutTest
|
||||
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
const AudioImportManifest = preload("res://scripts/infrastructure/audio_import_manifest.gd")
|
||||
|
||||
var game: Game
|
||||
|
||||
func before_each() -> void:
|
||||
game = GameScene.instantiate()
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
|
||||
func test_options_control_audio_buses_and_imported_manifest_playback_without_external_files() -> void:
|
||||
var audio = game.get_node("AudioLibrary") as AudioLibrary
|
||||
var manifest := AudioImportManifest.new()
|
||||
assert_true(manifest.register_ambience(&"combat", _silent_stream()))
|
||||
assert_true(manifest.register_sfx(&"attack_given", _silent_stream()))
|
||||
audio.set_manifest(manifest)
|
||||
|
||||
await _dispatch_key(KEY_O)
|
||||
var options_panel := game.get_node("HUD/OptionsPanel") as OptionsPanel
|
||||
assert_true(options_panel.visible)
|
||||
assert_string_contains((options_panel.get_node("Body") as RichTextLabel).get_parsed_text(), "Ambiance")
|
||||
await _dispatch_key(KEY_A)
|
||||
await _dispatch_key(KEY_S)
|
||||
assert_eq(audio.get_ambience_volume_percent(), 90)
|
||||
assert_eq(audio.get_sfx_volume_percent(), 90)
|
||||
|
||||
audio.set_ambience_context("combat")
|
||||
audio.play_sfx("attack_given")
|
||||
assert_true(audio.has_playable_ambience())
|
||||
assert_true(audio.has_playable_sfx())
|
||||
assert_eq(audio.get_ambience_player().bus, AudioLibrary.AMBIENCE_BUS)
|
||||
assert_eq(audio.get_sfx_player().bus, AudioLibrary.SFX_BUS)
|
||||
|
||||
func _dispatch_key(keycode: Key) -> void:
|
||||
var event := InputEventKey.new()
|
||||
event.keycode = keycode
|
||||
event.physical_keycode = keycode
|
||||
event.pressed = true
|
||||
game._unhandled_input(event)
|
||||
await get_tree().process_frame
|
||||
|
||||
func _silent_stream() -> AudioStreamWAV:
|
||||
var stream := AudioStreamWAV.new()
|
||||
stream.format = AudioStreamWAV.FORMAT_16_BITS
|
||||
stream.mix_rate = 44100
|
||||
stream.stereo = false
|
||||
stream.data = PackedByteArray([0, 0, 0, 0])
|
||||
return stream
|
||||
@@ -0,0 +1 @@
|
||||
uid://b44wxq45xtuwp
|
||||
@@ -12,7 +12,7 @@ func before_each() -> void:
|
||||
DirAccess.make_dir_recursive_absolute(empty_audio_home)
|
||||
OS.set_environment("DCW_AUDIO_HOME", empty_audio_home)
|
||||
game = GameScene.instantiate()
|
||||
# Replace the scene library before ready to isolate both production search roots.
|
||||
# Replace the scene library before ready to isolate the no-audio fallback.
|
||||
var scene_audio := game.get_node("AudioLibrary")
|
||||
var isolated_audio := AudioLibrary.new(empty_audio_home)
|
||||
isolated_audio.name = "AudioLibrary"
|
||||
@@ -43,18 +43,14 @@ func test_real_game_resolves_combat_with_empty_audio_home() -> void:
|
||||
assert_false(audio.has_playable_ambience())
|
||||
assert_false(audio.has_playable_sfx())
|
||||
|
||||
func test_external_nominal_and_invalid_wavs_do_not_affect_combat() -> void:
|
||||
func test_external_wavs_do_not_affect_combat_or_become_playable() -> void:
|
||||
var audio = game.get_node("AudioLibrary")
|
||||
var nominal_path := empty_audio_home.path_join("audio/combat/silence.wav")
|
||||
var nominal_path := empty_audio_home.path_join("audio/combat/external.wav")
|
||||
var invalid_path := empty_audio_home.path_join("sfx/attack_given/truncated.wav")
|
||||
DirAccess.make_dir_recursive_absolute(nominal_path.get_base_dir())
|
||||
DirAccess.make_dir_recursive_absolute(invalid_path.get_base_dir())
|
||||
var nominal_file := FileAccess.open(nominal_path, FileAccess.WRITE)
|
||||
nominal_file.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,
|
||||
]))
|
||||
nominal_file.store_string("untrusted external WAV")
|
||||
nominal_file.close()
|
||||
var invalid_file := FileAccess.open(invalid_path, FileAccess.WRITE)
|
||||
invalid_file.store_string("truncated WAV")
|
||||
@@ -69,10 +65,9 @@ func test_external_nominal_and_invalid_wavs_do_not_affect_combat() -> void:
|
||||
assert_eq(first_melee[0].kind, &"melee")
|
||||
assert_eq(lethal_melee[1].kind, &"enemy_defeated")
|
||||
assert_false(game.get_game_state().enemies.has(&"goblin"))
|
||||
# Discovery remains diagnostic-only after combat; no external stream is playable.
|
||||
audio.set_ambience_context("combat")
|
||||
audio.play_sfx("attack_given")
|
||||
assert_eq(audio.get_last_ambience_path(), nominal_path)
|
||||
assert_eq(audio.get_last_sfx_path(), invalid_path)
|
||||
assert_eq(audio.get_last_ambience_path(), "")
|
||||
assert_eq(audio.get_last_sfx_path(), "")
|
||||
assert_false(audio.has_playable_ambience())
|
||||
assert_false(audio.has_playable_sfx())
|
||||
|
||||
@@ -29,18 +29,14 @@ func test_unknown_requests_are_silent() -> void:
|
||||
assert_false(library.has_playable_ambience())
|
||||
assert_false(library.has_playable_sfx())
|
||||
|
||||
func test_nominal_and_invalid_wavs_are_discovered_but_never_playable() -> void:
|
||||
func test_legacy_external_directory_override_is_ignored_and_invalid_wavs_stay_silent() -> void:
|
||||
var root := ProjectSettings.globalize_path("user://s4-external-audio-library")
|
||||
var nominal_path := root.path_join("audio/exploration/silence.wav")
|
||||
var invalid_path := root.path_join("sfx/attack_given/not-a-wave.wav")
|
||||
DirAccess.make_dir_recursive_absolute(nominal_path.get_base_dir())
|
||||
DirAccess.make_dir_recursive_absolute(invalid_path.get_base_dir())
|
||||
var nominal_file := FileAccess.open(nominal_path, FileAccess.WRITE)
|
||||
nominal_file.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,
|
||||
]))
|
||||
nominal_file.store_string("this must not be loaded by the audio library")
|
||||
nominal_file.close()
|
||||
var invalid_file := FileAccess.open(invalid_path, FileAccess.WRITE)
|
||||
invalid_file.store_string("this is not a WAV file")
|
||||
@@ -51,7 +47,7 @@ func test_nominal_and_invalid_wavs_are_discovered_but_never_playable() -> void:
|
||||
library.set_ambience_context("exploration")
|
||||
library.play_sfx("attack_given")
|
||||
|
||||
assert_eq(library.get_last_ambience_path(), nominal_path)
|
||||
assert_eq(library.get_last_sfx_path(), invalid_path)
|
||||
assert_eq(library.get_last_ambience_path(), "")
|
||||
assert_eq(library.get_last_sfx_path(), "")
|
||||
assert_false(library.has_playable_ambience())
|
||||
assert_false(library.has_playable_sfx())
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
extends GutTest
|
||||
|
||||
const AudioLibrary = preload("res://scripts/infrastructure/audio_library.gd")
|
||||
const AudioImportManifest = preload("res://scripts/infrastructure/audio_import_manifest.gd")
|
||||
|
||||
func test_imported_manifest_maps_only_known_ambience_and_sfx_to_godot_streams() -> void:
|
||||
var ambience_stream := _silent_stream()
|
||||
var sfx_stream := _silent_stream()
|
||||
var manifest := AudioImportManifest.new()
|
||||
|
||||
assert_true(manifest.register_ambience(&"combat", ambience_stream))
|
||||
assert_true(manifest.register_sfx(&"attack_given", sfx_stream))
|
||||
assert_false(manifest.register_ambience(&"unknown", ambience_stream))
|
||||
assert_false(manifest.register_sfx(&"unknown", sfx_stream))
|
||||
|
||||
var library := AudioLibrary.new(manifest)
|
||||
add_child_autofree(library)
|
||||
library.set_ambience_context("combat")
|
||||
library.play_sfx("attack_given")
|
||||
|
||||
assert_eq(library.get_ambience_stream(), ambience_stream)
|
||||
assert_eq(library.get_sfx_stream(), sfx_stream)
|
||||
assert_true(library.has_playable_ambience())
|
||||
assert_true(library.has_playable_sfx())
|
||||
assert_eq(library.get_ambience_player().bus, AudioLibrary.AMBIENCE_BUS)
|
||||
assert_eq(library.get_sfx_player().bus, AudioLibrary.SFX_BUS)
|
||||
|
||||
func test_setup_creates_the_private_user_audio_directory_for_manifest_assets() -> void:
|
||||
assert_eq(AudioImportManifest.ensure_user_audio_directory(), OK)
|
||||
assert_true(DirAccess.dir_exists_absolute(ProjectSettings.globalize_path(AudioImportManifest.USER_AUDIO_DIRECTORY)))
|
||||
var manifest := AudioImportManifest.new()
|
||||
assert_true(manifest.register_sfx(&"menu_select", _silent_stream()))
|
||||
assert_eq(manifest.sfx_for(&"menu_select").get_class(), "AudioStreamWAV")
|
||||
assert_eq(manifest.ambience_for(&"combat"), null)
|
||||
|
||||
func test_unregistered_external_audio_file_is_never_decoded_or_playable() -> void:
|
||||
var root := ProjectSettings.globalize_path("user://g3-unregistered-audio-%s" % Time.get_ticks_usec())
|
||||
var wav_path := root.path_join("audio/combat/external.wav")
|
||||
DirAccess.make_dir_recursive_absolute(wav_path.get_base_dir())
|
||||
var file := FileAccess.open(wav_path, FileAccess.WRITE)
|
||||
file.store_string("this must never be decoded by AudioLibrary")
|
||||
file.close()
|
||||
var library := AudioLibrary.new()
|
||||
add_child_autofree(library)
|
||||
|
||||
library.set_ambience_context("combat")
|
||||
library.play_sfx("attack_given")
|
||||
|
||||
assert_eq(library.get_ambience_stream(), null)
|
||||
assert_eq(library.get_sfx_stream(), null)
|
||||
assert_false(library.has_playable_ambience())
|
||||
assert_false(library.has_playable_sfx())
|
||||
|
||||
func _silent_stream() -> AudioStreamWAV:
|
||||
var stream := AudioStreamWAV.new()
|
||||
stream.format = AudioStreamWAV.FORMAT_16_BITS
|
||||
stream.mix_rate = 44100
|
||||
stream.stereo = false
|
||||
stream.data = PackedByteArray([0, 0, 0, 0])
|
||||
return stream
|
||||
@@ -0,0 +1 @@
|
||||
uid://b7ftt2slt52b0
|
||||
Reference in New Issue
Block a user