UNPKG

@real_one_chess_king/game-logic

Version:
64 lines 3.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PositionSpecificMovementRule = void 0; const movement_rule_1 = require("./movement-rule"); const straight_movement_rule_1 = require("./straight-movement.rule"); const affect_utils_1 = require("../../affect/affect.utils"); class PositionSpecificMovementRule extends straight_movement_rule_1.StraightMovementRule { activatePositions; constructor({ id, name, moveToEmpty, moveToKill, collision, distance, directions, speed, activatePositions, }) { super(id, name, moveToEmpty, moveToKill, collision, distance, directions, speed); this.activatePositions = activatePositions; if (activatePositions.x && !directions.has(movement_rule_1.Direction.Left) && !directions.has(movement_rule_1.Direction.Right) && !directions.has(movement_rule_1.Direction.UpRight) && !directions.has(movement_rule_1.Direction.UpLeft) && !directions.has(movement_rule_1.Direction.DownRight) && !directions.has(movement_rule_1.Direction.DownLeft)) { throw new Error("PositionSpecificMovementRule: x position provided but no horizontal directions"); } if (activatePositions.y && !directions.has(movement_rule_1.Direction.Up) && !directions.has(movement_rule_1.Direction.Down) && !directions.has(movement_rule_1.Direction.UpRight) && !directions.has(movement_rule_1.Direction.UpLeft) && !directions.has(movement_rule_1.Direction.DownRight) && !directions.has(movement_rule_1.Direction.DownLeft)) { throw new Error("PositionSpecificMovementRule: y position provided but no vertical directions"); } } possibleDirrections = [ movement_rule_1.Direction.Up, movement_rule_1.Direction.Down, movement_rule_1.Direction.Left, movement_rule_1.Direction.Right, movement_rule_1.Direction.DownLeft, movement_rule_1.Direction.UpLeft, movement_rule_1.Direction.UpRight, movement_rule_1.Direction.DownRight, ]; calculateNewCoord = (x, y, diff, dirrection, // eslint-disable-next-line @typescript-eslint/no-unused-vars _) => { if (this.activatePositions.y?.has(y) || this.activatePositions.x?.has(x)) { return [ (0, affect_utils_1.markAsUserSelected)((0, affect_utils_1.buildMoveAffect)([x, y], (0, straight_movement_rule_1.directionToVector)(dirrection, x, y, diff))), ]; } return []; }; getMeta() { const xPositions = this.activatePositions.x && Array.from(this.activatePositions.x); const yPositions = this.activatePositions.y && Array.from(this.activatePositions.y); return { activatePositions: { ...(xPositions ? { x: xPositions } : {}), ...(yPositions ? { y: yPositions } : {}), }, ...super.getMeta(), }; } } exports.PositionSpecificMovementRule = PositionSpecificMovementRule; //# sourceMappingURL=position-specific-movement.rule.js.map