本文整理汇总了TypeScript中game.game.replayable方法的典型用法代码示例。如果您正苦于以下问题:TypeScript game.replayable方法的具体用法?TypeScript game.replayable怎么用?TypeScript game.replayable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类game.game
的用法示例。
在下文中一共展示了game.replayable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: analysisButton
function analysisButton(ctrl: RoundController): VNode | null {
const d = ctrl.data,
url = router.game(d, analysisBoardOrientation(d)) + '#' + ctrl.ply;
return game.replayable(d) ? h('a.button', {
attrs: { href: url },
hook: util.bind('click', _ => {
// force page load in case the URL is the same
if (location.pathname === url.split('#')[0]) location.reload();
})
}, ctrl.trans.noarg('analysis')) : null;
}
示例2: function
export default function(root: AnalyseCtrl, opts, allow: boolean): ExplorerCtrl {
const allowed = prop(allow),
enabled = root.embed ? prop(false) : storedProp('explorer.enabled', false),
loading = prop(true),
failing = prop(false),
hovering = prop<Hovering | null>(null),
movesAway = prop(0),
gameMenu = prop<string | null>(null);
if ((location.hash === '#explorer' || location.hash === '#opening') && !root.embed) enabled(true);
let cache = {};
function onConfigClose() {
root.redraw();
cache = {};
setNode();
}
const withGames = synthetic(root.data) || gameUtil.replayable(root.data) || !!root.data.opponent.ai;
const effectiveVariant = root.data.game.variant.key === 'fromPosition' ? 'standard' : root.data.game.variant.key;
const config = configCtrl(root.data.game, onConfigClose, root.trans, root.redraw);
const fetch = window.lichess.fp.debounce(function() {
const fen = root.node.fen;
const request: JQueryPromise<ExplorerData> = (withGames && tablebaseRelevant(effectiveVariant, fen)) ?
xhr.tablebase(opts.tablebaseEndpoint, effectiveVariant, fen) :
xhr.opening(opts.endpoint, effectiveVariant, fen, config.data, withGames);
request.then((res: ExplorerData) => {
cache[fen] = res;
movesAway(res.moves.length ? 0 : movesAway() + 1);
loading(false);
failing(false);
root.redraw();
}, () => {
loading(false);
failing(true);
root.redraw();
});
}, 250, true);
const empty = {
opening: true,
moves: {}
};
function setNode() {
if (!enabled()) return;
gameMenu(null);
const node = root.node;
if (node.ply > 50 && !tablebaseRelevant(effectiveVariant, node.fen)) {
cache[node.fen] = empty;
}
const cached = cache[root.node.fen];
if (cached) {
movesAway(cached.moves.length ? 0 : movesAway() + 1);
loading(false);
failing(false);
} else {
loading(true);
fetch();
}
};
return {
allowed,
enabled,
setNode,
loading,
failing,
hovering,
movesAway,
config,
withGames,
gameMenu,
current: () => cache[root.node.fen],
toggle() {
movesAway(0);
enabled(!enabled());
setNode();
root.autoScroll();
},
disable() {
if (enabled()) {
enabled(false);
gameMenu(null);
root.autoScroll();
}
},
setHovering(fen, uci) {
hovering(uci ? {
fen,
uci,
} : null);
root.setAutoShapes();
},
fetchMasterOpening: (function() {
const masterCache = {};
return (fen: Fen): JQueryPromise<OpeningData> => {
if (masterCache[fen]) return $.Deferred().resolve(masterCache[fen]).promise() as JQueryPromise<OpeningData>;
//.........这里部分代码省略.........