extract round speech code
This commit is contained in:
parent
14d0a31641
commit
bc30fbeb5c
|
@ -7,6 +7,7 @@ import { make as makeSocket, RoundSocket } from './socket';
|
|||
import * as title from './title';
|
||||
import * as promotion from './promotion';
|
||||
import * as blur from './blur';
|
||||
import * as speech from './speech';
|
||||
import * as cg from 'chessground/types';
|
||||
import { Config as CgConfig } from 'chessground/config';
|
||||
import { Api as CgApi } from 'chessground/api';
|
||||
|
@ -21,7 +22,6 @@ import { valid as crazyValid } from './crazy/crazyCtrl';
|
|||
import { ctrl as makeKeyboardMove, KeyboardMove } from './keyboardMove';
|
||||
import renderUser = require('./view/user');
|
||||
import cevalSub = require('./cevalSub');
|
||||
import viewStatus from 'game/view/status';
|
||||
import * as keyboard from './keyboard';
|
||||
|
||||
import { RoundOpts, RoundData, ApiMove, ApiEnd, Redraw, SocketMove, SocketDrop, SocketOpts, MoveMetadata, Position, NvuiPlugin } from './interfaces';
|
||||
|
@ -121,18 +121,7 @@ export default class RoundController {
|
|||
this.music = li.playMusic();
|
||||
});
|
||||
if (this.music && set !== 'music') this.music = undefined;
|
||||
|
||||
if (!window.Speech && set === 'speech')
|
||||
li.loadScript('compiled/lichess.round.speech.min.js').then(() => {
|
||||
const s = viewStatus(this);
|
||||
if (s == 'playingRightNow') window.Speech!.step(this.stepAt(this.ply), false);
|
||||
else {
|
||||
window.Speech!.say(s);
|
||||
const w = this.data.game.winner;
|
||||
if (w) window.Speech!.say(this.trans.noarg(w + 'IsVictorious'))
|
||||
}
|
||||
});
|
||||
if (window.Speech && set !== 'music') window.Speech = undefined;
|
||||
speech.onSoundSet(this, set);
|
||||
});
|
||||
|
||||
li.pubsub.on('zen', () => {
|
||||
|
@ -205,9 +194,7 @@ export default class RoundController {
|
|||
userJump = (ply: Ply): void => {
|
||||
this.cancelMove();
|
||||
this.chessground.selectSquare(null);
|
||||
if (this.jump(ply)) {
|
||||
if (window.Speech) window.Speech.step(this.stepAt(ply));
|
||||
}
|
||||
if (this.jump(ply)) speech.userJump(this, ply);
|
||||
else this.redraw();
|
||||
};
|
||||
|
||||
|
@ -454,7 +441,7 @@ export default class RoundController {
|
|||
this.onChange();
|
||||
if (this.keyboardMove) this.keyboardMove.update(step);
|
||||
if (this.music) this.music.jump(o);
|
||||
if (window.Speech) window.Speech.step(step, false);
|
||||
speech.step(step);
|
||||
};
|
||||
|
||||
private playPredrop = () => {
|
||||
|
@ -684,7 +671,7 @@ export default class RoundController {
|
|||
}
|
||||
};
|
||||
|
||||
private stepAt = (ply: Ply) => round.plyStep(this.data, ply);
|
||||
stepAt = (ply: Ply) => round.plyStep(this.data, ply);
|
||||
|
||||
private delayedInit = () => {
|
||||
const d = this.data;
|
||||
|
|
26
ui/round/src/speech.ts
Normal file
26
ui/round/src/speech.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import RoundController from './ctrl';
|
||||
import { Step } from './interfaces';
|
||||
import viewStatus from 'game/view/status';
|
||||
|
||||
export function onSoundSet(ctrl: RoundController, set: string) {
|
||||
if (!window.Speech && set === 'speech')
|
||||
window.lichess.loadScript('compiled/lichess.round.speech.min.js').then(() => {
|
||||
const s = viewStatus(ctrl);
|
||||
if (s == 'playingRightNow') window.Speech!.step(ctrl.stepAt(ctrl.ply), false);
|
||||
else {
|
||||
window.Speech!.say(s);
|
||||
const w = ctrl.data.game.winner;
|
||||
if (w) window.Speech!.say(ctrl.trans.noarg(w + 'IsVictorious'))
|
||||
}
|
||||
});
|
||||
if (window.Speech && set !== 'music') window.Speech = undefined;
|
||||
}
|
||||
|
||||
|
||||
export function userJump(ctrl: RoundController, ply: Ply) {
|
||||
if (window.Speech) window.Speech.step(ctrl.stepAt(ply));
|
||||
}
|
||||
|
||||
export function step(step: Step) {
|
||||
if (window.Speech) window.Speech.step(step, false);
|
||||
}
|
Loading…
Reference in a new issue