Randoloot/tests/levels/surface_audio_test.gd
2026-10-18 16:22:39 +02:00

63 lines
2.7 KiB
GDScript

extends Node
func _ready() -> void:
var progress: Resource = GameState.captain.expedition
for biome in 6:
var profile: Dictionary = preload("res://scripts/planets/planet_profiles.gd").generate(99,biome,"Audio test")
profile.temperature = 75 if biome == 4 else (-35 if biome == 5 else 20)
profile.oxygen = 90
progress.lander_hp = 100
assert(progress.begin_visit(profile))
progress.visit_seed = 200+biome
var surface := Control.new()
surface.set_script(preload("res://scripts/planets/surface_screen.gd"))
surface.captain = GameState.captain
surface.progress = progress
add_child(surface)
surface.set_physics_process(false)
var audio: Node = surface.get_node("SurfaceAudio")
assert(audio._streams.size() == 13 and audio._voices.size() == 3)
assert(audio._biome == biome)
assert(audio._wind.playing and audio._foliage.playing)
assert(audio._wind.stream.loop_mode == AudioStreamWAV.LOOP_FORWARD)
for id in audio._streams: assert(audio._streams[id] != null and audio._streams[id].get_length() > .1)
var choices: Array = audio.fauna_choices()
if biome == 2: assert(choices.has("marsh_call"))
else: assert(not choices.has("marsh_call"))
if biome == 4: assert(choices == ["insects"])
audio._oxygen = 0
assert(audio.fauna_choices().is_empty())
audio._oxygen = 90
# A treeless local clearing must not emit nearby leaves or creaks.
audio.set_process(false)
audio._near_trees.clear()
audio._density = 0
audio._next_fauna = INF
audio._next_gust = INF
audio._next_leaves = 0
audio._next_creak = 0
var before: int = audio.played_count
audio._process(.1)
assert(audio.played_count == before)
audio._near_trees.append(surface.lander.position+Vector2(100,0))
audio._next_leaves = 0
audio._process(.1)
assert(audio.played_count == before+1)
for index in 12: audio._play("leaves_1",Vector2(100,0),-20)
assert(audio._voices.size() == 3)
var world_reference: WeakRef = weakref(audio._world_audio)
audio.set_process(true)
var position_before: float = audio._wind.get_playback_position()
get_tree().paused = true
await get_tree().create_timer(.4,true).timeout
assert(audio.can_process() and audio._wind.can_process() and audio._wind.playing and not audio._wind.stream_paused)
assert(audio._wind.get_playback_position() > position_before)
get_tree().paused = false
progress.finish_visit(GameState.captain,false)
surface.queue_free()
await get_tree().process_frame
await get_tree().process_frame
assert(world_reference.get_ref() == null,"Nature emitters and listener must not survive leaving the surface")
print("SURFACE AUDIO PASS: six biomes, 13 streams, wind/foliage loops, local trees, biome fauna, low-oxygen suppression, bounded spatial voices, paused playback, cleanup after return")
get_tree().quit()