本文整理汇总了TypeScript中game.game.setOnGame方法的典型用法代码示例。如果您正苦于以下问题:TypeScript game.setOnGame方法的具体用法?TypeScript game.setOnGame怎么用?TypeScript game.setOnGame使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类game.game
的用法示例。
在下文中一共展示了game.setOnGame方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: make
export function make(send: SocketSend, ctrl: RoundController): RoundSocket {
function reload(o: Incoming, isRetry?: boolean) {
// avoid reload if possible!
if (o && o.t) {
ctrl.setLoading(false);
handlers[o.t](o.d);
}
else xhr.reload(ctrl).then(data => {
if (li.socket.getVersion() > data.player.version) {
// race condition! try to reload again
if (isRetry) li.reload(); // give up and reload the page
else reload(o, true);
}
else ctrl.reload(data);
});
};
const handlers: Handlers = {
takebackOffers(o) {
ctrl.setLoading(false);
ctrl.data.player.proposingTakeback = o[ctrl.data.player.color];
const fromOp = ctrl.data.opponent.proposingTakeback = o[ctrl.data.opponent.color];
if (fromOp) li.desktopNotification(ctrl.trans.noarg('yourOpponentProposesATakeback'));
ctrl.redraw();
},
move: ctrl.apiMove,
drop: ctrl.apiMove,
reload,
redirect: ctrl.setRedirecting,
clockInc(o) {
if (ctrl.clock) {
ctrl.clock.addTime(o.color, o.time);
ctrl.redraw();
}
},
cclock(o) {
if (ctrl.corresClock) {
ctrl.data.correspondence.white = o.white;
ctrl.data.correspondence.black = o.black;
ctrl.corresClock.update(o.white, o.black);
ctrl.redraw();
}
},
crowd(o) {
game.setOnGame(ctrl.data, 'white', o['white']);
game.setOnGame(ctrl.data, 'black', o['black']);
ctrl.redraw();
},
// end: function(winner) { } // use endData instead
endData(o: ApiEnd) {
ctrl.endWithData(o);
},
rematchOffer(by: Color) {
ctrl.data.player.offeringRematch = by === ctrl.data.player.color;
const fromOp = ctrl.data.opponent.offeringRematch = by === ctrl.data.opponent.color;
if (fromOp) li.desktopNotification(ctrl.trans.noarg('yourOpponentWantsToPlayANewGameWithYou'));
ctrl.redraw();
},
rematchTaken(nextId: string) {
ctrl.data.game.rematch = nextId;
if (!ctrl.data.player.spectator) ctrl.setLoading(true);
else ctrl.redraw();
},
drawOffer(by) {
ctrl.data.player.offeringDraw = by === ctrl.data.player.color;
const fromOp = ctrl.data.opponent.offeringDraw = by === ctrl.data.opponent.color;
if (fromOp) li.desktopNotification(ctrl.trans.noarg('yourOpponentOffersADraw'));
ctrl.redraw();
},
berserk(color: Color) {
ctrl.setBerserk(color);
},
gone(isGone) {
if (!ctrl.data.opponent.ai) {
game.setIsGone(ctrl.data, ctrl.data.opponent.color, isGone);
ctrl.redraw();
}
},
checkCount(e) {
ctrl.data.player.checks = ctrl.data.player.color == 'white' ? e.white : e.black;
ctrl.data.opponent.checks = ctrl.data.opponent.color == 'white' ? e.white : e.black;
ctrl.redraw();
},
simulPlayerMove(gameId: string) {
if (
ctrl.opts.userId &&
ctrl.data.simul &&
ctrl.opts.userId == ctrl.data.simul.hostId &&
gameId !== ctrl.data.game.id &&
ctrl.moveOn.get() &&
ctrl.chessground.state.turnColor !== ctrl.chessground.state.movable.color) {
ctrl.setRedirecting();
sound.move();
li.hasToReload = true;
location.href = '/' + gameId;
}
},
simulEnd(simul: Simul) {
$.modal($(
//.........这里部分代码省略.........