Offset on sounds api

This commit is contained in:
2026-11-22 08:35:54 -03:00
parent d18fe19027
commit 5d374091cd
5 changed files with 58 additions and 4 deletions
+21
View File
@@ -175,6 +175,27 @@ Deno.test("a loop out of range waits, and comes back as far in as it would have
assertEquals(output.playing[0].settings.offset, 10);
});
Deno.test("a sound played with an offset starts as if it had started that long ago", () => {
const { client, output, time } = client_sounds([{ id: "noisy:theme", range: 10 }]);
client.frame(at(0), () => undefined, VOLUMES);
time.now = 100;
client.play("noisy:theme", { offset: 12 });
// its file at twice the speed is twice as far in
client.play("noisy:theme", { offset: 12, pitch: 2 });
assertEquals(output.voices.map((voice) => voice.settings.offset), [12, 24]);
// a loop coming back in range keeps counting from when it would have started
output.voices.length = 0;
client.play("noisy:theme", { at: { x: 0, y: 0, z: 0 }, loop: true, offset: 30 });
time.now = 103;
client.frame(at(50), () => undefined, VOLUMES);
time.now = 105;
client.frame(at(1), () => undefined, VOLUMES);
assertEquals(output.playing.at(-1)!.settings.offset, 35);
assertThrows(() => client.play("noisy:theme", { offset: -1 }), Error, "offset");
});
Deno.test("a loop played before anything can play starts once it can, and a one-off is dropped", () => {
const { client, output } = client_sounds([{ id: "noisy:hum" }, { id: "noisy:thud" }]);
output.ready = false;