2021-02-06 06:26:05 -07:00
|
|
|
import * as cg from 'chessground/types';
|
2021-08-21 06:27:23 -06:00
|
|
|
import { VNodeData } from 'snabbdom';
|
2021-07-26 16:17:24 -06:00
|
|
|
import { Dests, EncodedDests } from './interfaces';
|
2021-06-24 22:55:19 -06:00
|
|
|
|
2021-07-26 21:17:59 -06:00
|
|
|
export { bind, onInsert } from 'common/snabbdom';
|
2017-04-25 08:10:14 -06:00
|
|
|
|
2020-10-02 14:28:42 -06:00
|
|
|
export const justIcon = (icon: string): VNodeData => ({
|
2021-02-06 06:26:05 -07:00
|
|
|
attrs: { 'data-icon': icon },
|
2020-10-02 14:28:42 -06:00
|
|
|
});
|
2017-05-23 02:34:28 -06:00
|
|
|
|
2020-10-02 14:28:42 -06:00
|
|
|
export const uci2move = (uci: string): cg.Key[] | undefined => {
|
2017-04-25 05:16:04 -06:00
|
|
|
if (!uci) return undefined;
|
2017-04-25 08:10:14 -06:00
|
|
|
if (uci[1] === '@') return [uci.slice(2, 4) as cg.Key];
|
|
|
|
return [uci.slice(0, 2), uci.slice(2, 4)] as cg.Key[];
|
2021-02-06 06:26:05 -07:00
|
|
|
};
|
2017-07-09 04:23:43 -06:00
|
|
|
|
2020-07-07 06:16:00 -06:00
|
|
|
export function parsePossibleMoves(dests?: EncodedDests): Dests {
|
|
|
|
const dec = new Map();
|
|
|
|
if (!dests) return dec;
|
2018-12-15 07:09:13 -07:00
|
|
|
if (typeof dests == 'string')
|
2020-07-07 06:16:00 -06:00
|
|
|
for (const ds of dests.split(' ')) {
|
2020-10-02 14:28:42 -06:00
|
|
|
dec.set(ds.slice(0, 2), ds.slice(2).match(/.{2}/g) as cg.Key[]);
|
2020-07-07 06:16:00 -06:00
|
|
|
}
|
|
|
|
else for (const k in dests) dec.set(k, dests[k].match(/.{2}/g) as cg.Key[]);
|
2017-07-12 07:25:30 -06:00
|
|
|
return dec;
|
2017-07-09 04:23:43 -06:00
|
|
|
}
|