@gamepark/rules-api 6.0.1-alpha.0 → 6.0.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/material/HiddenMaterialRules.d.ts +12 -10
- package/dist/material/HiddenMaterialRules.js +20 -15
- package/dist/material/HiddenMaterialRules.js.map +1 -1
- package/dist/material/MaterialRules.d.ts +3 -2
- package/dist/material/MaterialRules.js +15 -20
- package/dist/material/MaterialRules.js.map +1 -1
- package/dist/material/index.d.ts +0 -1
- package/dist/material/index.js +0 -1
- package/dist/material/index.js.map +1 -1
- package/dist/material/items/Material.d.ts +12 -6
- package/dist/material/items/Material.js +70 -48
- package/dist/material/items/Material.js.map +1 -1
- package/dist/material/items/MaterialItem.d.ts +5 -3
- package/dist/material/items/MaterialMutator.d.ts +20 -0
- package/dist/material/items/MaterialMutator.js +150 -0
- package/dist/material/items/MaterialMutator.js.map +1 -0
- package/dist/material/items/MaterialOperation.d.ts +1 -4
- package/dist/material/items/MaterialOperation.js +16 -30
- package/dist/material/items/MaterialOperation.js.map +1 -1
- package/dist/material/items/index.d.ts +1 -1
- package/dist/material/items/index.js +1 -1
- package/dist/material/items/index.js.map +1 -1
- package/dist/material/location/Location.d.ts +0 -1
- package/dist/material/location/Location.js +0 -9
- package/dist/material/location/Location.js.map +1 -1
- package/dist/material/location/strategy/FillGapStrategy.d.ts +10 -0
- package/dist/material/location/strategy/FillGapStrategy.js +25 -0
- package/dist/material/location/strategy/FillGapStrategy.js.map +1 -0
- package/dist/material/location/strategy/index.d.ts +1 -0
- package/dist/material/location/strategy/index.js +1 -0
- package/dist/material/location/strategy/index.js.map +1 -1
- package/dist/material/moves/MoveItem.d.ts +8 -9
- package/dist/material/moves/MoveItem.js +5 -45
- package/dist/material/moves/MoveItem.js.map +1 -1
- package/dist/material/moves/local/RulesDisplay.d.ts +1 -1
- package/dist/material/moves/rules/MaterialMutator.d.ts +17 -0
- package/dist/material/moves/rules/MaterialMutator.js +133 -0
- package/dist/material/moves/rules/MaterialMutator.js.map +1 -0
- package/package.json +2 -2
|
@@ -3,16 +3,18 @@ import { MaterialRules } from './MaterialRules';
|
|
|
3
3
|
import { MaterialGame } from './MaterialGame';
|
|
4
4
|
import { CreateItem, MaterialRulesMove, MaterialRulesMoveRandomized, MoveItem } from './moves';
|
|
5
5
|
import { MaterialItem } from './items';
|
|
6
|
-
export declare abstract class HiddenMaterialRules<
|
|
7
|
-
abstract hidingStrategies: Partial<Record<
|
|
8
|
-
getItemTypeHidingStrategies(type:
|
|
9
|
-
isUnpredictableMove(move: MaterialRulesMove<
|
|
10
|
-
randomize(move: MaterialRulesMove<
|
|
11
|
-
getView(player?:
|
|
12
|
-
hideItem(type:
|
|
13
|
-
getMoveView(move: MaterialRulesMoveRandomized<
|
|
14
|
-
getMoveItemView(move: MoveItem<
|
|
15
|
-
|
|
6
|
+
export declare abstract class HiddenMaterialRules<P extends number = number, M extends number = number, L extends number = number> extends MaterialRules<P, M, L> implements IncompleteInformation<MaterialGame<P, M, L>, MaterialRulesMove<P, M, L>, MaterialRulesMove<P, M, L>> {
|
|
7
|
+
abstract hidingStrategies: Partial<Record<M, Partial<Record<L, HidingStrategy<P, L>>>>>;
|
|
8
|
+
getItemTypeHidingStrategies(type: M): Partial<Record<L, HidingStrategy<P, L>>> | undefined;
|
|
9
|
+
isUnpredictableMove(move: MaterialRulesMove<P, M, L>): boolean;
|
|
10
|
+
randomize(move: MaterialRulesMove<P, M, L>): MaterialRulesMove<P, M, L> & MaterialRulesMoveRandomized<P, M, L>;
|
|
11
|
+
getView(player?: P): any;
|
|
12
|
+
hideItem(type: M, item: MaterialItem<P, L>, player?: P): MaterialItem<P, L>;
|
|
13
|
+
getMoveView(move: MaterialRulesMoveRandomized<P, M, L>, player?: P): MaterialRulesMove<P, M, L>;
|
|
14
|
+
getMoveItemView(move: MoveItem<P, M, L>, player?: P): MoveItem<P, M, L>;
|
|
15
|
+
moveItemRevealsInformation(dataBefore: Omit<MaterialItem, 'quantity' | 'location' | 'rotation'>, dataAfter: Omit<MaterialItem, 'quantity' | 'location' | 'rotation'>): boolean;
|
|
16
|
+
private getHideItemData;
|
|
17
|
+
getCreateItemsView(move: CreateItem<P, M, L>, player?: P): CreateItem<P, M, L>;
|
|
16
18
|
private getShuffleItemsView;
|
|
17
19
|
}
|
|
18
20
|
export declare type HidingStrategy<P extends number = number, L extends number = number> = (item: MaterialItem<P, L>) => MaterialItem<P, L>;
|
|
@@ -45,7 +45,6 @@ var lodash_mapvalues_1 = __importDefault(require("lodash.mapvalues"));
|
|
|
45
45
|
var MaterialRules_1 = require("./MaterialRules");
|
|
46
46
|
var moves_1 = require("./moves");
|
|
47
47
|
var items_1 = require("./items");
|
|
48
|
-
var fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
49
48
|
var HiddenMaterialRules = /** @class */ (function (_super) {
|
|
50
49
|
__extends(HiddenMaterialRules, _super);
|
|
51
50
|
function HiddenMaterialRules() {
|
|
@@ -60,18 +59,20 @@ var HiddenMaterialRules = /** @class */ (function (_super) {
|
|
|
60
59
|
if (move.kind !== moves_1.MoveKind.MaterialMove)
|
|
61
60
|
return false;
|
|
62
61
|
if (move.type === moves_1.MaterialMoveType.Move) {
|
|
63
|
-
return move.reveal
|
|
62
|
+
return move.reveal !== undefined;
|
|
64
63
|
}
|
|
65
64
|
return false;
|
|
66
65
|
};
|
|
67
66
|
HiddenMaterialRules.prototype.randomize = function (move) {
|
|
68
67
|
if (move.kind === moves_1.MoveKind.MaterialMove && move.type === moves_1.MaterialMoveType.Move) {
|
|
69
68
|
// Hack the randomize function to flag any item movement that reveals something, thus making the action undoable
|
|
70
|
-
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
if (this.hidingStrategies /* TODO: can be undefined during setup because setup is called by constructor */) {
|
|
70
|
+
for (var _i = 0, _a = this.game.players; _i < _a.length; _i++) {
|
|
71
|
+
var player = _a[_i];
|
|
72
|
+
var moveView = this.getMoveItemView(move, player);
|
|
73
|
+
if (moveView.reveal) {
|
|
74
|
+
return _super.prototype.randomize.call(this, __assign(__assign({}, move), { reveal: {} }));
|
|
75
|
+
}
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
}
|
|
@@ -110,14 +111,18 @@ var HiddenMaterialRules = /** @class */ (function (_super) {
|
|
|
110
111
|
return move;
|
|
111
112
|
};
|
|
112
113
|
HiddenMaterialRules.prototype.getMoveItemView = function (move, player) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
var
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return
|
|
114
|
+
var mutator = new items_1.MaterialMutator(move.itemType, this.game.items[move.itemType]);
|
|
115
|
+
var movedItemData = this.getHideItemData(move.itemType, this.material(move.itemType).getItem(move.itemIndex), player);
|
|
116
|
+
var newItemData = this.getHideItemData(move.itemType, mutator.getItemAfterMove(move), player);
|
|
117
|
+
return this.moveItemRevealsInformation(movedItemData, newItemData) ? __assign(__assign({}, move), { reveal: newItemData }) : move;
|
|
118
|
+
};
|
|
119
|
+
// Overload if needed
|
|
120
|
+
HiddenMaterialRules.prototype.moveItemRevealsInformation = function (dataBefore, dataAfter) {
|
|
121
|
+
return dataAfter.id !== undefined && dataBefore.id === undefined;
|
|
122
|
+
};
|
|
123
|
+
HiddenMaterialRules.prototype.getHideItemData = function (type, item, player) {
|
|
124
|
+
var _a = this.hideItem(type, item, player), quantity = _a.quantity, rotation = _a.rotation, location = _a.location, hideItemData = __rest(_a, ["quantity", "rotation", "location"]);
|
|
125
|
+
return hideItemData;
|
|
121
126
|
};
|
|
122
127
|
HiddenMaterialRules.prototype.getCreateItemsView = function (move, player) {
|
|
123
128
|
return __assign(__assign({}, move), { item: this.hideItem(move.itemType, move.item, player) });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HiddenMaterialRules.js","sourceRoot":"","sources":["../../src/material/HiddenMaterialRules.ts"],"names":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,CAAA;IAClE,CAAC;IAEO,6CAAe,GAAvB,UAAwB,IAAO,EAAE,IAAwB,EAAE,MAAU;QACnE,IAAM,KAAoD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,EAAnF,QAAQ,cAAA,EAAE,QAAQ,cAAA,EAAE,QAAQ,cAAA,EAAK,YAAY,cAA/C,oCAAiD,CAAoC,CAAA;QAC3F,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,gDAAkB,GAAlB,UAAmB,IAAyB,EAAE,MAAU;QACtD,6BAAY,IAAI,KAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,IAAE;IAC3E,CAAC;IAEO,iDAAmB,GAA3B,UAA4B,IAA0B,EAAE,OAAW;QACjE,+FAA+F;QACvF,IAAA,UAAU,GAAkB,IAAI,WAAtB,EAAK,QAAQ,UAAK,IAAI,EAAlC,cAA2B,CAAF,CAAS;QACxC,OAAO,QAAQ,CAAA;IACjB,CAAC;IACH,0BAAC;AAAD,CAAC,AAhGD,CACU,6BAAa,GA+FtB;AAhGqB,kDAAmB;AAoGlC,IAAM,UAAU,GAAG,UAAuD,IAAwB;IAC/F,IAAA,EAAE,GAAoB,IAAI,GAAxB,EAAK,UAAU,UAAK,IAAI,EAA5B,MAAqB,CAAF,CAAS;IAClC,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA;AAHY,QAAA,UAAU,cAGtB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MaterialGame } from './MaterialGame';
|
|
2
2
|
import { Rules } from '../Rules';
|
|
3
3
|
import { MaterialRulesMove, MaterialRulesMoveRandomized } from './moves';
|
|
4
|
-
import { Material, MaterialItem
|
|
4
|
+
import { Material, MaterialItem } from './items';
|
|
5
5
|
import { RandomMove } from '../RandomMove';
|
|
6
6
|
import { MaterialRulesStepCreator, MaterialStepRules } from './rules';
|
|
7
7
|
import { LocationStrategy } from './location';
|
|
@@ -11,8 +11,8 @@ export declare abstract class MaterialRules<Player extends number = number, Mate
|
|
|
11
11
|
constructor(state: MaterialGame<Player, MaterialType, LocationType>);
|
|
12
12
|
constructor(options: any);
|
|
13
13
|
items(type: MaterialType): MaterialItem<Player, LocationType>[];
|
|
14
|
+
setupMaterial(type: MaterialType): Material<Player, MaterialType, LocationType>;
|
|
14
15
|
material(type: MaterialType): Material<Player, MaterialType, LocationType>;
|
|
15
|
-
materialOperations(type: MaterialType): MaterialOperation<Player, MaterialType, LocationType>;
|
|
16
16
|
abstract setup(options: any): void;
|
|
17
17
|
abstract get rulesSteps(): Record<number, MaterialRulesStepCreator<Player, MaterialType, LocationType>>;
|
|
18
18
|
getLocationsStrategies(): Partial<Record<MaterialType, Partial<Record<LocationType, LocationStrategy<Player, MaterialType, LocationType>>>>>;
|
|
@@ -22,6 +22,7 @@ export declare abstract class MaterialRules<Player extends number = number, Mate
|
|
|
22
22
|
start<RuleId extends number = number>(id: RuleId, player?: Player, memory?: Record<string, any>): void;
|
|
23
23
|
randomize(move: MaterialRulesMove<Player, MaterialType, LocationType>): MaterialRulesMove<Player, MaterialType, LocationType> & MaterialRulesMoveRandomized<Player, MaterialType, LocationType>;
|
|
24
24
|
play(move: MaterialRulesMove<Player, MaterialType, LocationType> & MaterialRulesMoveRandomized<Player, MaterialType, LocationType>): MaterialRulesMove<Player, MaterialType, LocationType>[];
|
|
25
|
+
isMoveTrigger(move: MaterialRulesMove<Player, MaterialType, LocationType>, predicate: (move: MaterialRulesMove<Player, MaterialType, LocationType>) => boolean): boolean;
|
|
25
26
|
canUndo(action: Action<MaterialRulesMove<Player, MaterialType, LocationType>, Player>, consecutiveActions: Action<MaterialRulesMove<Player, MaterialType, LocationType>, Player>[]): boolean;
|
|
26
27
|
actionBlocksUndo(action: Action<MaterialRulesMove<Player, MaterialType, LocationType>, Player>): boolean;
|
|
27
28
|
actionActivatesPlayer(action: Action<MaterialRulesMove<Player, MaterialType, LocationType>, Player>): boolean;
|
|
@@ -49,15 +49,17 @@ var MaterialRules = /** @class */ (function (_super) {
|
|
|
49
49
|
var _a;
|
|
50
50
|
return (_a = this.game.items[type]) !== null && _a !== void 0 ? _a : [];
|
|
51
51
|
};
|
|
52
|
+
MaterialRules.prototype.setupMaterial = function (type) {
|
|
53
|
+
var _this = this;
|
|
54
|
+
var _a;
|
|
55
|
+
return new items_1.Material(type, Array.from(((_a = this.game.items[type]) !== null && _a !== void 0 ? _a : []).entries()).filter(function (entry) { return entry[1].quantity !== 0; }), function (move) {
|
|
56
|
+
_this.play(_this.randomize(JSON.parse(JSON.stringify(move))));
|
|
57
|
+
});
|
|
58
|
+
};
|
|
52
59
|
MaterialRules.prototype.material = function (type) {
|
|
53
60
|
var _a;
|
|
54
61
|
return new items_1.Material(type, Array.from(((_a = this.game.items[type]) !== null && _a !== void 0 ? _a : []).entries()).filter(function (entry) { return entry[1].quantity !== 0; }));
|
|
55
62
|
};
|
|
56
|
-
MaterialRules.prototype.materialOperations = function (type) {
|
|
57
|
-
if (!this.game.items[type])
|
|
58
|
-
this.game.items[type] = [];
|
|
59
|
-
return new items_1.MaterialOperation(type, this.game.items[type], this.getLocationsStrategies()[type]);
|
|
60
|
-
};
|
|
61
63
|
MaterialRules.prototype.getLocationsStrategies = function () {
|
|
62
64
|
return {};
|
|
63
65
|
};
|
|
@@ -100,21 +102,10 @@ var MaterialRules = /** @class */ (function (_super) {
|
|
|
100
102
|
if (delegate) {
|
|
101
103
|
consequences.push.apply(consequences, delegate.beforeMaterialMove(move));
|
|
102
104
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
break;
|
|
108
|
-
case moves_1.MaterialMoveType.Delete:
|
|
109
|
-
material.delete(move.itemIndex, move.quantity);
|
|
110
|
-
break;
|
|
111
|
-
case moves_1.MaterialMoveType.Shuffle:
|
|
112
|
-
material.shuffle(move.indexes, move.newIndexes);
|
|
113
|
-
break;
|
|
114
|
-
case moves_1.MaterialMoveType.Move:
|
|
115
|
-
material.move(move.itemIndex, move.item);
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
105
|
+
if (!this.game.items[move.itemType])
|
|
106
|
+
this.game.items[move.itemType] = [];
|
|
107
|
+
var mutator = new items_1.MaterialMutator(move.itemType, this.game.items[move.itemType], this.getLocationsStrategies()[move.itemType]);
|
|
108
|
+
mutator.applyMove(move);
|
|
118
109
|
if (delegate) {
|
|
119
110
|
consequences.push.apply(consequences, delegate.afterMaterialMove(move));
|
|
120
111
|
}
|
|
@@ -155,6 +146,10 @@ var MaterialRules = /** @class */ (function (_super) {
|
|
|
155
146
|
}
|
|
156
147
|
return consequences;
|
|
157
148
|
};
|
|
149
|
+
MaterialRules.prototype.isMoveTrigger = function (move, predicate) {
|
|
150
|
+
var _this = this;
|
|
151
|
+
return predicate(move) || (move.kind === moves_1.MoveKind.CustomMove && this.play(move).some(function (consequence) { return _this.isMoveTrigger(consequence, predicate); }));
|
|
152
|
+
};
|
|
158
153
|
MaterialRules.prototype.canUndo = function (action, consecutiveActions) {
|
|
159
154
|
for (var i = consecutiveActions.length - 1; i >= 0; i--) {
|
|
160
155
|
var consecutiveAction = consecutiveActions[i];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MaterialRules.js","sourceRoot":"","sources":["../../src/material/MaterialRules.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kCAAgC;AAChC,iCAAiI;AACjI,kEAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"MaterialRules.js","sourceRoot":"","sources":["../../src/material/MaterialRules.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kCAAgC;AAChC,iCAAiI;AACjI,kEAAoC;AACpC,iCAAiE;AAOjE;IACU,iCAAsH;IAM9H,uBAAY,GAAQ;QAApB,iBAMC;QALC,IAAM,SAAS,GAAG,CAAE,GAAoB,CAAC,KAA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C,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAClD,UAAC,EAAE,IAAK,OAAA,CAAC,EAAE,GAAG,CAAC,CAAW,EAAlB,CAAkB,CAC3B,CAAA;KACF;AACH,CAAC"}
|
package/dist/material/index.d.ts
CHANGED
package/dist/material/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./helper"), exports);
|
|
18
17
|
__exportStar(require("./items"), exports);
|
|
19
18
|
__exportStar(require("./location"), exports);
|
|
20
19
|
__exportStar(require("./moves"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/material/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/material/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,6CAA0B;AAC1B,0CAAuB;AACvB,0CAAuB;AACvB,wDAAqC;AACrC,iDAA8B;AAC9B,kDAA+B;AAC/B,wDAAqC"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { MaterialItem } from './MaterialItem';
|
|
2
|
-
import {
|
|
3
|
-
import { CreateItem, MoveItem } from '../moves';
|
|
1
|
+
import { ItemPosition, MaterialItem } from './MaterialItem';
|
|
2
|
+
import { Location } from '../location';
|
|
3
|
+
import { CreateItem, MaterialRulesMove, MoveItem, Shuffle } from '../moves';
|
|
4
4
|
import { DeleteItem } from '../moves/DeleteItem';
|
|
5
5
|
declare type ItemEntry<P extends number = number, L extends number = number> = [number, MaterialItem<P, L>];
|
|
6
6
|
export declare class Material<P extends number = number, M extends number = number, L extends number = number> {
|
|
7
7
|
private readonly type;
|
|
8
8
|
private readonly entries;
|
|
9
|
-
|
|
9
|
+
private readonly play?;
|
|
10
|
+
constructor(type: M, items: ItemEntry<P, L>[], play?: (move: MaterialRulesMove<P, M, L>) => void);
|
|
11
|
+
private new;
|
|
10
12
|
getItems(): MaterialItem<P, L>[];
|
|
11
13
|
getItems<T>(mapFn: (item: MaterialItem<P, L>) => T): T[];
|
|
12
14
|
getItem(index: number): MaterialItem<P, L> | undefined;
|
|
@@ -22,9 +24,13 @@ export declare class Material<P extends number = number, M extends number = numb
|
|
|
22
24
|
sort(selector: (item: MaterialItem<P, L>) => number): Material<P, M, L>;
|
|
23
25
|
limit(count: number): Material<P, M, L>;
|
|
24
26
|
maxBy(selector: (item: MaterialItem<P, L>) => number): Material<P, M, L>;
|
|
27
|
+
private process;
|
|
25
28
|
createItem(item: MaterialItem<P, L>): CreateItem<P, M, L>;
|
|
29
|
+
createItems(items: MaterialItem<P, L>[]): CreateItem<P, M, L>[];
|
|
26
30
|
deleteItem(quantity?: number): DeleteItem<M>;
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
deleteItems(quantity?: number): DeleteItem<M>[];
|
|
32
|
+
moveItem(position: Partial<ItemPosition<P, L>>, quantity?: number): MoveItem<P, M, L>;
|
|
33
|
+
moveItems(position: Partial<ItemPosition<P, L>>, quantity?: number): MoveItem<P, M, L>[];
|
|
34
|
+
shuffle(): Shuffle<M>;
|
|
29
35
|
}
|
|
30
36
|
export {};
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
@@ -21,10 +10,14 @@ var minBy_1 = __importDefault(require("lodash/minBy"));
|
|
|
21
10
|
var maxBy_1 = __importDefault(require("lodash/maxBy"));
|
|
22
11
|
var orderBy_1 = __importDefault(require("lodash/orderBy"));
|
|
23
12
|
var Material = /** @class */ (function () {
|
|
24
|
-
function Material(type, items) {
|
|
13
|
+
function Material(type, items, play) {
|
|
25
14
|
this.type = type;
|
|
26
15
|
this.entries = items;
|
|
16
|
+
this.play = play;
|
|
27
17
|
}
|
|
18
|
+
Material.prototype.new = function (entries) {
|
|
19
|
+
return new Material(this.type, entries, this.play);
|
|
20
|
+
};
|
|
28
21
|
Material.prototype.getItems = function (mapFn) {
|
|
29
22
|
return this.entries.map(function (entry) { return mapFn ? mapFn(entry[1]) : entry[1]; });
|
|
30
23
|
};
|
|
@@ -52,7 +45,7 @@ var Material = /** @class */ (function () {
|
|
|
52
45
|
configurable: true
|
|
53
46
|
});
|
|
54
47
|
Material.prototype.filter = function (predicate) {
|
|
55
|
-
return new
|
|
48
|
+
return this.new(this.entries.filter(function (_a) {
|
|
56
49
|
var item = _a[1];
|
|
57
50
|
return predicate(item);
|
|
58
51
|
}));
|
|
@@ -89,59 +82,88 @@ var Material = /** @class */ (function () {
|
|
|
89
82
|
};
|
|
90
83
|
Material.prototype.minBy = function (selector) {
|
|
91
84
|
var min = (0, minBy_1.default)(this.entries, function (entry) { return selector(entry[1]); });
|
|
92
|
-
return new
|
|
85
|
+
return this.new(min ? [min] : []);
|
|
93
86
|
};
|
|
94
87
|
Material.prototype.sort = function (selector) {
|
|
95
88
|
var orderedItems = (0, orderBy_1.default)(this.entries, function (entry) { return selector(entry[1]); });
|
|
96
|
-
return new
|
|
89
|
+
return this.new(orderedItems);
|
|
97
90
|
};
|
|
98
91
|
Material.prototype.limit = function (count) {
|
|
99
|
-
return new
|
|
92
|
+
return this.new(this.entries.slice(0, count));
|
|
100
93
|
};
|
|
101
94
|
Material.prototype.maxBy = function (selector) {
|
|
102
95
|
var max = (0, maxBy_1.default)(this.entries, function (entry) { return selector(entry[1]); });
|
|
103
|
-
return new
|
|
96
|
+
return this.new(max ? [max] : []);
|
|
97
|
+
};
|
|
98
|
+
Material.prototype.process = function (moves) {
|
|
99
|
+
if (this.play) {
|
|
100
|
+
for (var _i = 0, moves_2 = moves; _i < moves_2.length; _i++) {
|
|
101
|
+
var move = moves_2[_i];
|
|
102
|
+
this.play(move);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return moves;
|
|
104
106
|
};
|
|
105
107
|
Material.prototype.createItem = function (item) {
|
|
106
|
-
return
|
|
108
|
+
return this.createItems([item])[0];
|
|
109
|
+
};
|
|
110
|
+
Material.prototype.createItems = function (items) {
|
|
111
|
+
var _this = this;
|
|
112
|
+
return this.process(items.map(function (item) { return ({
|
|
113
|
+
kind: moves_1.MoveKind.MaterialMove,
|
|
114
|
+
type: moves_1.MaterialMoveType.Create,
|
|
115
|
+
itemType: _this.type,
|
|
116
|
+
item: item
|
|
117
|
+
}); }));
|
|
107
118
|
};
|
|
108
119
|
Material.prototype.deleteItem = function (quantity) {
|
|
109
|
-
if (!this.length
|
|
120
|
+
if (!this.length)
|
|
110
121
|
throw new Error('You are trying to delete an item that does not exists');
|
|
111
|
-
return
|
|
112
|
-
kind: moves_1.MoveKind.MaterialMove,
|
|
113
|
-
type: moves_1.MaterialMoveType.Delete,
|
|
114
|
-
itemType: this.type,
|
|
115
|
-
itemIndex: this.entries[0][0],
|
|
116
|
-
quantity: quantity
|
|
117
|
-
};
|
|
122
|
+
return this.limit(1).deleteItems(quantity)[0];
|
|
118
123
|
};
|
|
119
|
-
Material.prototype.
|
|
124
|
+
Material.prototype.deleteItems = function (quantity) {
|
|
125
|
+
var _this = this;
|
|
126
|
+
return this.process(this.entries.map(function (entry) {
|
|
127
|
+
var move = {
|
|
128
|
+
kind: moves_1.MoveKind.MaterialMove,
|
|
129
|
+
type: moves_1.MaterialMoveType.Delete,
|
|
130
|
+
itemType: _this.type,
|
|
131
|
+
itemIndex: entry[0]
|
|
132
|
+
};
|
|
133
|
+
if (quantity)
|
|
134
|
+
move.quantity = quantity;
|
|
135
|
+
return move;
|
|
136
|
+
}));
|
|
137
|
+
};
|
|
138
|
+
Material.prototype.moveItem = function (position, quantity) {
|
|
120
139
|
if (!this.length)
|
|
121
140
|
throw new Error('You are trying to move an item that does not exists');
|
|
122
|
-
|
|
123
|
-
if (rotation)
|
|
124
|
-
destination.rotation = rotation;
|
|
125
|
-
return {
|
|
126
|
-
kind: moves_1.MoveKind.MaterialMove,
|
|
127
|
-
type: moves_1.MaterialMoveType.Move,
|
|
128
|
-
itemType: this.type,
|
|
129
|
-
itemIndex: this.entries[0][0],
|
|
130
|
-
item: destination
|
|
131
|
-
};
|
|
141
|
+
return this.limit(1).moveItems(position, quantity)[0];
|
|
132
142
|
};
|
|
133
|
-
Material.prototype.moveItems = function (
|
|
143
|
+
Material.prototype.moveItems = function (position, quantity) {
|
|
134
144
|
var _this = this;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
+
if (position.rotation && !position.rotation.x && !position.rotation.y && !position.rotation.z)
|
|
146
|
+
delete position.rotation;
|
|
147
|
+
return this.process(this.entries.map(function (entry) {
|
|
148
|
+
var move = {
|
|
149
|
+
kind: moves_1.MoveKind.MaterialMove,
|
|
150
|
+
type: moves_1.MaterialMoveType.Move,
|
|
151
|
+
itemType: _this.type,
|
|
152
|
+
itemIndex: entry[0],
|
|
153
|
+
position: position
|
|
154
|
+
};
|
|
155
|
+
if (quantity)
|
|
156
|
+
move.quantity = quantity;
|
|
157
|
+
return move;
|
|
158
|
+
}));
|
|
159
|
+
};
|
|
160
|
+
Material.prototype.shuffle = function () {
|
|
161
|
+
return this.process([{
|
|
162
|
+
kind: moves_1.MoveKind.MaterialMove,
|
|
163
|
+
type: moves_1.MaterialMoveType.Shuffle,
|
|
164
|
+
itemType: this.type,
|
|
165
|
+
indexes: this.entries.map(function (entry) { return entry[0]; })
|
|
166
|
+
}])[0];
|
|
145
167
|
};
|
|
146
168
|
return Material;
|
|
147
169
|
}());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Material.js","sourceRoot":"","sources":["../../../src/material/items/Material.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Material.js","sourceRoot":"","sources":["../../../src/material/items/Material.ts"],"names":[],"mappings":";;;;;;AAEA,oEAAmC;AACnC,kCAAqH;AACrH,uDAAgC;AAChC,uDAAgC;AAChC,2DAAoC;AAKpC;IAME,kBAAY,IAAO,EAAE,KAAwB,EAAE,IAAiD;QAC9F,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAEO,sBAAG,GAAX,UAAY,OAA0B;QACpC,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;IACpD,CAAC;IAID,2BAAQ,GAAR,UAAY,KAAuC;QACjD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAlC,CAAkC,CAAC,CAAA;IACtE,CAAC;IAID,0BAAO,GAAP,UAAQ,GAAsD;QAC5D,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,IAAM,KAA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AAD,CAAC,AAxJD,IAwJC;AAxJY,4BAAQ"}
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* A material item is a piece of material in a game
|
|
3
3
|
*/
|
|
4
4
|
import { Coordinates, Location } from '../location';
|
|
5
|
-
export declare type MaterialItem<
|
|
5
|
+
export declare type MaterialItem<P extends number = number, L extends number = number, Id = any> = {
|
|
6
6
|
id?: Id;
|
|
7
|
-
location: Location<Player, LocationType>;
|
|
8
|
-
rotation?: Partial<Coordinates>;
|
|
9
7
|
quantity?: number;
|
|
8
|
+
} & ItemPosition<P, L>;
|
|
9
|
+
export declare type ItemPosition<P extends number = number, L extends number = number> = {
|
|
10
|
+
location: Location<P, L>;
|
|
11
|
+
rotation?: Partial<Coordinates>;
|
|
10
12
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MaterialItem } from './index';
|
|
2
|
+
import { LocationStrategy } from '../location';
|
|
3
|
+
import { MaterialMoveRandomized, MoveItem } from '../moves';
|
|
4
|
+
export declare class MaterialMutator<P extends number = number, M extends number = number, L extends number = number> {
|
|
5
|
+
readonly type: M;
|
|
6
|
+
items: MaterialItem<P, L>[];
|
|
7
|
+
locationsStrategies: Partial<Record<L, LocationStrategy<P, M, L>>>;
|
|
8
|
+
constructor(type: M, items: MaterialItem<P, L>[], locationsStrategies?: Partial<Record<L, LocationStrategy<P, M, L>>>);
|
|
9
|
+
applyMove(move: MaterialMoveRandomized<P, M, L>): void;
|
|
10
|
+
findMergeItem(newItem: MaterialItem<P, L>): MaterialItem<P, L> | undefined;
|
|
11
|
+
private addItem;
|
|
12
|
+
private applyAddItemStrategy;
|
|
13
|
+
private removeItem;
|
|
14
|
+
private applyRemoveItemStrategy;
|
|
15
|
+
private create;
|
|
16
|
+
private move;
|
|
17
|
+
getItemAfterMove(move: MoveItem<P, M, L>): MaterialItem<P, L>;
|
|
18
|
+
private delete;
|
|
19
|
+
private shuffle;
|
|
20
|
+
}
|