give puzzles a voice
This commit is contained in:
parent
50b874bfb3
commit
981f4b5880
|
@ -13,6 +13,6 @@ export function node(n: Tree.Node) {
|
|||
withSpeech(s => s.step(n, true));
|
||||
}
|
||||
|
||||
export function withSpeech(f: (speech: LichessSpeech) => void) {
|
||||
function withSpeech(f: (speech: LichessSpeech) => void) {
|
||||
if (window.LichessSpeech) f(window.LichessSpeech);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import { prop } from 'common';
|
|||
import { storedProp } from 'common/storage';
|
||||
import throttle from 'common/throttle';
|
||||
import * as xhr from './xhr';
|
||||
import * as speech from './speech';
|
||||
import { sound } from './sound';
|
||||
import { Api as CgApi } from 'chessground/api';
|
||||
import * as cg from 'chessground/types';
|
||||
|
@ -162,6 +163,7 @@ export default function(opts, redraw: () => void): Controller {
|
|||
var progress = moveTest();
|
||||
if (progress) applyProgress(progress);
|
||||
redraw();
|
||||
speech.node(node, false);
|
||||
};
|
||||
|
||||
function reorderChildren(path: Tree.Path, recursive?: boolean) {
|
||||
|
@ -222,6 +224,7 @@ export default function(opts, redraw: () => void): Controller {
|
|||
vm.round = res.round;
|
||||
vm.voted = res.voted;
|
||||
redraw();
|
||||
if (win) speech.success();
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -369,6 +372,7 @@ export default function(opts, redraw: () => void): Controller {
|
|||
g.selectSquare(null);
|
||||
});
|
||||
jump(path);
|
||||
speech.node(vm.node, true);
|
||||
};
|
||||
|
||||
function viewSolution() {
|
||||
|
@ -450,6 +454,8 @@ export default function(opts, redraw: () => void): Controller {
|
|||
});
|
||||
});
|
||||
|
||||
speech.setup();
|
||||
|
||||
return {
|
||||
vm,
|
||||
getData() {
|
||||
|
|
22
ui/puzzle/src/speech.ts
Normal file
22
ui/puzzle/src/speech.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
export function setup() {
|
||||
window.lichess.pubsub.on('speech.enabled', onSpeechChange);
|
||||
onSpeechChange(window.lichess.sound.speech());
|
||||
}
|
||||
|
||||
function onSpeechChange(enabled: boolean) {
|
||||
if (!window.LichessSpeech && enabled)
|
||||
window.lichess.loadScript(window.lichess.compiledScript('speech'));
|
||||
else if (window.LichessSpeech && !enabled) window.LichessSpeech = undefined;
|
||||
}
|
||||
|
||||
export function node(n: Tree.Node, cut: boolean) {
|
||||
withSpeech(s => s.step(n, cut));
|
||||
}
|
||||
|
||||
export function success() {
|
||||
withSpeech(s => s.say("Success!", false));
|
||||
}
|
||||
|
||||
function withSpeech(f: (speech: LichessSpeech) => void) {
|
||||
if (window.LichessSpeech) f(window.LichessSpeech);
|
||||
}
|
|
@ -36,6 +36,6 @@ export function step(step: Step) {
|
|||
withSpeech(s => s.step(step, false));
|
||||
}
|
||||
|
||||
export function withSpeech(f: (speech: LichessSpeech) => void) {
|
||||
function withSpeech(f: (speech: LichessSpeech) => void) {
|
||||
if (window.LichessSpeech) f(window.LichessSpeech);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue