@real_one_chess_king/game-logic
Version:
R.O.C.K. chess game logic
56 lines • 1.42 kB
JavaScript
import { AffectType, } from "./affect.types";
export function isKillAffect(affect) {
return affect.type === AffectType.kill;
}
export function isMoveAffect(affect) {
return affect.type === AffectType.move;
}
export function isSpawnAffect(affect) {
return affect.type === AffectType.spawn;
}
export function isTransformationAffect(affect) {
return affect.type === AffectType.transformation;
}
export function isUserSelectableAffect(affect) {
return !!affect.userSelected;
}
export function markAsUserSelected(a) {
a.userSelected = true;
return a;
}
export function buildMoveAffect(from, to) {
return {
type: AffectType.move,
from,
to,
};
}
export function buildKillAffect(from) {
return {
type: AffectType.kill,
from,
};
}
export function buildSpawnAffect(from) {
return {
type: AffectType.spawn,
from,
};
}
export function buildTransformationAffect(from, destPieceType, sourcePieceType) {
return {
type: AffectType.transformation,
from,
destPieceType,
sourcePieceType,
};
}
// currently supports only move
export function getUserSelectedMoveAffect(affects) {
const a = affects.find((a) => a.userSelected && isMoveAffect(a));
if (!a) {
throw new Error("User selected from coordinate is not found");
}
return a;
}
//# sourceMappingURL=affect.utils.js.map