@gamepark/rules-api
Version:
API to implement the rules of a board game
27 lines • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDeleteItemType = exports.isDeleteItem = void 0;
var ItemMoveType_1 = require("./ItemMoveType");
var MoveKind_1 = require("../MoveKind");
/**
* Type guard to test if a {@link MaterialMove} is a {@link DeleteItem} move
* @param move Move to test
* @returns true if move is a {@link DeleteItem}
*/
function isDeleteItem(move) {
return move.kind === MoveKind_1.MoveKind.ItemMove && move.type === ItemMoveType_1.ItemMoveType.Delete;
}
exports.isDeleteItem = isDeleteItem;
/**
* Function to get a type guard for a {@link DeleteItem} move for specific item types.
* @param type Item type to test
* @param index Optional itemIndex to test along the item type
* @returns a type guard similar as {@link isDeleteItem} but that also verify the item type.
*/
function isDeleteItemType(type, index) {
return function (move) {
return isDeleteItem(move) && move.itemType === type && (index === undefined || move.itemIndex === index);
};
}
exports.isDeleteItemType = isDeleteItemType;
//# sourceMappingURL=DeleteItem.js.map