extends TestCase ## A8: the score builds with the tide, quiet in play and full in menus and results. var tree: SceneTree func before_each() -> void: super.before_each() tree = Engine.get_main_loop() as SceneTree func _game(phase: int, tide_tick: int = -1) -> ClientGame: var game: ClientGame = ClientGame.new() game.world = Simulation.new(3, SimGround.flat(0.0)) game.match_phase = phase if tide_tick >= 0: game.world.tide = Tide.new(0) game.world.tick = tide_tick return game func test_intensity_by_moment() -> void: assert_eq(MusicDirector.intensity_for(null), 3, "menus are fullest") assert_eq(MusicDirector.intensity_for(_game(Match.LOBBY)), 1) assert_eq(MusicDirector.intensity_for(_game(Match.RESULTS)), 3) var tide: Tide = Tide.new(0) assert_eq(MusicDirector.intensity_for(_game(Match.PLAY, 10)), 0, "a holding tide: the drone alone") var rising: int = tide.ticks_until_rise(0) + 5 assert_eq(MusicDirector.intensity_for(_game(Match.PLAY, rising)), 1, "the drum comes in as the sea rises") var levels: Array[int] = [] var tick: int = 0 while tide.stage_at(tick) != Tide.SUDDEN_DEATH: levels.append(MusicDirector.intensity_for(_game(Match.PLAY, tick))) tick += Tuning.TICK_RATE_HZ * 5 levels.append(MusicDirector.intensity_for(_game(Match.PLAY, tick))) for index: int in range(1, levels.size()): assert_true(levels[index] >= levels[index - 1], "never falls back as the tide goes on: %s" % [levels]) assert_eq(levels[levels.size() - 1], 3, "the whole tune for the last land") assert_true(levels.has(2), "the concertina in the middle phases") func test_layers_fade_toward_the_intensity_and_play_on_the_music_bus() -> void: var music: MusicDirector = MusicDirector.new() tree.root.add_child(music) assert_eq(String(music.player.bus), SoundBank.MUSIC_BUS) assert_true(music.player.stream is AudioStreamSynchronized) var game: ClientGame = _game(Match.PLAY, 10) music.update(game, 1.0) assert_near(music.gains[0], 1.0 / MusicDirector.FADE_SECONDS, 0.001, "fading, not switching") for frame: int in 10: music.update(game, 1.0) assert_eq(Array(music.gains), [1.0, 0.0, 0.0, 0.0]) assert_true(music.in_match) for frame: int in 10: music.update(null, 1.0) assert_eq(Array(music.gains), [1.0, 1.0, 1.0, 1.0], "menus have everything") assert_false(music.in_match) music.free() SoundBank.clear()