UNPKG

@gamepark/rules-api

Version:

API to implement the rules of a board game

76 lines 3.3 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.isSimultaneousRule = exports.SimultaneousRule = void 0; var moves_1 = require("../moves"); var MaterialRulesPart_1 = require("./MaterialRulesPart"); /** * Base class for any part of the rules where multiple players have to do something at the same time. */ var SimultaneousRule = /** @class */ (function (_super) { __extends(SimultaneousRule, _super); function SimultaneousRule() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.endPlayerTurn = moves_1.MaterialMoveBuilder.endPlayerTurn; return _this; } /** * See {@link Rules.isTurnToPlay} */ SimultaneousRule.prototype.isTurnToPlay = function (player) { var _a, _b, _c; return (_c = (_b = (_a = this.game.rule) === null || _a === void 0 ? void 0 : _a.players) === null || _b === void 0 ? void 0 : _b.includes(player)) !== null && _c !== void 0 ? _c : false; }; Object.defineProperty(SimultaneousRule.prototype, "activePlayers", { /** * @returns all the active players */ get: function () { var _a, _b; return (_b = (_a = this.game.rule) === null || _a === void 0 ? void 0 : _a.players) !== null && _b !== void 0 ? _b : []; }, enumerable: false, configurable: true }); /** * See {@link Rules.getLegalMoves} */ SimultaneousRule.prototype.getLegalMoves = function (player) { return this.isTurnToPlay(player) ? this.getActivePlayerLegalMoves(player) : []; }; /** * This function is called immediately after a {@link EndPlayerTurn} has been played. * @param _move The move which has just been played * @param _context Context of execution * @returns {MaterialMove[]} Any consequences that should automatically be played after the move */ SimultaneousRule.prototype.onPlayerTurnEnd = function (_move, _context) { return []; }; return SimultaneousRule; }(MaterialRulesPart_1.MaterialRulesPart)); exports.SimultaneousRule = SimultaneousRule; /** * Type guard to know if a {@link MaterialRulesPart} is a {@link SimultaneousRule} * @param rule The rule * @returns true if the rule if a {@link SimultaneousRule} */ function isSimultaneousRule(rule) { return rule !== undefined && typeof rule.getMovesAfterPlayersDone === 'function'; } exports.isSimultaneousRule = isSimultaneousRule; //# sourceMappingURL=SimultaneousRule.js.map