From fc77f1e7c747422b8885bb549871e79ca8972fce Mon Sep 17 00:00:00 2001 From: Jonathan Gamble Date: Fri, 22 Nov 2024 16:17:35 -0600 Subject: [PATCH 1/3] 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 { From cd7919702b84fbeb7acc9ebe1328a1d739f4af45 Mon Sep 17 00:00:00 2001 From: Jonathan Gamble Date: Fri, 22 Nov 2024 16:32:55 -0600 Subject: [PATCH 2/3] support initialFen and remove filter from soundMove.ts --- ui/bits/src/bits.soundMove.ts | 1 - ui/round/src/ctrl.ts | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 de6331ad6061..b2902236175a 100644 --- a/ui/round/src/ctrl.ts +++ b/ui/round/src/ctrl.ts @@ -174,7 +174,12 @@ export default class RoundController implements MoveRootCtrl { atomic.capture(this, dest); return; } - const san = sanOf(readFen(this.stepAt(this.ply - 1).fen), orig + dest); + const fen = + this.ply === 0 + ? (this.data.game.initialFen ?? 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR') + : this.stepAt(this.ply - 1).fen; + const san = sanOf(readFen(fen), orig + dest); + site.sound.move({ san, uci: orig + dest }); site.sound.saySan(san); }; From 6006b58eb88c6631f2963cb6be3520d83d376a3d Mon Sep 17 00:00:00 2001 From: Jonathan Gamble Date: Sat, 23 Nov 2024 07:23:32 -0600 Subject: [PATCH 3/3] use d.game.fen for ply 0 as d.game.initialFen is not always defined --- ui/round/src/ctrl.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ui/round/src/ctrl.ts b/ui/round/src/ctrl.ts index b2902236175a..5da7a1c1d418 100644 --- a/ui/round/src/ctrl.ts +++ b/ui/round/src/ctrl.ts @@ -174,10 +174,7 @@ export default class RoundController implements MoveRootCtrl { atomic.capture(this, dest); return; } - const fen = - this.ply === 0 - ? (this.data.game.initialFen ?? 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR') - : this.stepAt(this.ply - 1).fen; + 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 });