fix: harden S4 audio verification
This commit is contained in:
@@ -1,19 +1,29 @@
|
||||
extends GutTest
|
||||
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
const AudioLibrary = preload("res://scripts/infrastructure/audio_library.gd")
|
||||
var empty_audio_home := ""
|
||||
var previous_audio_home := ""
|
||||
var game: Game
|
||||
|
||||
func before_each() -> void:
|
||||
previous_audio_home = OS.get_environment("DCW_AUDIO_HOME")
|
||||
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()
|
||||
# Replace the scene library before ready to isolate both production search roots.
|
||||
var scene_audio := game.get_node("AudioLibrary")
|
||||
var isolated_audio := AudioLibrary.new(empty_audio_home)
|
||||
isolated_audio.name = "AudioLibrary"
|
||||
game.remove_child(scene_audio)
|
||||
scene_audio.free()
|
||||
game.add_child(isolated_audio)
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
|
||||
func after_each() -> void:
|
||||
OS.set_environment("DCW_AUDIO_HOME", "")
|
||||
OS.set_environment("DCW_AUDIO_HOME", previous_audio_home)
|
||||
|
||||
func test_real_game_resolves_combat_with_empty_audio_home() -> void:
|
||||
var audio = game.get_node("AudioLibrary")
|
||||
|
||||
@@ -25,6 +25,24 @@ func test_unknown_requests_are_silent() -> void:
|
||||
assert_eq(library.get_last_ambience_path(), "")
|
||||
assert_eq(library.get_last_sfx_path(), "")
|
||||
|
||||
func test_invalid_wav_is_not_selected_or_played_and_does_not_block_requests() -> void:
|
||||
var root := ProjectSettings.globalize_path("user://s4-invalid-audio-library")
|
||||
var invalid_path := root.path_join("audio/exploration/not-a-wave.wav")
|
||||
DirAccess.make_dir_recursive_absolute(invalid_path.get_base_dir())
|
||||
var invalid_file := FileAccess.open(invalid_path, FileAccess.WRITE)
|
||||
invalid_file.store_string("this is not a WAV file")
|
||||
invalid_file.close()
|
||||
var library := AudioLibrary.new(root)
|
||||
add_child_autofree(library)
|
||||
|
||||
library.set_ambience_context("exploration")
|
||||
library.play_sfx("attack_given")
|
||||
|
||||
assert_eq(library.get_last_ambience_path(), "")
|
||||
assert_eq(library.get_last_sfx_path(), "")
|
||||
assert_false(library._ambience_player.playing)
|
||||
assert_false(library._sfx_player.playing)
|
||||
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user