Offset on sounds api
This commit is contained in:
+7
-2
@@ -40,7 +40,8 @@ export interface VoiceSettings {
|
||||
volume: number;
|
||||
pitch: number;
|
||||
loop: boolean;
|
||||
// seconds into the file it starts at, for a loop coming back partway. past the file's length it goes around
|
||||
// seconds into the file it starts at, for one played with an offset or a loop coming back partway. past the file's
|
||||
// length a loop goes around, and anything else has finished
|
||||
offset: number;
|
||||
}
|
||||
|
||||
@@ -157,12 +158,16 @@ export class Sounds {
|
||||
|
||||
play(sound: string, options: ClientPlayOptions = {}): PlayingSound {
|
||||
const json = sound_to_play(sound, options);
|
||||
const offset = options.offset ?? 0;
|
||||
if (typeof offset !== "number" || !(offset >= 0) || !Number.isFinite(offset)) {
|
||||
throw new Error("a sound's offset must be 0 or more seconds");
|
||||
}
|
||||
const path = json.files[Math.floor(Math.random() * json.files.length)];
|
||||
const file = this.#files.get(`${sound.split(":")[0]}:${path}`);
|
||||
if (!file) throw new Error(`sound ${sound} has no file ${path}`);
|
||||
|
||||
const at = options.follow !== undefined ? this.#entity_position(options.follow) : options.at;
|
||||
const playing = new Playing(json, file, { ...options }, this.clock(), at && { ...at });
|
||||
const playing = new Playing(json, file, { ...options }, this.clock() - offset, at && { ...at });
|
||||
this.#playing.push(playing);
|
||||
// an entity this client doesn't have yet, like one whose animator is being made, has until the next frame to
|
||||
// turn up
|
||||
|
||||
Reference in New Issue
Block a user