Fix Eightpieces
[vchess.git] / client / src / utils / playUndo.js
1 export function playMove(move, vr) {
2 if (!Array.isArray(move)) move = [move];
3 move.forEach(m => vr.play(m));
4 }
5
6 export function undoMove(move, vr) {
7 if (!Array.isArray(move)) move = [move];
8 // If multi-move, undo all submoves from last to first
9 for (let i = move.length - 1; i >= 0; i--)
10 vr.undo(move[i]);
11 }
12
13 export function getFilteredMove(move) {
14 if (!Array.isArray(move)) move = [move];
15 const filtered_move = move.map(m => {
16 return {
17 appear: m.appear,
18 vanish: m.vanish,
19 start: m.start,
20 end: m.end
21 };
22 });
23 return filtered_move.length == 1 ? filtered_move[0] : filtered_move;
24 }