本文整理汇总了TypeScript中chessground/util.key2pos函数的典型用法代码示例。如果您正苦于以下问题:TypeScript key2pos函数的具体用法?TypeScript key2pos怎么用?TypeScript key2pos使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了key2pos函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: renderPromotion
function renderPromotion(dest, pieces, color, orientation) {
if (!promoting) return;
let left = (8 - cgUtil.key2pos(dest)[0]) * 12.5;
if (orientation === 'white') left = 87.5 - left;
const vertical = color === orientation ? 'top' : 'bottom';
return h('div#promotion-choice.' + vertical, {
hook: onInsert(el => {
el.addEventListener('click', cancel);
el.oncontextmenu = () => false;
})
}, pieces.map(function(serverRole, i) {
const top = (color === orientation ? i : 7 - i) * 12.5;
return h('square', {
attrs: {
style: 'top: ' + top + '%;left: ' + left + '%'
},
hook: bind('click', e => {
e.stopPropagation();
finish(serverRole);
})
}, [h('piece.' + serverRole + '.' + color)]);
}));
};
示例2: renderPromotion
function renderPromotion(ctrl: AnalyseCtrl, dest: Key, pieces, color: Color, orientation: Color) {
if (!promoting) return;
let left = (8 - util.key2pos(dest)[0]) * 12.5;
if (orientation === 'white') left = 87.5 - left;
const vertical = color === orientation ? 'top' : 'bottom';
return h('div#promotion_choice.' + vertical, {
hook: {
insert: vnode => {
const el = (vnode.elm as HTMLElement);
el.addEventListener('click', _ => cancel(ctrl));
el.oncontextmenu = () => false;
}
}
}, pieces.map(function(serverRole, i) {
const top = (color === orientation ? i : 7 - i) * 12.5;
return h('square', {
attrs: {
style: 'top: ' + top + '%;left: ' + left + '%'
},
hook: bind('click', e => {
e.stopPropagation();
finish(ctrl, serverRole);
})
}, [h('piece.' + serverRole + '.' + color)]);
}));
}
示例3: renderPromotion
function renderPromotion(ctrl: RoundController, dest: cg.Key, roles: cg.Role[], color: Color, orientation: Color) {
var left = (8 - key2pos(dest)[0]) * 12.5;
if (orientation === 'white') left = 87.5 - left;
var vertical = color === orientation ? 'top' : 'bottom';
return h('div#promotion_choice.' + vertical, {
hook: {
insert: vnode => {
const el = vnode.elm as HTMLElement;
el.addEventListener('click', () => cancel(ctrl));
el.addEventListener('contextmenu', e => {
e.preventDefault();
return false;
});
}
}
}, roles.map((serverRole, i) => {
var top = (color === orientation ? i : 7 - i) * 12.5;
return h('square', {
attrs: {style: 'top: ' + top + '%;left: ' + left + '%'},
hook: bind('click', e => {
e.stopPropagation();
finish(ctrl, serverRole);
})
}, [
h('piece.' + serverRole + '.' + color)
]);
}));
};
示例4: capture
export function capture(ctrl: RoundController, key: cg.Key) {
const exploding: cg.Key[] = [],
diff: cg.PiecesDiff = {},
orig = util.key2pos(key),
minX = Math.max(1, orig[0] - 1),
maxX = Math.min(8, orig[0] + 1),
minY = Math.max(1, orig[1] - 1),
maxY = Math.min(8, orig[1] + 1);
const pieces = ctrl.chessground.state.pieces;
for (let x = minX; x <= maxX; x++) {
for (let y = minY; y <= maxY; y++) {
const k = util.pos2key([x, y]);
exploding.push(k);
const explodes = pieces[k] && (
k === key || pieces[k]!.role !== 'pawn')
if (explodes) diff[k] = undefined;
}
}
ctrl.chessground.setPieces(diff);
ctrl.chessground.explode(exploding);
}
示例5: enpassant
export function enpassant(ctrl: RoundController, key: cg.Key, color: cg.Color) {
const pos = util.key2pos(key),
pawnPos: cg.Pos = [pos[0], pos[1] + (color === 'white' ? -1 : 1)];
capture(ctrl, util.pos2key(pawnPos));
}