74 lines
3.1 KiB
GDScript
74 lines
3.1 KiB
GDScript
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-%s" % Time.get_ticks_usec())
|
|
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 the no-audio fallback.
|
|
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", previous_audio_home)
|
|
|
|
func test_real_game_resolves_combat_with_empty_audio_home() -> void:
|
|
var audio = game.get_node("AudioLibrary")
|
|
|
|
var state := game.get_game_state()
|
|
state.enemies[&"goblin"].cell = state.player.cell + Vector2i(2, 0)
|
|
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(), "")
|
|
assert_false(audio.has_playable_ambience())
|
|
assert_false(audio.has_playable_sfx())
|
|
|
|
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/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_string("untrusted external WAV")
|
|
nominal_file.close()
|
|
var invalid_file := FileAccess.open(invalid_path, FileAccess.WRITE)
|
|
invalid_file.store_string("truncated WAV")
|
|
invalid_file.close()
|
|
|
|
var state := game.get_game_state()
|
|
state.enemies[&"goblin"].cell = state.player.cell + Vector2i(2, 0)
|
|
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"))
|
|
audio.set_ambience_context("combat")
|
|
audio.play_sfx("attack_given")
|
|
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())
|