Offset on sounds api
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user