Skip to content

Commit

Permalink
remove unnecessary "music only" call to sound.move
Browse files Browse the repository at this point in the history
  • Loading branch information
schlawg committed Nov 22, 2024
1 parent 666866c commit fc77f1e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
1 change: 0 additions & 1 deletion ui/@types/lichess/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ type SoundMoveOpts = {
san?: string;
uci?: string;
volume?: number;
filter?: 'music' | 'game';
};

type SoundMove = (opts?: SoundMoveOpts) => void;
Expand Down
16 changes: 8 additions & 8 deletions ui/round/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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
};

Expand Down
26 changes: 13 additions & 13 deletions ui/site/src/sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SoundMove>('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<SoundMove>('bits.soundMove');
this.music(o);
}

async playAndDelayMateResultIfNecessary(name: Name): Promise<void> {
Expand Down

0 comments on commit fc77f1e

Please sign in to comment.