From fc77f1e7c747422b8885bb549871e79ca8972fce Mon Sep 17 00:00:00 2001 From: Jonathan Gamble Date: Fri, 22 Nov 2024 16:17:35 -0600 Subject: [PATCH] remove unnecessary "music only" call to sound.move --- ui/@types/lichess/index.d.ts | 1 - ui/round/src/ctrl.ts | 16 ++++++++-------- ui/site/src/sound.ts | 26 +++++++++++++------------- 3 files changed, 21 insertions(+), 22 deletions(-) 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/round/src/ctrl.ts b/ui/round/src/ctrl.ts index 7711b941087a..de6331ad6061 100644 --- a/ui/round/src/ctrl.ts +++ b/ui/round/src/ctrl.ts @@ -169,12 +169,14 @@ 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 san = sanOf(readFen(this.stepAt(this.ply - 1).fen), orig + dest); + site.sound.move({ san, uci: orig + dest }); + site.sound.saySan(san); }; private startPromotion = (orig: Key, dest: Key, meta: MoveMetadata) => @@ -490,8 +492,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 {