@gamepark/rules-api
Version:
API to implement the rules of a board game
28 lines • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FillGapStrategy = void 0;
/**
* This strategy attributes the first gap in a sequence, and leaves a gap when an item is removed.
* Use for river-type mechanisms for instance.
*/
var FillGapStrategy = /** @class */ (function () {
function FillGapStrategy(axis) {
if (axis === void 0) { axis = 'x'; }
this.axis = axis;
}
FillGapStrategy.prototype.addItem = function (material, item) {
var _this = this;
var _a;
if (item.location[this.axis] === undefined) {
var items = material.sort(function (item) { return item.location[_this.axis]; }).getItems();
var position = 0;
while (((_a = items[position]) === null || _a === void 0 ? void 0 : _a.location[this.axis]) === position) {
position++;
}
item.location[this.axis] = position;
}
};
return FillGapStrategy;
}());
exports.FillGapStrategy = FillGapStrategy;
//# sourceMappingURL=FillGapStrategy.js.map