Apply clock announcement spatial range from server
This commit is contained in:
@@ -13,14 +13,14 @@ export class ClockAnnouncer {
|
||||
private readonly getListenerPosition: ListenerPositionGetter,
|
||||
) {}
|
||||
|
||||
async playSequence(sounds: string[], sourceX: number, sourceY: number): Promise<void> {
|
||||
async playSequence(sounds: string[], sourceX: number, sourceY: number, range?: number): Promise<void> {
|
||||
if (sounds.length === 0) return;
|
||||
const token = ++this.playToken;
|
||||
const effectiveRange = Number.isFinite(range) && (range as number) > 0 ? (range as number) : undefined;
|
||||
for (const sound of sounds) {
|
||||
if (token !== this.playToken) return;
|
||||
const listener = this.getListenerPosition();
|
||||
await this.audio.playSpatialSampleAndWait(sound, { x: sourceX, y: sourceY }, listener, 1);
|
||||
await this.audio.playSpatialSampleAndWait(sound, { x: sourceX, y: sourceY }, listener, 1, effectiveRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1660,8 +1660,8 @@ const onAppMessage = createOnMessageHandler({
|
||||
playIncomingItemUseSound: (url, x, y, range) => {
|
||||
void audio.playSpatialSample(url, { x, y }, { x: state.player.x, y: state.player.y }, 1, range ?? HEARING_RADIUS);
|
||||
},
|
||||
playClockAnnouncement: (sounds, x, y) => {
|
||||
void clockAnnouncer.playSequence(sounds.map(resolveIncomingSoundUrl), x, y);
|
||||
playClockAnnouncement: (sounds, x, y, range) => {
|
||||
void clockAnnouncer.playSequence(sounds.map(resolveIncomingSoundUrl), x, y, range);
|
||||
},
|
||||
handleAuthRequired,
|
||||
handleAuthResult,
|
||||
|
||||
@@ -69,7 +69,7 @@ type MessageHandlerDeps = {
|
||||
playLocateToneAt: (x: number, y: number) => void;
|
||||
resolveIncomingSoundUrl: (url: string) => string;
|
||||
playIncomingItemUseSound: (url: string, x: number, y: number, range?: number) => void;
|
||||
playClockAnnouncement: (sounds: string[], x: number, y: number) => void;
|
||||
playClockAnnouncement: (sounds: string[], x: number, y: number, range?: number) => void;
|
||||
handleAuthRequired: (message: Extract<IncomingMessage, { type: 'auth_required' }>) => void;
|
||||
handleAuthResult: (message: Extract<IncomingMessage, { type: 'auth_result' }>) => Promise<void>;
|
||||
isPeerNegotiationReady: () => boolean;
|
||||
@@ -310,7 +310,7 @@ export function createOnMessageHandler(deps: MessageHandlerDeps): (message: Inco
|
||||
|
||||
case 'item_clock_announce': {
|
||||
if (!deps.getAudioLayers().world) break;
|
||||
deps.playClockAnnouncement(message.sounds, message.x, message.y);
|
||||
deps.playClockAnnouncement(message.sounds, message.x, message.y, message.range);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -222,6 +222,7 @@ export const itemClockAnnounceSchema = z.object({
|
||||
sounds: z.array(z.string()),
|
||||
x: z.number().int(),
|
||||
y: z.number().int(),
|
||||
range: z.number().int().positive().optional(),
|
||||
});
|
||||
|
||||
export const itemPianoNoteSchema = z.object({
|
||||
|
||||
Reference in New Issue
Block a user