diff --git a/ui/@types/lichess/index.d.ts b/ui/@types/lichess/index.d.ts index b46e01beb3ef..ec2affe1e3b1 100644 --- a/ui/@types/lichess/index.d.ts +++ b/ui/@types/lichess/index.d.ts @@ -91,7 +91,6 @@ type SoundMoveOpts = { san?: string; uci?: string; volume?: number; - filter?: 'music' | 'game'; }; type SoundMove = (opts?: SoundMoveOpts) => void; diff --git a/ui/bits/src/bits.soundMove.ts b/ui/bits/src/bits.soundMove.ts index f38081abd29f..2715f9f2f62a 100644 --- a/ui/bits/src/bits.soundMove.ts +++ b/ui/bits/src/bits.soundMove.ts @@ -51,7 +51,6 @@ export async function initModule(): Promise { await Promise.all(promises); return o => { - if (o?.filter === 'game') return; const volume = o?.volume ?? 1; if (o?.san && o.uci) { const pitch = keyToPitch(o.uci.slice(2)); diff --git a/ui/round/src/ctrl.ts b/ui/round/src/ctrl.ts index 7711b941087a..5da7a1c1d418 100644 --- a/ui/round/src/ctrl.ts +++ b/ui/round/src/ctrl.ts @@ -169,12 +169,16 @@ export default class RoundController implements MoveRootCtrl { }; private onMove = (orig: Key, dest: Key, captured?: Piece) => { - if (captured || this.enpassant(orig, dest)) { - if (this.data.game.variant.key === 'atomic') { - site.sound.play('explosion'); - atomic.capture(this, dest); - } else site.sound.move({ name: 'capture', filter: 'game' }); - } else site.sound.move({ name: 'move', filter: 'game' }); + if ((captured || this.enpassant(orig, dest)) && this.data.game.variant.key === 'atomic') { + site.sound.play('explosion'); + atomic.capture(this, dest); + return; + } + const fen = this.ply === 0 ? this.data.game.fen : this.stepAt(this.ply - 1).fen; + const san = sanOf(readFen(fen), orig + dest); + + site.sound.move({ san, uci: orig + dest }); + site.sound.saySan(san); }; private startPromotion = (orig: Key, dest: Key, meta: MoveMetadata) => @@ -490,8 +494,6 @@ export default class RoundController implements MoveRootCtrl { this.autoScroll(); this.onChange(); this.pluginUpdate(step.fen); - if (!this.opts.local) site.sound.move({ ...o, filter: 'music' }); - site.sound.saySan(step.san); return true; // prevents default socket pubsub }; diff --git a/ui/site/src/sound.ts b/ui/site/src/sound.ts index 2ecbcd272f2d..028b4b38c225 100644 --- a/ui/site/src/sound.ts +++ b/ui/site/src/sound.ts @@ -72,21 +72,21 @@ export default new (class implements SoundI { async move(o?: SoundMoveOpts) { const volume = o?.volume ?? 1; - if (o?.filter !== 'music' && this.theme !== 'music') { - if (o?.name) this.throttled(o.name, volume); - else { - if (o?.san?.includes('x')) this.throttled('capture', volume); - else this.throttled('move', volume); - if (o?.san?.includes('#')) { - this.throttled('checkmate', volume); - } else if (o?.san?.includes('+')) { - this.throttled('check', volume); - } + if (this.theme === 'music') { + this.music ??= await site.asset.loadEsm('bits.soundMove'); + this.music(o); + return; + } + if (o?.name) this.throttled(o.name, volume); + else { + if (o?.san?.includes('x')) this.throttled('capture', volume); + else this.throttled('move', volume); + if (o?.san?.includes('#')) { + this.throttled('checkmate', volume); + } else if (o?.san?.includes('+')) { + this.throttled('check', volume); } } - if (o?.filter === 'game' || this.theme !== 'music') return; - this.music ??= await site.asset.loadEsm('bits.soundMove'); - this.music(o); } async playAndDelayMateResultIfNecessary(name: Name): Promise {