Skip to content

Commit

Permalink
Merge pull request lichess-org#12277 from 370417/pentatonic-puzzles
Browse files Browse the repository at this point in the history
Pentatonic sound for puzzles
  • Loading branch information
ornicar authored Jan 29, 2023
2 parents 20614f0 + ab22bfc commit 258eb83
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 72 deletions.
68 changes: 0 additions & 68 deletions public/javascripts/music/replay.js

This file was deleted.

6 changes: 3 additions & 3 deletions ui/analyse/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ export default class AnalyseCtrl {

lichess.pubsub.on('sound_set', (set: string) => {
if (!this.music && set === 'music')
lichess.loadScript('javascripts/music/replay.js').then(() => {
this.music = window.lichessReplayMusic();
lichess.loadScript('javascripts/music/play.js').then(() => {
this.music = lichess.playMusic();
});
if (this.music && set !== 'music') this.music = null;
if (this.music && set !== 'music') this.music = undefined;
});

lichess.pubsub.on('ply.trigger', () =>
Expand Down
11 changes: 11 additions & 0 deletions ui/puzzle/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default function (opts: PuzzleOpts, redraw: Redraw): Controller {
good: loadSound('lisp/PuzzleStormGood', 0.7, 500),
end: loadSound('lisp/PuzzleStormEnd', 1, 1000),
};
let music: any;

let flipped = false;

Expand Down Expand Up @@ -255,6 +256,7 @@ export default function (opts: PuzzleOpts, redraw: Redraw): Controller {
reorderChildren(path);
redraw();
speech.node(node, false);
if (music) music.jump(node);
}

function reorderChildren(path: Tree.Path, recursive?: boolean): void {
Expand Down Expand Up @@ -477,6 +479,7 @@ export default function (opts: PuzzleOpts, redraw: Redraw): Controller {
withGround(g => g.selectSquare(null));
jump(path);
speech.node(vm.node, true);
if (music) music.jump(vm.node);
}

function userJumpPlyDelta(plyDelta: Ply) {
Expand Down Expand Up @@ -580,6 +583,14 @@ export default function (opts: PuzzleOpts, redraw: Redraw): Controller {

speech.setup();

lichess.pubsub.on('sound_set', (set: string) => {
if (!music && set === 'music')
lichess.loadScript('javascripts/music/play.js').then(() => {
music = lichess.playMusic();
});
if (music && set !== 'music') music = undefined;
});

lichess.pubsub.on('zen', () => {
const zen = $('body').toggleClass('zen').hasClass('zen');
window.dispatchEvent(new Event('resize'));
Expand Down
2 changes: 1 addition & 1 deletion ui/round/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default class RoundController {
this.redraw();
});

lichess.pubsub.on('sound_set', set => {
lichess.pubsub.on('sound_set', (set: string) => {
if (!this.music && set === 'music')
lichess.loadScript('javascripts/music/play.js').then(() => {
this.music = lichess.playMusic();
Expand Down
10 changes: 10 additions & 0 deletions ui/storm/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Clock } from 'puz/clock';
import { Combo } from 'puz/combo';
import { getNow, puzzlePov, sound } from 'puz/util';
import { makeCgOpts } from 'puz/run';
import { makeSan } from 'chessops/san';
import { parseUci } from 'chessops/util';
import { PromotionCtrl } from 'chess/promotion';
import { prop, Prop } from 'common';
Expand All @@ -18,6 +19,7 @@ import { StormOpts, StormData, StormVm, StormRecap, StormPrefs } from './interfa
export default class StormCtrl implements PuzCtrl {
private data: StormData;
private redraw: () => void;
private music?: any;
pref: StormPrefs;
run: Run;
vm: StormVm;
Expand Down Expand Up @@ -63,6 +65,13 @@ export default class StormCtrl implements PuzCtrl {
this.redraw();
}
}, config.timeToStart + 1000);
lichess.pubsub.on('sound_set', (set: string) => {
if (!this.music && set === 'music')
lichess.loadScript('javascripts/music/play.js').then(() => {
this.music = lichess.playMusic();
});
if (this.music && set !== 'music') this.music = undefined;
});
lichess.pubsub.on('zen', () => {
const zen = $('body').toggleClass('zen').hasClass('zen');
window.dispatchEvent(new Event('resize'));
Expand Down Expand Up @@ -140,6 +149,7 @@ export default class StormCtrl implements PuzCtrl {
if (this.run.clock.flag()) this.end();
else if (!this.incPuzzle()) this.end();
}
if (this.music) this.music.jump({ san: makeSan(pos, move), uci });
this.redraw();
this.redrawQuick();
this.redrawSlow();
Expand Down

0 comments on commit 258eb83

Please sign in to comment.