@real_one_chess_king/game-logic
Version:
R.O.C.K. chess game logic
69 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isKillAffect = isKillAffect;
exports.isMoveAffect = isMoveAffect;
exports.isSpawnAffect = isSpawnAffect;
exports.isTransformationAffect = isTransformationAffect;
exports.isUserSelectableAffect = isUserSelectableAffect;
exports.markAsUserSelected = markAsUserSelected;
exports.buildMoveAffect = buildMoveAffect;
exports.buildKillAffect = buildKillAffect;
exports.buildSpawnAffect = buildSpawnAffect;
exports.buildTransformationAffect = buildTransformationAffect;
exports.getUserSelectedMoveAffect = getUserSelectedMoveAffect;
const affect_types_1 = require("./affect.types");
function isKillAffect(affect) {
return affect.type === affect_types_1.AffectType.kill;
}
function isMoveAffect(affect) {
return affect.type === affect_types_1.AffectType.move;
}
function isSpawnAffect(affect) {
return affect.type === affect_types_1.AffectType.spawn;
}
function isTransformationAffect(affect) {
return affect.type === affect_types_1.AffectType.transformation;
}
function isUserSelectableAffect(affect) {
return !!affect.userSelected;
}
function markAsUserSelected(a) {
a.userSelected = true;
return a;
}
function buildMoveAffect(from, to) {
return {
type: affect_types_1.AffectType.move,
from,
to,
};
}
function buildKillAffect(from) {
return {
type: affect_types_1.AffectType.kill,
from,
};
}
function buildSpawnAffect(from) {
return {
type: affect_types_1.AffectType.spawn,
from,
};
}
function buildTransformationAffect(from, destPieceType, sourcePieceType) {
return {
type: affect_types_1.AffectType.transformation,
from,
destPieceType,
sourcePieceType,
};
}
// currently supports only move
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