Files
DungeonCrawlerWorld/tests/e2e/test_audio_settings_e2e.gd
T

66 lines
2.4 KiB
GDScript

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_bundled_music_switches_from_exploration_to_combat() -> void:
var audio := game.get_node("AudioLibrary") as AudioLibrary
var exploration_stream := audio.get_ambience_stream()
assert_not_null(exploration_stream)
assert_string_contains(exploration_stream.resource_path, "dungeon_exploration.wav")
var state := game.get_game_state()
var enemy: ActorState = state.enemies[&"goblin"]
enemy.cell = state.player.cell + Vector2i.RIGHT
game.submit_test_action(Vector2i.RIGHT)
assert_eq(audio.current_ambience_context, "combat")
assert_string_contains(audio.get_ambience_stream().resource_path, "dungeon_combat.wav")
assert_true(audio.get_ambience_player().playing)
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