@gamepark/rules-api
Version:
API to implement the rules of a board game
34 lines • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ItemMovesBuilder = void 0;
var MoveKind_1 = require("../MoveKind");
var ItemMoveType_1 = require("./ItemMoveType");
var ItemMovesBuilder = (function () {
function ItemMovesBuilder(items) {
this.moves = [];
this.items = items;
}
ItemMovesBuilder.prototype.shuffle = function (itemsType, predicate) {
if (predicate === void 0) { predicate = function () {
return true;
}; }
var items = this.items[itemsType];
if (!items)
throw new Error('You cannot shuffle a type of items that does not exists');
var move = {
kind: MoveKind_1.MoveKind.ItemMove,
itemType: itemsType,
type: ItemMoveType_1.ItemMoveType.Shuffle,
indexes: []
};
for (var index = 0; index < items.length; index++) {
if (predicate(items[index]))
move.indexes.push(index);
}
this.moves.push(move);
return this;
};
return ItemMovesBuilder;
}());
exports.ItemMovesBuilder = ItemMovesBuilder;
//# sourceMappingURL=ItemMovesBuilder.js.map