@gamepark/rules-api 7.0.0-beta.0 → 7.0.0-beta.2
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/Action.js +1 -2
- package/dist/Bot.js +15 -37
- package/dist/Bot.js.map +1 -1
- package/dist/Competitive.js +3 -8
- package/dist/Competitive.js.map +1 -1
- package/dist/Eliminations.js +2 -5
- package/dist/Eliminations.js.map +1 -1
- package/dist/GameSetup.js +1 -2
- package/dist/HiddenInformation.js +2 -5
- package/dist/HiddenInformation.js.map +1 -1
- package/dist/LocalMovePreview.js +1 -4
- package/dist/LocalMovePreview.js.map +1 -1
- package/dist/RandomMove.js +1 -2
- package/dist/Rules.js +49 -56
- package/dist/Rules.js.map +1 -1
- package/dist/SecretInformation.js +2 -5
- package/dist/SecretInformation.js.map +1 -1
- package/dist/TimeLimit.js +1 -4
- package/dist/TimeLimit.js.map +1 -1
- package/dist/Undo.js +2 -5
- package/dist/Undo.js.map +1 -1
- package/dist/UnpredictableMove.js +1 -5
- package/dist/UnpredictableMove.js.map +1 -1
- package/dist/index.js +16 -32
- package/dist/index.js.map +1 -1
- package/dist/material/HiddenMaterialRules.js +125 -180
- package/dist/material/HiddenMaterialRules.js.map +1 -1
- package/dist/material/MaterialGame.js +1 -2
- package/dist/material/MaterialGameSetup.js +52 -70
- package/dist/material/MaterialGameSetup.js.map +1 -1
- package/dist/material/MaterialRules.js +186 -250
- package/dist/material/MaterialRules.js.map +1 -1
- package/dist/material/SecretMaterialRules.js +9 -35
- package/dist/material/SecretMaterialRules.js.map +1 -1
- package/dist/material/index.js +11 -27
- package/dist/material/index.js.map +1 -1
- package/dist/material/items/Material.js +177 -262
- package/dist/material/items/Material.js.map +1 -1
- package/dist/material/items/MaterialDeck.js +10 -36
- package/dist/material/items/MaterialDeck.js.map +1 -1
- package/dist/material/items/MaterialItem.js +1 -2
- package/dist/material/items/MaterialMoney.js +89 -141
- package/dist/material/items/MaterialMoney.js.map +1 -1
- package/dist/material/items/MaterialMutator.js +108 -145
- package/dist/material/items/MaterialMutator.js.map +1 -1
- package/dist/material/items/index.js +5 -21
- package/dist/material/items/index.js.map +1 -1
- package/dist/material/location/Location.js +1 -14
- package/dist/material/location/Location.js.map +1 -1
- package/dist/material/location/LocationBuilder.js +26 -41
- package/dist/material/location/LocationBuilder.js.map +1 -1
- package/dist/material/location/index.js +3 -19
- package/dist/material/location/index.js.map +1 -1
- package/dist/material/location/strategy/FillGapStrategy.js +9 -16
- package/dist/material/location/strategy/FillGapStrategy.js.map +1 -1
- package/dist/material/location/strategy/LocationStrategy.js +1 -2
- package/dist/material/location/strategy/PositiveSequenceStrategy.js +26 -35
- package/dist/material/location/strategy/PositiveSequenceStrategy.js.map +1 -1
- package/dist/material/location/strategy/StackingStrategy.js +15 -22
- package/dist/material/location/strategy/StackingStrategy.js.map +1 -1
- package/dist/material/location/strategy/index.js +5 -23
- package/dist/material/location/strategy/index.js.map +1 -1
- package/dist/material/memory/GameMemory.js +10 -14
- package/dist/material/memory/GameMemory.js.map +1 -1
- package/dist/material/memory/PlayerMemory.js +13 -18
- package/dist/material/memory/PlayerMemory.js.map +1 -1
- package/dist/material/memory/index.js +2 -18
- package/dist/material/memory/index.js.map +1 -1
- package/dist/material/moves/CustomMove.js +4 -9
- package/dist/material/moves/CustomMove.js.map +1 -1
- package/dist/material/moves/MaterialMove.js +1 -2
- package/dist/material/moves/MaterialMoveBuilder.js +16 -32
- package/dist/material/moves/MaterialMoveBuilder.js.map +1 -1
- package/dist/material/moves/MoveKind.js +2 -5
- package/dist/material/moves/MoveKind.js.map +1 -1
- package/dist/material/moves/index.js +7 -23
- package/dist/material/moves/index.js.map +1 -1
- package/dist/material/moves/items/CreateItem.js +6 -12
- package/dist/material/moves/items/CreateItem.js.map +1 -1
- package/dist/material/moves/items/CreateItemsAtOnce.js +6 -12
- package/dist/material/moves/items/CreateItemsAtOnce.js.map +1 -1
- package/dist/material/moves/items/DeleteItem.js +6 -12
- package/dist/material/moves/items/DeleteItem.js.map +1 -1
- package/dist/material/moves/items/DeleteItemsAtOnce.js +6 -12
- package/dist/material/moves/items/DeleteItemsAtOnce.js.map +1 -1
- package/dist/material/moves/items/ItemMove.js +1 -2
- package/dist/material/moves/items/ItemMoveType.js +2 -5
- package/dist/material/moves/items/ItemMoveType.js.map +1 -1
- package/dist/material/moves/items/MoveItem.js +6 -12
- package/dist/material/moves/items/MoveItem.js.map +1 -1
- package/dist/material/moves/items/MoveItemsAtOnce.js +6 -12
- package/dist/material/moves/items/MoveItemsAtOnce.js.map +1 -1
- package/dist/material/moves/items/RollItem.js +6 -12
- package/dist/material/moves/items/RollItem.js.map +1 -1
- package/dist/material/moves/items/SelectItem.js +6 -12
- package/dist/material/moves/items/SelectItem.js.map +1 -1
- package/dist/material/moves/items/Shuffle.js +7 -14
- package/dist/material/moves/items/Shuffle.js.map +1 -1
- package/dist/material/moves/items/index.js +11 -27
- package/dist/material/moves/items/index.js.map +1 -1
- package/dist/material/moves/local/CloseTutorialPopup.js +4 -7
- package/dist/material/moves/local/CloseTutorialPopup.js.map +1 -1
- package/dist/material/moves/local/DisplayHelp.js +2 -5
- package/dist/material/moves/local/DisplayHelp.js.map +1 -1
- package/dist/material/moves/local/DropItem.js +1 -2
- package/dist/material/moves/local/LocalMove.js +2 -5
- package/dist/material/moves/local/LocalMove.js.map +1 -1
- package/dist/material/moves/local/SetTutorialStep.js +4 -7
- package/dist/material/moves/local/SetTutorialStep.js.map +1 -1
- package/dist/material/moves/local/index.js +5 -21
- package/dist/material/moves/local/index.js.map +1 -1
- package/dist/material/moves/rules/EndGame.js +4 -7
- package/dist/material/moves/rules/EndGame.js.map +1 -1
- package/dist/material/moves/rules/EndPlayerTurn.js +4 -7
- package/dist/material/moves/rules/EndPlayerTurn.js.map +1 -1
- package/dist/material/moves/rules/RuleMove.js +3 -7
- package/dist/material/moves/rules/RuleMove.js.map +1 -1
- package/dist/material/moves/rules/StartPlayerTurn.js +4 -7
- package/dist/material/moves/rules/StartPlayerTurn.js.map +1 -1
- package/dist/material/moves/rules/StartRule.js +4 -7
- package/dist/material/moves/rules/StartRule.js.map +1 -1
- package/dist/material/moves/rules/StartSimultaneousRule.js +4 -7
- package/dist/material/moves/rules/StartSimultaneousRule.js.map +1 -1
- package/dist/material/moves/rules/index.js +6 -22
- package/dist/material/moves/rules/index.js.map +1 -1
- package/dist/material/rules/MaterialRulesPart.js +38 -63
- package/dist/material/rules/MaterialRulesPart.js.map +1 -1
- package/dist/material/rules/PlayerTurnRule.js +20 -52
- package/dist/material/rules/PlayerTurnRule.js.map +1 -1
- package/dist/material/rules/RuleStep.js +1 -2
- package/dist/material/rules/SimultaneousRule.js +19 -51
- package/dist/material/rules/SimultaneousRule.js.map +1 -1
- package/dist/material/rules/index.js +4 -20
- package/dist/material/rules/index.js.map +1 -1
- package/dist/material/tutorial/TutorialState.js +1 -2
- package/dist/material/tutorial/index.js +1 -17
- package/dist/material/tutorial/index.js.map +1 -1
- package/dist/options/EnumArrayOption.js +3 -6
- package/dist/options/EnumArrayOption.js.map +1 -1
- package/dist/options/EnumOption.js +1 -4
- package/dist/options/EnumOption.js.map +1 -1
- package/dist/options/Option.js +1 -2
- package/dist/options/OptionSpecOf.js +1 -2
- package/dist/options/OptionsSpec.js +1 -2
- package/dist/options/OptionsValidationError.js +6 -28
- package/dist/options/OptionsValidationError.js.map +1 -1
- package/dist/options/PlayerEnumOption.js +19 -29
- package/dist/options/PlayerEnumOption.js.map +1 -1
- package/dist/options/PlayersOptionsSpec.js +1 -2
- package/dist/options/WithIdOption.js +1 -2
- package/dist/options/WithPlayerOptionsSpec.js +1 -4
- package/dist/options/WithPlayerOptionsSpec.js.map +1 -1
- package/dist/options/WithPlayersOptions.js +1 -2
- package/dist/options/index.js +12 -28
- package/dist/options/index.js.map +1 -1
- package/dist/options/isWithPlayerIdOptions.js +3 -6
- package/dist/options/isWithPlayerIdOptions.js.map +1 -1
- package/dist/utils/action-view.util.js +18 -25
- package/dist/utils/action-view.util.js.map +1 -1
- package/dist/utils/action.util.js +11 -16
- package/dist/utils/action.util.js.map +1 -1
- package/dist/utils/adjacent-groups.util.js +33 -41
- package/dist/utils/adjacent-groups.util.js.map +1 -1
- package/dist/utils/automatic-moves.util.js +10 -15
- package/dist/utils/automatic-moves.util.js.map +1 -1
- package/dist/utils/enum.util.js +7 -13
- package/dist/utils/enum.util.js.map +1 -1
- package/dist/utils/game-view.util.js +5 -8
- package/dist/utils/game-view.util.js.map +1 -1
- package/dist/utils/grid.hex.util.js +36 -88
- package/dist/utils/grid.hex.util.js.map +1 -1
- package/dist/utils/grid.squares.util.js +8 -19
- package/dist/utils/grid.squares.util.js.map +1 -1
- package/dist/utils/grid.util.js +1 -5
- package/dist/utils/grid.util.js.map +1 -1
- package/dist/utils/index.js +16 -32
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/listing.util.js +8 -13
- package/dist/utils/listing.util.js.map +1 -1
- package/dist/utils/loops.util.js +3 -6
- package/dist/utils/loops.util.js.map +1 -1
- package/dist/utils/money.util.js +54 -73
- package/dist/utils/money.util.js.map +1 -1
- package/dist/utils/neighbors.util.js +6 -10
- package/dist/utils/neighbors.util.js.map +1 -1
- package/dist/utils/polyhex.util.js +36 -56
- package/dist/utils/polyhex.util.js.map +1 -1
- package/dist/utils/random.util.js +2 -5
- package/dist/utils/random.util.js.map +1 -1
- package/dist/utils/rank.util.js +9 -13
- package/dist/utils/rank.util.js.map +1 -1
- package/package.json +43 -37
- package/dist/ApplyAutomaticMoves.d.ts +0 -2
- package/dist/ApplyAutomaticMoves.js +0 -25
- package/dist/ApplyAutomaticMoves.js.map +0 -1
- package/dist/DefaultGameSetup.d.ts +0 -7
- package/dist/DefaultGameSetup.js +0 -15
- package/dist/DefaultGameSetup.js.map +0 -1
- package/dist/Dummy.d.ts +0 -7
- package/dist/Dummy.js +0 -27
- package/dist/Dummy.js.map +0 -1
- package/dist/GameSetupCreator.d.ts +0 -4
- package/dist/GameSetupCreator.js +0 -3
- package/dist/GameSetupCreator.js.map +0 -1
- package/dist/IncompleteInformation.d.ts +0 -14
- package/dist/IncompleteInformation.js +0 -38
- package/dist/IncompleteInformation.js.map +0 -1
- package/dist/LoopWithFuse.d.ts +0 -4
- package/dist/LoopWithFuse.js +0 -15
- package/dist/LoopWithFuse.js.map +0 -1
- package/dist/Robot.d.ts +0 -1
- package/dist/Robot.js +0 -3
- package/dist/Robot.js.map +0 -1
- package/dist/RulesCreator.d.ts +0 -7
- package/dist/RulesCreator.js +0 -3
- package/dist/RulesCreator.js.map +0 -1
- package/dist/material/location/strategy/StakingStrategy.d.ts +0 -12
- package/dist/material/location/strategy/StakingStrategy.js +0 -32
- package/dist/material/location/strategy/StakingStrategy.js.map +0 -1
- package/dist/material/moves/items/ItemMovesBuilder.d.ts +0 -8
- package/dist/material/moves/items/ItemMovesBuilder.js +0 -34
- package/dist/material/moves/items/ItemMovesBuilder.js.map +0 -1
- package/dist/material/rules/MaterialMoveBuilder.d.ts +0 -9
- package/dist/material/rules/MaterialMoveBuilder.js +0 -28
- package/dist/material/rules/MaterialMoveBuilder.js.map +0 -1
- package/dist/material/rules/MaterialRulesMovesBuilder.d.ts +0 -12
- package/dist/material/rules/MaterialRulesMovesBuilder.js +0 -36
- package/dist/material/rules/MaterialRulesMovesBuilder.js.map +0 -1
- package/dist/setup/DefaultGameSetup.d.ts +0 -7
- package/dist/setup/DefaultGameSetup.js +0 -15
- package/dist/setup/DefaultGameSetup.js.map +0 -1
- package/dist/setup/GameSetup.d.ts +0 -3
- package/dist/setup/GameSetup.js +0 -3
- package/dist/setup/GameSetup.js.map +0 -1
- package/dist/setup/GameSetupCreator.d.ts +0 -4
- package/dist/setup/GameSetupCreator.js +0 -3
- package/dist/setup/GameSetupCreator.js.map +0 -1
- package/dist/setup/index.d.ts +0 -2
- package/dist/setup/index.js +0 -19
- package/dist/setup/index.js.map +0 -1
- package/dist/utils/EnumUtils.d.ts +0 -1
- package/dist/utils/EnumUtils.js +0 -8
- package/dist/utils/EnumUtils.js.map +0 -1
- package/dist/utils/coordinates.util.d.ts +0 -5
- package/dist/utils/coordinates.util.js +0 -16
- package/dist/utils/coordinates.util.js.map +0 -1
- package/dist/utils/isDeadEndMove.util.d.ts +0 -2
- package/dist/utils/isDeadEndMove.util.js +0 -19
- package/dist/utils/isDeadEndMove.util.js.map +0 -1
|
@@ -1,33 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.Material = void 0;
|
|
26
|
-
var es_toolkit_1 = require("es-toolkit");
|
|
27
|
-
var compat_1 = require("es-toolkit/compat");
|
|
28
|
-
var location_1 = require("../location");
|
|
29
|
-
var moves_1 = require("../moves");
|
|
30
|
-
var index_1 = require("./index");
|
|
1
|
+
import { isEqual, maxBy, minBy, sumBy } from 'es-toolkit';
|
|
2
|
+
import { orderBy } from 'es-toolkit/compat';
|
|
3
|
+
import { isSameLocationArea } from '../location';
|
|
4
|
+
import { ItemMoveType, MoveKind } from '../moves';
|
|
5
|
+
import { MaterialDeck, MaterialMoney } from './index';
|
|
31
6
|
/**
|
|
32
7
|
* The Material class is the core helper class that help manipulate the game items in a simple way.
|
|
33
8
|
* It includes two kind of functions: functions to filter items, and functions to build {@link ItemMove} objects.
|
|
@@ -37,7 +12,11 @@ var index_1 = require("./index");
|
|
|
37
12
|
* @typeparam M - Numeric enum of the types of material manipulated in the game
|
|
38
13
|
* @typeparam L - Numeric enum of the types of location in the game where the material can be located
|
|
39
14
|
*/
|
|
40
|
-
|
|
15
|
+
export class Material {
|
|
16
|
+
type;
|
|
17
|
+
items;
|
|
18
|
+
processMove;
|
|
19
|
+
entries;
|
|
41
20
|
/**
|
|
42
21
|
* Construct a new Material helper instance
|
|
43
22
|
* @param {number} type Type of items this instance will work on
|
|
@@ -45,9 +24,7 @@ var Material = /** @class */ (function () {
|
|
|
45
24
|
* @param {function} processMove if provided, this function will be executed on every move created with this instance
|
|
46
25
|
* @param {ItemEntry[]} entries The list of items to work on. Each entry consists of an array with the index of the item, and the item
|
|
47
26
|
*/
|
|
48
|
-
|
|
49
|
-
if (items === void 0) { items = []; }
|
|
50
|
-
if (entries === void 0) { entries = Array.from(items.entries()).filter(function (entry) { return entry[1].quantity !== 0; }); }
|
|
27
|
+
constructor(type, items = [], processMove, entries = Array.from(items.entries()).filter(entry => entry[1].quantity !== 0)) {
|
|
51
28
|
this.type = type;
|
|
52
29
|
this.items = items;
|
|
53
30
|
this.processMove = processMove;
|
|
@@ -59,10 +36,10 @@ var Material = /** @class */ (function () {
|
|
|
59
36
|
* @returns {this} the new Material instance
|
|
60
37
|
* @protected
|
|
61
38
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
39
|
+
new(entries) {
|
|
40
|
+
const Class = this.constructor;
|
|
64
41
|
return new Class(this.type, this.items, this.processMove, entries);
|
|
65
|
-
}
|
|
42
|
+
}
|
|
66
43
|
/**
|
|
67
44
|
* Use this function to collect all the items in the current Material instance.
|
|
68
45
|
* For example, you can filter then collect the matching items: this.material(type).location(locationType).getItems()
|
|
@@ -71,10 +48,10 @@ var Material = /** @class */ (function () {
|
|
|
71
48
|
* @param {function} predicate If provided, only the items matching the predicate will be returned
|
|
72
49
|
* @returns {MaterialItem[]} the items in this Material instance
|
|
73
50
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
51
|
+
getItems(predicate) {
|
|
52
|
+
const items = this.entries.map(entry => entry[1]);
|
|
76
53
|
return predicate ? items.filter(predicate) : items;
|
|
77
|
-
}
|
|
54
|
+
}
|
|
78
55
|
/**
|
|
79
56
|
* Use this function to collect this first item in the current Material instance.
|
|
80
57
|
* You can use {@link sort} to sort the items first.
|
|
@@ -82,91 +59,70 @@ var Material = /** @class */ (function () {
|
|
|
82
59
|
* @param {number | function} arg Index of the item, or predicate function
|
|
83
60
|
* @returns {MaterialItem | undefined} the item, or undefined if none match
|
|
84
61
|
*/
|
|
85
|
-
|
|
62
|
+
getItem(arg) {
|
|
86
63
|
if (typeof arg === 'number') {
|
|
87
|
-
|
|
64
|
+
const entry = this.entries.find(entry => entry[0] === arg);
|
|
88
65
|
if (!entry)
|
|
89
|
-
throw new Error(
|
|
66
|
+
throw new Error(`Could not find any item with index ${arg} for type ${this.type}`);
|
|
90
67
|
return entry[1];
|
|
91
68
|
}
|
|
92
69
|
else if (typeof arg === 'function') {
|
|
93
|
-
|
|
94
|
-
var item = _a[1];
|
|
95
|
-
return arg(item);
|
|
96
|
-
});
|
|
70
|
+
const entries = this.entries.filter(([, item]) => arg(item));
|
|
97
71
|
return entries.length ? entries[0][1] : undefined;
|
|
98
72
|
}
|
|
99
73
|
else {
|
|
100
74
|
return this.entries.length ? this.entries[0][1] : undefined;
|
|
101
75
|
}
|
|
102
|
-
}
|
|
76
|
+
}
|
|
103
77
|
/**
|
|
104
78
|
* @returns {number} index of the first item
|
|
105
79
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
};
|
|
80
|
+
getIndex() {
|
|
81
|
+
return this.entries[0]?.[0] ?? -1;
|
|
82
|
+
}
|
|
110
83
|
/**
|
|
111
84
|
* @returns {number[]} indexes of the items
|
|
112
85
|
*/
|
|
113
|
-
|
|
114
|
-
return this.entries.map(
|
|
115
|
-
}
|
|
86
|
+
getIndexes() {
|
|
87
|
+
return this.entries.map(entry => entry[0]);
|
|
88
|
+
}
|
|
116
89
|
/**
|
|
117
90
|
* Filter and return a new instance with only the items that match a specific index, or a specific index predicate
|
|
118
91
|
* @param {number | function} arg The index to keep, or the predicate matching the indexes to keep
|
|
119
92
|
*/
|
|
120
|
-
|
|
93
|
+
index(arg) {
|
|
121
94
|
switch (typeof arg) {
|
|
122
95
|
case 'function':
|
|
123
|
-
return this.filter(
|
|
96
|
+
return this.filter((_, index) => arg(index));
|
|
124
97
|
case 'number':
|
|
125
|
-
|
|
126
|
-
var index = _a[0];
|
|
127
|
-
return index === arg;
|
|
128
|
-
});
|
|
98
|
+
const item = this.entries.find(([index]) => index === arg);
|
|
129
99
|
return this.new(item ? [item] : []);
|
|
130
100
|
case 'undefined':
|
|
131
101
|
return this.new([]);
|
|
132
102
|
default:
|
|
133
|
-
|
|
134
|
-
var i = _a[0];
|
|
135
|
-
return arg.includes(i);
|
|
136
|
-
});
|
|
103
|
+
const items = this.entries.filter(([i]) => arg.includes(i));
|
|
137
104
|
return this.new(items);
|
|
138
105
|
}
|
|
139
|
-
}
|
|
106
|
+
}
|
|
140
107
|
/**
|
|
141
108
|
* @deprecated Use {@link index} instead
|
|
142
109
|
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
var i = _a[0];
|
|
146
|
-
return indexes.includes(i);
|
|
147
|
-
});
|
|
110
|
+
indexes(indexes) {
|
|
111
|
+
const items = this.entries.filter(([i]) => indexes.includes(i));
|
|
148
112
|
return this.new(items);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
},
|
|
157
|
-
enumerable: false,
|
|
158
|
-
configurable: true
|
|
159
|
-
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* @returns {number} number of items
|
|
116
|
+
*/
|
|
117
|
+
get length() {
|
|
118
|
+
return this.entries.length;
|
|
119
|
+
}
|
|
160
120
|
/**
|
|
161
121
|
* @returns {number} Sum of the quantity of all items
|
|
162
122
|
*/
|
|
163
|
-
|
|
164
|
-
return
|
|
165
|
-
|
|
166
|
-
var item = _a[1];
|
|
167
|
-
return (_b = item.quantity) !== null && _b !== void 0 ? _b : 1;
|
|
168
|
-
});
|
|
169
|
-
};
|
|
123
|
+
getQuantity() {
|
|
124
|
+
return sumBy(this.entries, ([, item]) => item.quantity ?? 1);
|
|
125
|
+
}
|
|
170
126
|
/**
|
|
171
127
|
* This function filter the items and returns a new instance with only the filtered items.
|
|
172
128
|
* This function is the top level filtering function, but other function can be used to simplify the code:
|
|
@@ -175,94 +131,72 @@ var Material = /** @class */ (function () {
|
|
|
175
131
|
* @param {function} predicate The predicate function. Takes every item and index, and keep the item if it returns true
|
|
176
132
|
* @returns {this} New instance with only the items that match the predicate
|
|
177
133
|
*/
|
|
178
|
-
|
|
179
|
-
return this.new(this.entries.filter(
|
|
180
|
-
|
|
181
|
-
return predicate(item, index);
|
|
182
|
-
}));
|
|
183
|
-
};
|
|
134
|
+
filter(predicate) {
|
|
135
|
+
return this.new(this.entries.filter(([index, item]) => predicate(item, index)));
|
|
136
|
+
}
|
|
184
137
|
/**
|
|
185
138
|
* Filters the items based on their ids.
|
|
186
139
|
*
|
|
187
140
|
* @param {function | string | number | Record} arg Id to keep, or predicate function to match the ids of the items to keep
|
|
188
141
|
* @returns {this} New instance with only the items which ids match the argument
|
|
189
142
|
*/
|
|
190
|
-
|
|
191
|
-
return this.filter(function (
|
|
192
|
-
|
|
193
|
-
return typeof arg === 'function' ? arg(id) : (0, es_toolkit_1.isEqual)(id, arg);
|
|
194
|
-
});
|
|
195
|
-
};
|
|
143
|
+
id(arg) {
|
|
144
|
+
return this.filter(({ id }) => typeof arg === 'function' ? arg(id) : isEqual(id, arg));
|
|
145
|
+
}
|
|
196
146
|
/**
|
|
197
147
|
* Filters the items based on their location type, or their location.
|
|
198
148
|
*
|
|
199
149
|
* @param {function | number} arg Location type to keep, or predicate function to match the location of the items to keep
|
|
200
150
|
* @returns {this} New instance with only the items which locations match the argument
|
|
201
151
|
*/
|
|
202
|
-
|
|
203
|
-
return this.filter(function (
|
|
204
|
-
|
|
205
|
-
return typeof arg === 'function' ? arg(location) : location.type === arg;
|
|
206
|
-
});
|
|
207
|
-
};
|
|
152
|
+
location(arg) {
|
|
153
|
+
return this.filter(({ location }) => typeof arg === 'function' ? arg(location) : location.type === arg);
|
|
154
|
+
}
|
|
208
155
|
/**
|
|
209
156
|
* Filters the items based on their rotation (item.location.rotation)
|
|
210
157
|
*
|
|
211
158
|
* @param {function | string | number | boolean | Record} arg rotation to keep, or predicate function to match the rotations of the items to keep
|
|
212
159
|
* @returns {this} New instance with only the items which rotation match the argument
|
|
213
160
|
*/
|
|
214
|
-
|
|
215
|
-
return this.location(function (
|
|
216
|
-
|
|
217
|
-
return typeof arg === 'function' ? arg(rotation) : (0, es_toolkit_1.isEqual)(rotation, arg);
|
|
218
|
-
});
|
|
219
|
-
};
|
|
161
|
+
rotation(arg) {
|
|
162
|
+
return this.location(({ rotation }) => typeof arg === 'function' ? arg(rotation) : isEqual(rotation, arg));
|
|
163
|
+
}
|
|
220
164
|
/**
|
|
221
165
|
* Filters the items based on their owner (item.location.player)
|
|
222
166
|
*
|
|
223
167
|
* @param {function | number} arg player id to keep, or predicate function to match the owner player of the items to keep
|
|
224
168
|
* @returns {this} New instance with only the items which owner match the argument
|
|
225
169
|
*/
|
|
226
|
-
|
|
227
|
-
return this.location(function (
|
|
228
|
-
|
|
229
|
-
return typeof arg === 'function' ? arg(player) : player === arg;
|
|
230
|
-
});
|
|
231
|
-
};
|
|
170
|
+
player(arg) {
|
|
171
|
+
return this.location(({ player }) => typeof arg === 'function' ? arg(player) : player === arg);
|
|
172
|
+
}
|
|
232
173
|
/**
|
|
233
174
|
* Filters the items based on their location's id (item.location.id)
|
|
234
175
|
*
|
|
235
176
|
* @param {function | number} arg location id to keep, or predicate function to match the location id of the items to keep
|
|
236
177
|
* @returns {this} New instance with only the items which location id match the argument
|
|
237
178
|
*/
|
|
238
|
-
|
|
239
|
-
return this.location(function (
|
|
240
|
-
|
|
241
|
-
return typeof arg === 'function' ? arg(id) : (0, es_toolkit_1.isEqual)(id, arg);
|
|
242
|
-
});
|
|
243
|
-
};
|
|
179
|
+
locationId(arg) {
|
|
180
|
+
return this.location(({ id }) => typeof arg === 'function' ? arg(id) : isEqual(id, arg));
|
|
181
|
+
}
|
|
244
182
|
/**
|
|
245
183
|
* Filters the items based on their location's parent (item.location.parent).
|
|
246
184
|
*
|
|
247
185
|
* @param {function | number} arg location parent to keep, or predicate function to match the location parent of the items to keep
|
|
248
186
|
* @returns {this} New instance with only the items which location parent match the argument
|
|
249
187
|
*/
|
|
250
|
-
|
|
251
|
-
return this.location(function (
|
|
252
|
-
|
|
253
|
-
return typeof arg === 'function' ? arg(parent) : (0, es_toolkit_1.isEqual)(parent, arg);
|
|
254
|
-
});
|
|
255
|
-
};
|
|
188
|
+
parent(arg) {
|
|
189
|
+
return this.location(({ parent }) => typeof arg === 'function' ? arg(parent) : isEqual(parent, arg));
|
|
190
|
+
}
|
|
256
191
|
/**
|
|
257
192
|
* Filters the items that are selected (item.selected).
|
|
258
193
|
*
|
|
259
194
|
* @param {number | boolean} selected The selected value to compare (default is true)
|
|
260
195
|
* @returns {this} New instance with only the items which are selected
|
|
261
196
|
*/
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
};
|
|
197
|
+
selected(selected = true) {
|
|
198
|
+
return this.filter(item => (item.selected ?? false) === selected);
|
|
199
|
+
}
|
|
266
200
|
/**
|
|
267
201
|
* Keep only the item that has the minimum value returned by the selector argument.
|
|
268
202
|
* See {@link minBy} from Lodash
|
|
@@ -270,10 +204,10 @@ var Material = /** @class */ (function () {
|
|
|
270
204
|
* @param {function} selector The function that evaluate the item's value
|
|
271
205
|
* @returns {this} New instance with only the item which has the minimum value
|
|
272
206
|
*/
|
|
273
|
-
|
|
274
|
-
|
|
207
|
+
minBy(selector) {
|
|
208
|
+
const min = minBy(this.entries, entry => selector(entry[1]));
|
|
275
209
|
return this.new(min ? [min] : []);
|
|
276
|
-
}
|
|
210
|
+
}
|
|
277
211
|
/**
|
|
278
212
|
* Keep only the item that has the maximum value returned by the selector argument.
|
|
279
213
|
* See {@link maxBy} from Lodash
|
|
@@ -281,10 +215,10 @@ var Material = /** @class */ (function () {
|
|
|
281
215
|
* @param {function} selector The function that evaluate the item's value
|
|
282
216
|
* @returns {this} New instance with only the item which has the maximum value
|
|
283
217
|
*/
|
|
284
|
-
|
|
285
|
-
|
|
218
|
+
maxBy(selector) {
|
|
219
|
+
const max = maxBy(this.entries, entry => selector(entry[1]));
|
|
286
220
|
return this.new(max ? [max] : []);
|
|
287
|
-
}
|
|
221
|
+
}
|
|
288
222
|
/**
|
|
289
223
|
* Return a new material instance which items are ordered based on provided selector functions.
|
|
290
224
|
* See {@link orderBy} from Lodash
|
|
@@ -292,14 +226,10 @@ var Material = /** @class */ (function () {
|
|
|
292
226
|
* @param {...function} selectors The function or functions that evaluate each item's value
|
|
293
227
|
* @returns {this} New instance with items ordered by the selector functions
|
|
294
228
|
*/
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
298
|
-
selectors[_i] = arguments[_i];
|
|
299
|
-
}
|
|
300
|
-
var orderedItems = (0, compat_1.orderBy)(this.entries, selectors.map(function (s) { return function (entry) { return s(entry[1]); }; }));
|
|
229
|
+
sort(...selectors) {
|
|
230
|
+
let orderedItems = orderBy(this.entries, selectors.map((s) => (entry) => s(entry[1])));
|
|
301
231
|
return this.new(orderedItems);
|
|
302
|
-
}
|
|
232
|
+
}
|
|
303
233
|
/**
|
|
304
234
|
* Return a new material instance with only the first N items.
|
|
305
235
|
* You have to use {@link sort} first as the items are ordered initially by index, which is not relevant.
|
|
@@ -308,56 +238,54 @@ var Material = /** @class */ (function () {
|
|
|
308
238
|
* @param count Number of items to keep
|
|
309
239
|
* @returns {this} New instance with only the first "count" items
|
|
310
240
|
*/
|
|
311
|
-
|
|
241
|
+
limit(count) {
|
|
312
242
|
return this.new(this.entries.slice(0, count));
|
|
313
|
-
}
|
|
314
|
-
|
|
243
|
+
}
|
|
244
|
+
process(moves) {
|
|
315
245
|
if (this.processMove) {
|
|
316
|
-
for (
|
|
317
|
-
var move = moves_2[_i];
|
|
246
|
+
for (const move of moves) {
|
|
318
247
|
this.processMove(move);
|
|
319
248
|
}
|
|
320
249
|
}
|
|
321
250
|
return moves;
|
|
322
|
-
}
|
|
251
|
+
}
|
|
323
252
|
/**
|
|
324
253
|
* Prepare a move that will create a new item
|
|
325
254
|
* @param {MaterialItem} item The item to create
|
|
326
255
|
* @returns {CreateItem} the move that creates an item when executed
|
|
327
256
|
*/
|
|
328
|
-
|
|
257
|
+
createItem(item) {
|
|
329
258
|
return this.createItems([item])[0];
|
|
330
|
-
}
|
|
259
|
+
}
|
|
331
260
|
/**
|
|
332
261
|
* Prepare a list of moves to create new items
|
|
333
262
|
* @param {MaterialItem[]} items The items to create
|
|
334
263
|
* @returns {CreateItem[]} the moves that creates the new items when executed
|
|
335
264
|
*/
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
};
|
|
265
|
+
createItems(items) {
|
|
266
|
+
return this.process(items.map(item => ({
|
|
267
|
+
kind: MoveKind.ItemMove,
|
|
268
|
+
type: ItemMoveType.Create,
|
|
269
|
+
itemType: this.type,
|
|
270
|
+
item
|
|
271
|
+
})));
|
|
272
|
+
}
|
|
345
273
|
/**
|
|
346
274
|
* Prepare one move to create new items
|
|
347
275
|
* @param {MaterialItem[]} items The items to create
|
|
348
276
|
* @returns {CreateItemsAtOnce} the move that creates the new items when executed
|
|
349
277
|
*/
|
|
350
|
-
|
|
351
|
-
|
|
278
|
+
createItemsAtOnce(items) {
|
|
279
|
+
const move = { kind: MoveKind.ItemMove, type: ItemMoveType.CreateAtOnce, itemType: this.type, items };
|
|
352
280
|
return this.process([move])[0];
|
|
353
|
-
}
|
|
281
|
+
}
|
|
354
282
|
/**
|
|
355
283
|
* Prepare a move that will delete current first item in this material instance
|
|
356
284
|
*
|
|
357
285
|
* @param {number | undefined} quantity Optional: for items with a quantity, the number of items to remove. If undefined, the item is completely removed
|
|
358
286
|
* @returns {DeleteItem} the move that delete the item, or a part of its quantity, when executed
|
|
359
287
|
*/
|
|
360
|
-
|
|
288
|
+
deleteItem(quantity) {
|
|
361
289
|
switch (this.length) {
|
|
362
290
|
case 0:
|
|
363
291
|
throw new Error('You are trying to delete an item that does not exists');
|
|
@@ -366,36 +294,35 @@ var Material = /** @class */ (function () {
|
|
|
366
294
|
default:
|
|
367
295
|
return this.limit(1).deleteItems(quantity)[0];
|
|
368
296
|
}
|
|
369
|
-
}
|
|
297
|
+
}
|
|
370
298
|
/**
|
|
371
299
|
* Prepare moves that will delete all the items in this material instance
|
|
372
300
|
*
|
|
373
301
|
* @param {number | undefined} quantity Optional: for items with a quantity, the number of items to remove. If undefined, the items are completely removed
|
|
374
302
|
* @returns {DeleteItem[]} the moves that delete the items, or a part of their quantity, when executed
|
|
375
303
|
*/
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
itemType: _this.type,
|
|
304
|
+
deleteItems(quantity) {
|
|
305
|
+
return this.process(this.entries.map(entry => {
|
|
306
|
+
const move = {
|
|
307
|
+
kind: MoveKind.ItemMove,
|
|
308
|
+
type: ItemMoveType.Delete,
|
|
309
|
+
itemType: this.type,
|
|
383
310
|
itemIndex: entry[0]
|
|
384
311
|
};
|
|
385
312
|
if (quantity)
|
|
386
313
|
move.quantity = quantity;
|
|
387
314
|
return move;
|
|
388
315
|
}));
|
|
389
|
-
}
|
|
316
|
+
}
|
|
390
317
|
/**
|
|
391
318
|
* Prepare one move that will delete all the items in this material instance
|
|
392
319
|
*
|
|
393
320
|
* @returns {DeleteItemsAtOnce} the move that delete the items when executed
|
|
394
321
|
*/
|
|
395
|
-
|
|
396
|
-
|
|
322
|
+
deleteItemsAtOnce() {
|
|
323
|
+
const moves = { kind: MoveKind.ItemMove, type: ItemMoveType.DeleteAtOnce, itemType: this.type, indexes: this.getIndexes() };
|
|
397
324
|
return this.process([moves])[0];
|
|
398
|
-
}
|
|
325
|
+
}
|
|
399
326
|
/**
|
|
400
327
|
* Prepare a move that will change the location of the current first item in this material instance
|
|
401
328
|
*
|
|
@@ -403,7 +330,7 @@ var Material = /** @class */ (function () {
|
|
|
403
330
|
* @param {number | undefined} quantity Optional: for items with a quantity, the number of items to move. If undefined, the item is completely moved.
|
|
404
331
|
* @returns {MoveItem} the move that will change the location of the item (or a part of its quantity) when executed
|
|
405
332
|
*/
|
|
406
|
-
|
|
333
|
+
moveItem(location, quantity) {
|
|
407
334
|
switch (this.length) {
|
|
408
335
|
case 0:
|
|
409
336
|
throw new Error('You are trying to move an item that does not exists');
|
|
@@ -412,7 +339,7 @@ var Material = /** @class */ (function () {
|
|
|
412
339
|
default:
|
|
413
340
|
return this.limit(1).moveItems(location, quantity)[0];
|
|
414
341
|
}
|
|
415
|
-
}
|
|
342
|
+
}
|
|
416
343
|
/**
|
|
417
344
|
* Prepare moves that will change the location of all the items in this material instance
|
|
418
345
|
*
|
|
@@ -420,49 +347,45 @@ var Material = /** @class */ (function () {
|
|
|
420
347
|
* @param {number | undefined} quantity Optional: for items with a quantity, the number of items to move. If undefined, the items are completely moved.
|
|
421
348
|
* @returns {MoveItem[]} the moves that will change the location of the items (or a part of their quantity) when executed
|
|
422
349
|
*/
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
itemType: _this.type,
|
|
350
|
+
moveItems(location, quantity) {
|
|
351
|
+
const getLocation = typeof location === 'function' ? location : () => location;
|
|
352
|
+
return this.process(this.entries.map(entry => {
|
|
353
|
+
const location = getLocation(entry[1], entry[0]);
|
|
354
|
+
const move = {
|
|
355
|
+
kind: MoveKind.ItemMove,
|
|
356
|
+
type: ItemMoveType.Move,
|
|
357
|
+
itemType: this.type,
|
|
432
358
|
itemIndex: entry[0],
|
|
433
|
-
location
|
|
359
|
+
location
|
|
434
360
|
};
|
|
435
361
|
if (quantity)
|
|
436
362
|
move.quantity = quantity;
|
|
437
363
|
return move;
|
|
438
364
|
}));
|
|
439
|
-
}
|
|
365
|
+
}
|
|
440
366
|
/**
|
|
441
367
|
* Prepare one move that will change the location of all the items in this material instance
|
|
442
368
|
*
|
|
443
369
|
* @param {Location} location The new location of the items. It can only be the same location for every item.
|
|
444
370
|
* @returns {MoveItemsAtOnce} the move that will change the location of the items when executed
|
|
445
371
|
*/
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
kind:
|
|
449
|
-
type:
|
|
372
|
+
moveItemsAtOnce(location) {
|
|
373
|
+
const move = {
|
|
374
|
+
kind: MoveKind.ItemMove,
|
|
375
|
+
type: ItemMoveType.MoveAtOnce,
|
|
450
376
|
itemType: this.type,
|
|
451
|
-
indexes: this.entries.map(
|
|
452
|
-
|
|
453
|
-
return index;
|
|
454
|
-
}),
|
|
455
|
-
location: location
|
|
377
|
+
indexes: this.entries.map(([index]) => index),
|
|
378
|
+
location
|
|
456
379
|
};
|
|
457
380
|
return this.process([move])[0];
|
|
458
|
-
}
|
|
381
|
+
}
|
|
459
382
|
/**
|
|
460
383
|
* Prepare a move that will select current first item in this material instance
|
|
461
384
|
*
|
|
462
385
|
* @param {number | undefined} quantity Optional: for items with a quantity, the number of items to select. If undefined, the item is completely selected.
|
|
463
386
|
* @returns {SelectItem} the move that will select the item (or a part of its quantity) when executed
|
|
464
387
|
*/
|
|
465
|
-
|
|
388
|
+
selectItem(quantity) {
|
|
466
389
|
switch (this.length) {
|
|
467
390
|
case 0:
|
|
468
391
|
throw new Error('You are trying to select an item that does not exists');
|
|
@@ -471,34 +394,33 @@ var Material = /** @class */ (function () {
|
|
|
471
394
|
default:
|
|
472
395
|
return this.limit(1).selectItems(quantity)[0];
|
|
473
396
|
}
|
|
474
|
-
}
|
|
397
|
+
}
|
|
475
398
|
/**
|
|
476
399
|
* Prepare a move that will select all the items in this material instance
|
|
477
400
|
*
|
|
478
401
|
* @param {number | undefined} quantity Optional: for items with a quantity, the number of items to select. If undefined, the items are completely selected.
|
|
479
402
|
* @returns {SelectItem[]} the moves that will select the items (or a part of their quantity) when executed
|
|
480
403
|
*/
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
itemType: _this.type,
|
|
404
|
+
selectItems(quantity) {
|
|
405
|
+
return this.process(this.entries.map(entry => {
|
|
406
|
+
const move = {
|
|
407
|
+
kind: MoveKind.ItemMove,
|
|
408
|
+
type: ItemMoveType.Select,
|
|
409
|
+
itemType: this.type,
|
|
488
410
|
itemIndex: entry[0]
|
|
489
411
|
};
|
|
490
412
|
if (quantity)
|
|
491
413
|
move.quantity = quantity;
|
|
492
414
|
return move;
|
|
493
415
|
}));
|
|
494
|
-
}
|
|
416
|
+
}
|
|
495
417
|
/**
|
|
496
418
|
* Prepare a move that will unselect current first item in this material instance
|
|
497
419
|
*
|
|
498
420
|
* @param {number | undefined} quantity Optional: for items with a quantity, the number of items to unselect. If undefined, the item is completely unselected.
|
|
499
421
|
* @returns {SelectItem} the move that will unselect the item (or a part of its quantity) when executed
|
|
500
422
|
*/
|
|
501
|
-
|
|
423
|
+
unselectItem(quantity) {
|
|
502
424
|
switch (this.length) {
|
|
503
425
|
case 0:
|
|
504
426
|
throw new Error('You are trying to select an item that does not exists');
|
|
@@ -507,20 +429,19 @@ var Material = /** @class */ (function () {
|
|
|
507
429
|
default:
|
|
508
430
|
return this.limit(1).unselectItems(quantity)[0];
|
|
509
431
|
}
|
|
510
|
-
}
|
|
432
|
+
}
|
|
511
433
|
/**
|
|
512
434
|
* Prepare a move that will unselect all the items in this material instance
|
|
513
435
|
*
|
|
514
436
|
* @param {number | undefined} quantity Optional: for items with a quantity, the number of items to unselect. If undefined, the items are completely unselected.
|
|
515
437
|
* @returns {SelectItem[]} the moves that will unselect the items (or a part of their quantity) when executed
|
|
516
438
|
*/
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
itemType: _this.type,
|
|
439
|
+
unselectItems(quantity) {
|
|
440
|
+
return this.process(this.entries.map(entry => {
|
|
441
|
+
const move = {
|
|
442
|
+
kind: MoveKind.ItemMove,
|
|
443
|
+
type: ItemMoveType.Select,
|
|
444
|
+
itemType: this.type,
|
|
524
445
|
itemIndex: entry[0],
|
|
525
446
|
selected: false
|
|
526
447
|
};
|
|
@@ -528,7 +449,7 @@ var Material = /** @class */ (function () {
|
|
|
528
449
|
move.quantity = quantity;
|
|
529
450
|
return move;
|
|
530
451
|
}));
|
|
531
|
-
}
|
|
452
|
+
}
|
|
532
453
|
/**
|
|
533
454
|
* Prepare a move that will rotate current first item in this material instance.
|
|
534
455
|
* This function creates a {@link MoveItem} but copies the existing location values, only replacing the rotation property.
|
|
@@ -537,7 +458,7 @@ var Material = /** @class */ (function () {
|
|
|
537
458
|
* In case of a function, process the value based on the item state.
|
|
538
459
|
* @returns {MoveItem} the move that will rotate the item when executed
|
|
539
460
|
*/
|
|
540
|
-
|
|
461
|
+
rotateItem(arg) {
|
|
541
462
|
switch (this.length) {
|
|
542
463
|
case 0:
|
|
543
464
|
throw new Error('You are trying to rotate an item that does not exists');
|
|
@@ -546,7 +467,7 @@ var Material = /** @class */ (function () {
|
|
|
546
467
|
default:
|
|
547
468
|
return this.limit(1).rotateItems(arg)[0];
|
|
548
469
|
}
|
|
549
|
-
}
|
|
470
|
+
}
|
|
550
471
|
/**
|
|
551
472
|
* Prepare a move that will rotate all the items in this material instance.
|
|
552
473
|
* This function creates an array of {@link MoveItem} but copies the existing locations values, only replacing the rotation property.
|
|
@@ -555,36 +476,35 @@ var Material = /** @class */ (function () {
|
|
|
555
476
|
* In case of a function, process the value based on the item state.
|
|
556
477
|
* @returns {MoveItem[]} the moves that will rotate the item when executed
|
|
557
478
|
*/
|
|
558
|
-
|
|
559
|
-
return this.moveItems(
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
return rotation !== undefined ? (
|
|
479
|
+
rotateItems(arg) {
|
|
480
|
+
return this.moveItems(item => {
|
|
481
|
+
const rotation = typeof arg === 'function' ? arg(item) : arg;
|
|
482
|
+
const { rotation: oldRotation, ...location } = item.location;
|
|
483
|
+
return rotation !== undefined ? ({ ...location, rotation }) : location;
|
|
563
484
|
});
|
|
564
|
-
}
|
|
485
|
+
}
|
|
565
486
|
/**
|
|
566
487
|
* Prepare a move that will shuffle all the items in the current material instance
|
|
567
488
|
* @returns {Shuffle} the move that shuffle the items when executed
|
|
568
489
|
*/
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
if (process.env.NODE_ENV === 'development' && this.entries.some(function (e) { return !(0, location_1.isSameLocationArea)(e[1].location, _this.entries[0][1].location); })) {
|
|
490
|
+
shuffle() {
|
|
491
|
+
if (process.env.NODE_ENV === 'development' && this.entries.some(e => !isSameLocationArea(e[1].location, this.entries[0][1].location))) {
|
|
572
492
|
console.warn('Calling shuffle on items with different location areas might be a mistake.');
|
|
573
493
|
}
|
|
574
494
|
return this.process([{
|
|
575
|
-
kind:
|
|
576
|
-
type:
|
|
495
|
+
kind: MoveKind.ItemMove,
|
|
496
|
+
type: ItemMoveType.Shuffle,
|
|
577
497
|
itemType: this.type,
|
|
578
|
-
indexes: this.entries.map(
|
|
498
|
+
indexes: this.entries.map(entry => entry[0])
|
|
579
499
|
}])[0];
|
|
580
|
-
}
|
|
500
|
+
}
|
|
581
501
|
/**
|
|
582
502
|
* Prepare a move that will roll the current first item in this material instance. See {@link RollItem}.
|
|
583
503
|
*
|
|
584
504
|
* @param {Location | function} location The new location of the item. It can be a function to process the location based on the item current state.
|
|
585
505
|
* @returns {RollItem} the move that rolls the item when executed
|
|
586
506
|
*/
|
|
587
|
-
|
|
507
|
+
rollItem(location) {
|
|
588
508
|
switch (this.length) {
|
|
589
509
|
case 0:
|
|
590
510
|
throw new Error('You are trying to roll an item that does not exists');
|
|
@@ -593,46 +513,41 @@ var Material = /** @class */ (function () {
|
|
|
593
513
|
default:
|
|
594
514
|
return this.limit(1).rollItems(location)[0];
|
|
595
515
|
}
|
|
596
|
-
}
|
|
516
|
+
}
|
|
597
517
|
/**
|
|
598
518
|
* Prepare a move that will roll all the items in this material instance. See {@link RollItem}.
|
|
599
519
|
*
|
|
600
520
|
* @param {Location | function} location The new location of the items. It can be a function to process the location based on each item current state.
|
|
601
521
|
* @returns {RollItem[]} the moves that rolls the items when executed
|
|
602
522
|
*/
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
return this.process(this.entries.map(function (entry) {
|
|
608
|
-
var location = getLocation(entry[1]);
|
|
523
|
+
rollItems(location = (item) => item.location) {
|
|
524
|
+
const getLocation = typeof location === 'function' ? location : () => location;
|
|
525
|
+
return this.process(this.entries.map(entry => {
|
|
526
|
+
const location = getLocation(entry[1]);
|
|
609
527
|
return ({
|
|
610
|
-
kind:
|
|
611
|
-
type:
|
|
612
|
-
itemType:
|
|
528
|
+
kind: MoveKind.ItemMove,
|
|
529
|
+
type: ItemMoveType.Roll,
|
|
530
|
+
itemType: this.type,
|
|
613
531
|
itemIndex: entry[0],
|
|
614
|
-
location
|
|
532
|
+
location
|
|
615
533
|
});
|
|
616
534
|
}));
|
|
617
|
-
}
|
|
535
|
+
}
|
|
618
536
|
/**
|
|
619
537
|
* Return a new {@link MaterialDeck} helper class, to deal cards easily.
|
|
620
538
|
*
|
|
621
539
|
* @param selector The sort to apply on the deck. See {@link sort}. Defaults to -item.location.x
|
|
622
540
|
*/
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
};
|
|
541
|
+
deck(selector = item => -item.location.x) {
|
|
542
|
+
return new MaterialDeck(this.type, this.items, this.processMove, this.entries).sort(selector);
|
|
543
|
+
}
|
|
627
544
|
/**
|
|
628
545
|
* Return a new {@link MaterialMoney} helper class, to deal with moving money units easily.
|
|
629
546
|
*
|
|
630
547
|
* @param units The different units that exists in stock to count this money
|
|
631
548
|
*/
|
|
632
|
-
|
|
633
|
-
return new
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
}());
|
|
637
|
-
exports.Material = Material;
|
|
549
|
+
money(units) {
|
|
550
|
+
return new MaterialMoney(this.type, units, this.items, this.processMove, this.entries);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
638
553
|
//# sourceMappingURL=Material.js.map
|