@gamepark/rules-api 6.18.0 → 6.20.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.
Files changed (243) hide show
  1. package/dist/Action.d.ts +25 -25
  2. package/dist/Action.js +61 -61
  3. package/dist/Action.js.map +1 -1
  4. package/dist/ApplyAutomaticMoves.d.ts +2 -2
  5. package/dist/ApplyAutomaticMoves.js +24 -24
  6. package/dist/ApplyAutomaticMoves.js.map +1 -1
  7. package/dist/Competitive.d.ts +13 -13
  8. package/dist/Competitive.js +45 -45
  9. package/dist/Competitive.js.map +1 -1
  10. package/dist/DefaultGameSetup.d.ts +7 -7
  11. package/dist/DefaultGameSetup.js +14 -14
  12. package/dist/Dummy.d.ts +7 -7
  13. package/dist/Dummy.js +26 -26
  14. package/dist/Dummy.js.map +1 -1
  15. package/dist/Eliminations.d.ts +5 -5
  16. package/dist/Eliminations.js +8 -8
  17. package/dist/GameSetup.d.ts +3 -3
  18. package/dist/GameSetup.js +2 -2
  19. package/dist/GameSetupCreator.d.ts +4 -4
  20. package/dist/GameSetupCreator.js +2 -2
  21. package/dist/IncompleteInformation.d.ts +14 -14
  22. package/dist/IncompleteInformation.js +37 -37
  23. package/dist/IncompleteInformation.js.map +1 -1
  24. package/dist/LocalMovePreview.d.ts +4 -0
  25. package/dist/LocalMovePreview.js +8 -0
  26. package/dist/LocalMovePreview.js.map +1 -0
  27. package/dist/LoopWithFuse.d.ts +4 -4
  28. package/dist/LoopWithFuse.js +14 -14
  29. package/dist/LoopWithFuse.js.map +1 -1
  30. package/dist/RandomMove.d.ts +7 -7
  31. package/dist/RandomMove.js +14 -14
  32. package/dist/Robot.d.ts +1 -1
  33. package/dist/Robot.js +2 -2
  34. package/dist/Rules.d.ts +18 -17
  35. package/dist/Rules.js +78 -78
  36. package/dist/Rules.js.map +1 -1
  37. package/dist/RulesCreator.d.ts +7 -7
  38. package/dist/RulesCreator.js +2 -2
  39. package/dist/TimeLimit.d.ts +10 -10
  40. package/dist/TimeLimit.js +12 -12
  41. package/dist/TimeLimit.js.map +1 -1
  42. package/dist/Undo.d.ts +6 -6
  43. package/dist/Undo.js +8 -8
  44. package/dist/UnpredictableMove.d.ts +5 -5
  45. package/dist/UnpredictableMove.js +5 -5
  46. package/dist/index.d.ts +21 -20
  47. package/dist/index.js +37 -36
  48. package/dist/index.js.map +1 -1
  49. package/dist/material/HiddenMaterialRules.d.ts +36 -35
  50. package/dist/material/HiddenMaterialRules.js +245 -245
  51. package/dist/material/HiddenMaterialRules.js.map +1 -1
  52. package/dist/material/MaterialGame.d.ts +15 -15
  53. package/dist/material/MaterialGame.js +2 -2
  54. package/dist/material/MaterialGameSetup.d.ts +21 -21
  55. package/dist/material/MaterialGameSetup.js +75 -75
  56. package/dist/material/MaterialGameSetup.js.map +1 -1
  57. package/dist/material/MaterialRules.d.ts +44 -44
  58. package/dist/material/MaterialRules.js +242 -242
  59. package/dist/material/MaterialRules.js.map +1 -1
  60. package/dist/material/SecretMaterialRules.d.ts +13 -13
  61. package/dist/material/SecretMaterialRules.js +37 -37
  62. package/dist/material/index.d.ts +10 -10
  63. package/dist/material/index.js +26 -26
  64. package/dist/material/items/Material.d.ts +59 -57
  65. package/dist/material/items/Material.js +406 -376
  66. package/dist/material/items/Material.js.map +1 -1
  67. package/dist/material/items/MaterialItem.d.ts +7 -7
  68. package/dist/material/items/MaterialItem.js +2 -2
  69. package/dist/material/items/MaterialMutator.d.ts +31 -31
  70. package/dist/material/items/MaterialMutator.js +277 -272
  71. package/dist/material/items/MaterialMutator.js.map +1 -1
  72. package/dist/material/items/index.d.ts +3 -3
  73. package/dist/material/items/index.js +19 -19
  74. package/dist/material/location/Location.d.ts +11 -11
  75. package/dist/material/location/Location.js +2 -2
  76. package/dist/material/location/LocationBuilder.d.ts +12 -12
  77. package/dist/material/location/LocationBuilder.js +40 -40
  78. package/dist/material/location/index.d.ts +3 -3
  79. package/dist/material/location/index.js +19 -19
  80. package/dist/material/location/strategy/FillGapStrategy.d.ts +7 -7
  81. package/dist/material/location/strategy/FillGapStrategy.js +23 -23
  82. package/dist/material/location/strategy/FillGapStrategy.js.map +1 -1
  83. package/dist/material/location/strategy/LocationStrategy.d.ts +6 -6
  84. package/dist/material/location/strategy/LocationStrategy.js +2 -2
  85. package/dist/material/location/strategy/PositiveSequenceStrategy.d.ts +9 -9
  86. package/dist/material/location/strategy/PositiveSequenceStrategy.js +65 -65
  87. package/dist/material/location/strategy/PositiveSequenceStrategy.js.map +1 -1
  88. package/dist/material/location/strategy/index.d.ts +3 -3
  89. package/dist/material/location/strategy/index.js +19 -19
  90. package/dist/material/memory/GameMemory.d.ts +8 -8
  91. package/dist/material/memory/GameMemory.js +27 -27
  92. package/dist/material/memory/GameMemory.js.map +1 -1
  93. package/dist/material/memory/PlayerMemory.d.ts +9 -9
  94. package/dist/material/memory/PlayerMemory.js +32 -32
  95. package/dist/material/memory/PlayerMemory.js.map +1 -1
  96. package/dist/material/memory/index.d.ts +2 -2
  97. package/dist/material/memory/index.js +18 -18
  98. package/dist/material/moves/CustomMove.d.ts +9 -9
  99. package/dist/material/moves/CustomMove.js +10 -10
  100. package/dist/material/moves/MaterialMove.d.ts +7 -7
  101. package/dist/material/moves/MaterialMove.js +2 -2
  102. package/dist/material/moves/MoveKind.d.ts +6 -6
  103. package/dist/material/moves/MoveKind.js +10 -10
  104. package/dist/material/moves/MoveKind.js.map +1 -1
  105. package/dist/material/moves/index.d.ts +6 -6
  106. package/dist/material/moves/index.js +22 -22
  107. package/dist/material/moves/items/CreateItem.d.ts +10 -10
  108. package/dist/material/moves/items/CreateItem.js +15 -15
  109. package/dist/material/moves/items/CreateItemsAtOnce.d.ts +10 -10
  110. package/dist/material/moves/items/CreateItemsAtOnce.js +15 -15
  111. package/dist/material/moves/items/DeleteItem.d.ts +10 -10
  112. package/dist/material/moves/items/DeleteItem.js +15 -15
  113. package/dist/material/moves/items/DeleteItemsAtOnce.d.ts +9 -9
  114. package/dist/material/moves/items/DeleteItemsAtOnce.js +15 -15
  115. package/dist/material/moves/items/ItemMove.d.ts +17 -17
  116. package/dist/material/moves/items/ItemMove.js +2 -2
  117. package/dist/material/moves/items/ItemMoveType.d.ts +11 -11
  118. package/dist/material/moves/items/ItemMoveType.js +15 -15
  119. package/dist/material/moves/items/ItemMoveType.js.map +1 -1
  120. package/dist/material/moves/items/ItemMovesBuilder.d.ts +8 -8
  121. package/dist/material/moves/items/ItemMovesBuilder.js +33 -33
  122. package/dist/material/moves/items/ItemMovesBuilder.js.map +1 -1
  123. package/dist/material/moves/items/MoveItem.d.ts +14 -14
  124. package/dist/material/moves/items/MoveItem.js +15 -15
  125. package/dist/material/moves/items/MoveItemsAtOnce.d.ts +13 -13
  126. package/dist/material/moves/items/MoveItemsAtOnce.js +15 -15
  127. package/dist/material/moves/items/RollItem.d.ts +11 -11
  128. package/dist/material/moves/items/RollItem.js +15 -15
  129. package/dist/material/moves/items/SelectItem.d.ts +11 -10
  130. package/dist/material/moves/items/SelectItem.js +15 -15
  131. package/dist/material/moves/items/SelectItem.js.map +1 -1
  132. package/dist/material/moves/items/Shuffle.d.ts +13 -13
  133. package/dist/material/moves/items/Shuffle.js +19 -19
  134. package/dist/material/moves/items/index.d.ts +12 -12
  135. package/dist/material/moves/items/index.js +28 -28
  136. package/dist/material/moves/local/CloseTutorialPopup.d.ts +8 -8
  137. package/dist/material/moves/local/CloseTutorialPopup.js +9 -9
  138. package/dist/material/moves/local/DisplayHelp.d.ts +39 -39
  139. package/dist/material/moves/local/DisplayHelp.js +29 -29
  140. package/dist/material/moves/local/DisplayHelp.js.map +1 -1
  141. package/dist/material/moves/local/DropItem.d.ts +13 -13
  142. package/dist/material/moves/local/DropItem.js +9 -9
  143. package/dist/material/moves/local/LocalMove.d.ts +12 -12
  144. package/dist/material/moves/local/LocalMove.js +11 -11
  145. package/dist/material/moves/local/LocalMove.js.map +1 -1
  146. package/dist/material/moves/local/SetTutorialStep.d.ts +9 -9
  147. package/dist/material/moves/local/SetTutorialStep.js +9 -9
  148. package/dist/material/moves/local/index.d.ts +5 -5
  149. package/dist/material/moves/local/index.js +21 -21
  150. package/dist/material/moves/rules/EndGame.d.ts +6 -6
  151. package/dist/material/moves/rules/EndGame.js +9 -9
  152. package/dist/material/moves/rules/EndPlayerTurn.d.ts +7 -7
  153. package/dist/material/moves/rules/EndPlayerTurn.js +9 -9
  154. package/dist/material/moves/rules/RuleMove.d.ts +18 -18
  155. package/dist/material/moves/rules/RuleMove.js +18 -18
  156. package/dist/material/moves/rules/RuleMove.js.map +1 -1
  157. package/dist/material/moves/rules/StartPlayerTurn.d.ts +8 -8
  158. package/dist/material/moves/rules/StartPlayerTurn.js +9 -9
  159. package/dist/material/moves/rules/StartRule.d.ts +7 -7
  160. package/dist/material/moves/rules/StartRule.js +9 -9
  161. package/dist/material/moves/rules/StartSimultaneousRule.d.ts +8 -8
  162. package/dist/material/moves/rules/StartSimultaneousRule.js +9 -9
  163. package/dist/material/moves/rules/index.d.ts +6 -6
  164. package/dist/material/moves/rules/index.js +22 -22
  165. package/dist/material/rules/MaterialRulesMovesBuilder.d.ts +12 -12
  166. package/dist/material/rules/MaterialRulesMovesBuilder.js +35 -35
  167. package/dist/material/rules/MaterialRulesPart.d.ts +23 -23
  168. package/dist/material/rules/MaterialRulesPart.js +64 -64
  169. package/dist/material/rules/MaterialRulesPart.js.map +1 -1
  170. package/dist/material/rules/PlayerTurnRule.d.ts +9 -9
  171. package/dist/material/rules/PlayerTurnRule.js +52 -52
  172. package/dist/material/rules/RuleStep.d.ts +5 -5
  173. package/dist/material/rules/RuleStep.js +2 -2
  174. package/dist/material/rules/SimultaneousRule.d.ts +9 -9
  175. package/dist/material/rules/SimultaneousRule.js +41 -41
  176. package/dist/material/rules/SimultaneousRule.js.map +1 -1
  177. package/dist/material/rules/index.d.ts +5 -5
  178. package/dist/material/rules/index.js +21 -21
  179. package/dist/options/EnumOption.d.ts +6 -6
  180. package/dist/options/EnumOption.js +7 -7
  181. package/dist/options/Option.d.ts +8 -8
  182. package/dist/options/Option.js +2 -2
  183. package/dist/options/OptionSpecOf.d.ts +5 -5
  184. package/dist/options/OptionSpecOf.js +2 -2
  185. package/dist/options/OptionsSpec.d.ts +9 -9
  186. package/dist/options/OptionsSpec.js +2 -2
  187. package/dist/options/OptionsValidationError.d.ts +4 -4
  188. package/dist/options/OptionsValidationError.js +29 -29
  189. package/dist/options/OptionsValidationError.js.map +1 -1
  190. package/dist/options/PlayerEnumOption.d.ts +14 -14
  191. package/dist/options/PlayerEnumOption.js +66 -66
  192. package/dist/options/PlayerEnumOption.js.map +1 -1
  193. package/dist/options/PlayersOptionsSpec.d.ts +7 -7
  194. package/dist/options/PlayersOptionsSpec.js +2 -2
  195. package/dist/options/WithIdOption.d.ts +3 -3
  196. package/dist/options/WithIdOption.js +2 -2
  197. package/dist/options/WithPlayerOptionsSpec.d.ts +6 -6
  198. package/dist/options/WithPlayerOptionsSpec.js +7 -7
  199. package/dist/options/WithPlayersOptions.d.ts +3 -3
  200. package/dist/options/WithPlayersOptions.js +2 -2
  201. package/dist/options/index.d.ts +11 -11
  202. package/dist/options/index.js +27 -27
  203. package/dist/options/isWithPlayerIdOptions.d.ts +4 -4
  204. package/dist/options/isWithPlayerIdOptions.js +11 -11
  205. package/dist/utils/EnumUtils.d.ts +1 -1
  206. package/dist/utils/EnumUtils.js +7 -7
  207. package/dist/utils/grid.squares.util.d.ts +11 -11
  208. package/dist/utils/grid.squares.util.js +30 -30
  209. package/dist/utils/grid.squares.util.js.map +1 -1
  210. package/dist/utils/grid.util.d.ts +5 -5
  211. package/dist/utils/grid.util.js +7 -7
  212. package/dist/utils/index.d.ts +5 -5
  213. package/dist/utils/index.js +21 -21
  214. package/dist/utils/isDeadEndMove.util.d.ts +2 -2
  215. package/dist/utils/isDeadEndMove.util.js +18 -18
  216. package/dist/utils/listing.util.d.ts +2 -2
  217. package/dist/utils/listing.util.js +23 -23
  218. package/dist/utils/listing.util.js.map +1 -1
  219. package/package.json +34 -33
  220. package/dist/material/items/MaterialDeck.d.ts +0 -7
  221. package/dist/material/items/MaterialDeck.js +0 -35
  222. package/dist/material/items/MaterialDeck.js.map +0 -1
  223. package/dist/material/moves/items/MoveAtOnce.d.ts +0 -13
  224. package/dist/material/moves/items/MoveAtOnce.js +0 -16
  225. package/dist/material/moves/items/MoveAtOnce.js.map +0 -1
  226. package/dist/material/moves/items/Roll.d.ts +0 -11
  227. package/dist/material/moves/items/Roll.js +0 -16
  228. package/dist/material/moves/items/Roll.js.map +0 -1
  229. package/dist/material/moves/local/DisplayRules.d.ts +0 -32
  230. package/dist/material/moves/local/DisplayRules.js +0 -25
  231. package/dist/material/moves/local/DisplayRules.js.map +0 -1
  232. package/dist/material/moves/rules/StartSimultanousRule.d.ts +0 -10
  233. package/dist/material/moves/rules/StartSimultanousRule.js +0 -10
  234. package/dist/material/moves/rules/StartSimultanousRule.js.map +0 -1
  235. package/dist/options/PlayerIdSpec.d.ts +0 -7
  236. package/dist/options/PlayerIdSpec.js +0 -18
  237. package/dist/options/PlayerIdSpec.js.map +0 -1
  238. package/dist/options/getFallbackPlayerName.d.ts +0 -4
  239. package/dist/options/getFallbackPlayerName.js +0 -14
  240. package/dist/options/getFallbackPlayerName.js.map +0 -1
  241. package/dist/options/providePlayerIds.d.ts +0 -6
  242. package/dist/options/providePlayerIds.js +0 -36
  243. package/dist/options/providePlayerIds.js.map +0 -1
@@ -1,377 +1,407 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __rest = (this && this.__rest) || function (s, e) {
29
- var t = {};
30
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
31
- t[p] = s[p];
32
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
33
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
34
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
35
- t[p[i]] = s[p[i]];
36
- }
37
- return t;
38
- };
39
- var __importDefault = (this && this.__importDefault) || function (mod) {
40
- return (mod && mod.__esModule) ? mod : { "default": mod };
41
- };
42
- Object.defineProperty(exports, "__esModule", { value: true });
43
- exports.MaterialDeck = exports.Material = void 0;
44
- var fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
45
- var maxBy_1 = __importDefault(require("lodash/maxBy"));
46
- var minBy_1 = __importDefault(require("lodash/minBy"));
47
- var orderBy_1 = __importDefault(require("lodash/orderBy"));
48
- var sumBy_1 = __importDefault(require("lodash/sumBy"));
49
- var moves_1 = require("../moves");
50
- var Material = (function () {
51
- function Material(type, entries, processMove) {
52
- this.type = type;
53
- this.entries = entries;
54
- this.processMove = processMove;
55
- }
56
- Material.prototype.new = function (entries) {
57
- return new this.constructor(this.type, entries, this.processMove);
58
- };
59
- Material.prototype.getItems = function (predicate) {
60
- var items = this.entries.map(function (entry) { return entry[1]; });
61
- return predicate ? items.filter(predicate) : items;
62
- };
63
- Material.prototype.getItem = function (arg) {
64
- if (typeof arg === 'number') {
65
- var entry = this.entries.find(function (entry) { return entry[0] === arg; });
66
- return entry ? entry[1] : undefined;
67
- }
68
- else if (typeof arg === 'function') {
69
- var entries = this.entries.filter(function (_a) {
70
- var item = _a[1];
71
- return arg(item);
72
- });
73
- return entries.length ? entries[0][1] : undefined;
74
- }
75
- else {
76
- return this.entries.length ? this.entries[0][1] : undefined;
77
- }
78
- };
79
- Material.prototype.getIndex = function () {
80
- var _a, _b;
81
- return (_b = (_a = this.entries[0]) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : -1;
82
- };
83
- Material.prototype.getIndexes = function () {
84
- return this.entries.map(function (entry) { return entry[0]; });
85
- };
86
- Material.prototype.index = function (arg) {
87
- if (typeof arg === 'function') {
88
- return this.filter(function (_, index) { return arg(index); });
89
- }
90
- else {
91
- var item = this.entries.find(function (_a) {
92
- var index = _a[0];
93
- return index === arg;
94
- });
95
- return this.new(item ? [item] : []);
96
- }
97
- };
98
- Material.prototype.indexes = function (indexes) {
99
- var items = this.entries.filter(function (_a) {
100
- var i = _a[0];
101
- return indexes.includes(i);
102
- });
103
- return this.new(items);
104
- };
105
- Object.defineProperty(Material.prototype, "length", {
106
- get: function () {
107
- return this.entries.length;
108
- },
109
- enumerable: false,
110
- configurable: true
111
- });
112
- Material.prototype.getQuantity = function () {
113
- return (0, sumBy_1.default)(this.entries, function (_a) {
114
- var _b;
115
- var item = _a[1];
116
- return (_b = item.quantity) !== null && _b !== void 0 ? _b : 1;
117
- });
118
- };
119
- Material.prototype.filter = function (predicate) {
120
- return this.new(this.entries.filter(function (_a) {
121
- var index = _a[0], item = _a[1];
122
- return predicate(item, index);
123
- }));
124
- };
125
- Material.prototype.id = function (arg) {
126
- return this.filter(function (_a) {
127
- var id = _a.id;
128
- return typeof arg === 'function' ? arg(id) : (0, fast_deep_equal_1.default)(id, arg);
129
- });
130
- };
131
- Material.prototype.location = function (arg) {
132
- return this.filter(function (_a) {
133
- var location = _a.location;
134
- return typeof arg === 'function' ? arg(location) : location.type === arg;
135
- });
136
- };
137
- Material.prototype.rotation = function (arg) {
138
- return this.location(function (_a) {
139
- var rotation = _a.rotation;
140
- return typeof arg === 'function' ? arg(rotation) : (0, fast_deep_equal_1.default)(rotation, arg);
141
- });
142
- };
143
- Material.prototype.player = function (arg) {
144
- return this.location(function (_a) {
145
- var player = _a.player;
146
- return typeof arg === 'function' ? arg(player) : player === arg;
147
- });
148
- };
149
- Material.prototype.locationId = function (arg) {
150
- return this.location(function (_a) {
151
- var id = _a.id;
152
- return typeof arg === 'function' ? arg(id) : (0, fast_deep_equal_1.default)(id, arg);
153
- });
154
- };
155
- Material.prototype.parent = function (arg) {
156
- return this.location(function (_a) {
157
- var parent = _a.parent;
158
- return typeof arg === 'function' ? arg(parent) : (0, fast_deep_equal_1.default)(parent, arg);
159
- });
160
- };
161
- Material.prototype.minBy = function (selector) {
162
- var min = (0, minBy_1.default)(this.entries, function (entry) { return selector(entry[1]); });
163
- return this.new(min ? [min] : []);
164
- };
165
- Material.prototype.sort = function () {
166
- var selectors = [];
167
- for (var _i = 0; _i < arguments.length; _i++) {
168
- selectors[_i] = arguments[_i];
169
- }
170
- var orderedItems = (0, orderBy_1.default)(this.entries, selectors.map(function (s) { return function (entry) { return s(entry[1]); }; }));
171
- return this.new(orderedItems);
172
- };
173
- Material.prototype.limit = function (count) {
174
- return this.new(this.entries.slice(0, count));
175
- };
176
- Material.prototype.maxBy = function (selector) {
177
- var max = (0, maxBy_1.default)(this.entries, function (entry) { return selector(entry[1]); });
178
- return this.new(max ? [max] : []);
179
- };
180
- Material.prototype.selected = function (selected) {
181
- if (selected === void 0) { selected = true; }
182
- return this.filter(function (item) { var _a; return ((_a = item.selected) !== null && _a !== void 0 ? _a : false) === selected; });
183
- };
184
- Material.prototype.process = function (moves) {
185
- if (this.processMove) {
186
- for (var _i = 0, moves_2 = moves; _i < moves_2.length; _i++) {
187
- var move = moves_2[_i];
188
- this.processMove(move);
189
- }
190
- }
191
- return moves;
192
- };
193
- Material.prototype.createItem = function (item) {
194
- return this.createItems([item])[0];
195
- };
196
- Material.prototype.createItems = function (items) {
197
- var _this = this;
198
- return this.process(items.map(function (item) { return ({
199
- kind: moves_1.MoveKind.ItemMove,
200
- type: moves_1.ItemMoveType.Create,
201
- itemType: _this.type,
202
- item: item
203
- }); }));
204
- };
205
- Material.prototype.createItemsAtOnce = function (items) {
206
- var move = { kind: moves_1.MoveKind.ItemMove, type: moves_1.ItemMoveType.CreateAtOnce, itemType: this.type, items: items };
207
- return this.process([move])[0];
208
- };
209
- Material.prototype.deleteItem = function (quantity) {
210
- switch (this.length) {
211
- case 0:
212
- throw new Error('You are trying to delete an item that does not exists');
213
- case 1:
214
- return this.deleteItems(quantity)[0];
215
- default:
216
- return this.limit(1).deleteItems(quantity)[0];
217
- }
218
- };
219
- Material.prototype.deleteItems = function (quantity) {
220
- var _this = this;
221
- return this.process(this.entries.map(function (entry) {
222
- var move = {
223
- kind: moves_1.MoveKind.ItemMove,
224
- type: moves_1.ItemMoveType.Delete,
225
- itemType: _this.type,
226
- itemIndex: entry[0]
227
- };
228
- if (quantity)
229
- move.quantity = quantity;
230
- return move;
231
- }));
232
- };
233
- Material.prototype.deleteItemsAtOnce = function () {
234
- var moves = { kind: moves_1.MoveKind.ItemMove, type: moves_1.ItemMoveType.DeleteAtOnce, itemType: this.type, indexes: this.getIndexes() };
235
- return this.process([moves])[0];
236
- };
237
- Material.prototype.selectItem = function (quantity) {
238
- switch (this.length) {
239
- case 0:
240
- throw new Error('You are trying to select an item that does not exists');
241
- case 1:
242
- return this.selectItems(quantity)[0];
243
- default:
244
- return this.limit(1).selectItems(quantity)[0];
245
- }
246
- };
247
- Material.prototype.selectItems = function (quantity) {
248
- var _this = this;
249
- return this.process(this.entries.map(function (entry) {
250
- var move = {
251
- kind: moves_1.MoveKind.ItemMove,
252
- type: moves_1.ItemMoveType.Select,
253
- itemType: _this.type,
254
- itemIndex: entry[0]
255
- };
256
- if (quantity)
257
- move.quantity = quantity;
258
- return move;
259
- }));
260
- };
261
- Material.prototype.moveItem = function (location, quantity) {
262
- switch (this.length) {
263
- case 0:
264
- throw new Error('You are trying to move an item that does not exists');
265
- case 1:
266
- return this.moveItems(location, quantity)[0];
267
- default:
268
- return this.limit(1).moveItems(location, quantity)[0];
269
- }
270
- };
271
- Material.prototype.moveItems = function (location, quantity) {
272
- var _this = this;
273
- var getLocation = typeof location === 'function' ? location : function () { return location; };
274
- return this.process(this.entries.map(function (entry) {
275
- var location = getLocation(entry[1], entry[0]);
276
- var move = {
277
- kind: moves_1.MoveKind.ItemMove,
278
- type: moves_1.ItemMoveType.Move,
279
- itemType: _this.type,
280
- itemIndex: entry[0],
281
- location: location
282
- };
283
- if (quantity)
284
- move.quantity = quantity;
285
- return move;
286
- }));
287
- };
288
- Material.prototype.moveItemsAtOnce = function (location) {
289
- var move = {
290
- kind: moves_1.MoveKind.ItemMove,
291
- type: moves_1.ItemMoveType.MoveAtOnce,
292
- itemType: this.type,
293
- indexes: this.entries.map(function (_a) {
294
- var index = _a[0];
295
- return index;
296
- }),
297
- location: location
298
- };
299
- return this.process([move])[0];
300
- };
301
- Material.prototype.rotateItem = function (arg) {
302
- switch (this.length) {
303
- case 0:
304
- throw new Error('You are trying to rotate an item that does not exists');
305
- case 1:
306
- return this.rotateItems(arg)[0];
307
- default:
308
- return this.limit(1).rotateItems(arg)[0];
309
- }
310
- };
311
- Material.prototype.rotateItems = function (arg) {
312
- return this.moveItems(function (item) {
313
- var rotation = typeof arg === 'function' ? arg(item) : arg;
314
- var _a = item.location, oldRotation = _a.rotation, location = __rest(_a, ["rotation"]);
315
- return rotation !== undefined ? (__assign(__assign({}, location), { rotation: rotation })) : location;
316
- });
317
- };
318
- Material.prototype.shuffle = function () {
319
- return this.process([{
320
- kind: moves_1.MoveKind.ItemMove,
321
- type: moves_1.ItemMoveType.Shuffle,
322
- itemType: this.type,
323
- indexes: this.entries.map(function (entry) { return entry[0]; })
324
- }])[0];
325
- };
326
- Material.prototype.rollItem = function (location) {
327
- switch (this.length) {
328
- case 0:
329
- throw new Error('You are trying to roll an item that does not exists');
330
- case 1:
331
- return this.rollItems(location)[0];
332
- default:
333
- return this.limit(1).rollItems(location)[0];
334
- }
335
- };
336
- Material.prototype.rollItems = function (location) {
337
- var _this = this;
338
- if (location === void 0) { location = function (item) { return item.location; }; }
339
- var getLocation = typeof location === 'function' ? location : function () { return location; };
340
- return this.process(this.entries.map(function (entry) {
341
- var location = getLocation(entry[1]);
342
- return ({
343
- kind: moves_1.MoveKind.ItemMove,
344
- type: moves_1.ItemMoveType.Roll,
345
- itemType: _this.type,
346
- itemIndex: entry[0],
347
- location: location
348
- });
349
- }));
350
- };
351
- Material.prototype.deck = function (selector) {
352
- if (selector === void 0) { selector = function (item) { return -item.location.x; }; }
353
- return new MaterialDeck(this.type, this.entries, this.processMove).sort(selector);
354
- };
355
- return Material;
356
- }());
357
- exports.Material = Material;
358
- var MaterialDeck = (function (_super) {
359
- __extends(MaterialDeck, _super);
360
- function MaterialDeck() {
361
- return _super !== null && _super.apply(this, arguments) || this;
362
- }
363
- MaterialDeck.prototype.deal = function (arg, quantity) {
364
- if (quantity === void 0) { quantity = 1; }
365
- return this.new(this.entries.splice(0, quantity)).moveItems(arg);
366
- };
367
- MaterialDeck.prototype.dealOne = function (arg) {
368
- var deal = this.deal(arg);
369
- if (deal.length === 0) {
370
- throw new Error('You are trying to deal one card from an empty deck');
371
- }
372
- return deal[0];
373
- };
374
- return MaterialDeck;
375
- }(Material));
376
- exports.MaterialDeck = MaterialDeck;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __rest = (this && this.__rest) || function (s, e) {
29
+ var t = {};
30
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
31
+ t[p] = s[p];
32
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
33
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
34
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
35
+ t[p[i]] = s[p[i]];
36
+ }
37
+ return t;
38
+ };
39
+ var __importDefault = (this && this.__importDefault) || function (mod) {
40
+ return (mod && mod.__esModule) ? mod : { "default": mod };
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.MaterialDeck = exports.Material = void 0;
44
+ var fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
45
+ var maxBy_1 = __importDefault(require("lodash/maxBy"));
46
+ var minBy_1 = __importDefault(require("lodash/minBy"));
47
+ var orderBy_1 = __importDefault(require("lodash/orderBy"));
48
+ var sumBy_1 = __importDefault(require("lodash/sumBy"));
49
+ var moves_1 = require("../moves");
50
+ var Material = (function () {
51
+ function Material(type, entries, processMove) {
52
+ this.type = type;
53
+ this.entries = entries;
54
+ this.processMove = processMove;
55
+ }
56
+ Material.prototype.new = function (entries) {
57
+ var Class = this.constructor;
58
+ return new Class(this.type, entries, this.processMove);
59
+ };
60
+ Material.prototype.getItems = function (predicate) {
61
+ var items = this.entries.map(function (entry) { return entry[1]; });
62
+ return predicate ? items.filter(predicate) : items;
63
+ };
64
+ Material.prototype.getItem = function (arg) {
65
+ if (typeof arg === 'number') {
66
+ var entry = this.entries.find(function (entry) { return entry[0] === arg; });
67
+ return entry ? entry[1] : undefined;
68
+ }
69
+ else if (typeof arg === 'function') {
70
+ var entries = this.entries.filter(function (_a) {
71
+ var item = _a[1];
72
+ return arg(item);
73
+ });
74
+ return entries.length ? entries[0][1] : undefined;
75
+ }
76
+ else {
77
+ return this.entries.length ? this.entries[0][1] : undefined;
78
+ }
79
+ };
80
+ Material.prototype.getIndex = function () {
81
+ var _a, _b;
82
+ return (_b = (_a = this.entries[0]) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : -1;
83
+ };
84
+ Material.prototype.getIndexes = function () {
85
+ return this.entries.map(function (entry) { return entry[0]; });
86
+ };
87
+ Material.prototype.index = function (arg) {
88
+ if (typeof arg === 'function') {
89
+ return this.filter(function (_, index) { return arg(index); });
90
+ }
91
+ else {
92
+ var item = this.entries.find(function (_a) {
93
+ var index = _a[0];
94
+ return index === arg;
95
+ });
96
+ return this.new(item ? [item] : []);
97
+ }
98
+ };
99
+ Material.prototype.indexes = function (indexes) {
100
+ var items = this.entries.filter(function (_a) {
101
+ var i = _a[0];
102
+ return indexes.includes(i);
103
+ });
104
+ return this.new(items);
105
+ };
106
+ Object.defineProperty(Material.prototype, "length", {
107
+ get: function () {
108
+ return this.entries.length;
109
+ },
110
+ enumerable: false,
111
+ configurable: true
112
+ });
113
+ Material.prototype.getQuantity = function () {
114
+ return (0, sumBy_1.default)(this.entries, function (_a) {
115
+ var _b;
116
+ var item = _a[1];
117
+ return (_b = item.quantity) !== null && _b !== void 0 ? _b : 1;
118
+ });
119
+ };
120
+ Material.prototype.filter = function (predicate) {
121
+ return this.new(this.entries.filter(function (_a) {
122
+ var index = _a[0], item = _a[1];
123
+ return predicate(item, index);
124
+ }));
125
+ };
126
+ Material.prototype.id = function (arg) {
127
+ return this.filter(function (_a) {
128
+ var id = _a.id;
129
+ return typeof arg === 'function' ? arg(id) : (0, fast_deep_equal_1.default)(id, arg);
130
+ });
131
+ };
132
+ Material.prototype.location = function (arg) {
133
+ return this.filter(function (_a) {
134
+ var location = _a.location;
135
+ return typeof arg === 'function' ? arg(location) : location.type === arg;
136
+ });
137
+ };
138
+ Material.prototype.rotation = function (arg) {
139
+ return this.location(function (_a) {
140
+ var rotation = _a.rotation;
141
+ return typeof arg === 'function' ? arg(rotation) : (0, fast_deep_equal_1.default)(rotation, arg);
142
+ });
143
+ };
144
+ Material.prototype.player = function (arg) {
145
+ return this.location(function (_a) {
146
+ var player = _a.player;
147
+ return typeof arg === 'function' ? arg(player) : player === arg;
148
+ });
149
+ };
150
+ Material.prototype.locationId = function (arg) {
151
+ return this.location(function (_a) {
152
+ var id = _a.id;
153
+ return typeof arg === 'function' ? arg(id) : (0, fast_deep_equal_1.default)(id, arg);
154
+ });
155
+ };
156
+ Material.prototype.parent = function (arg) {
157
+ return this.location(function (_a) {
158
+ var parent = _a.parent;
159
+ return typeof arg === 'function' ? arg(parent) : (0, fast_deep_equal_1.default)(parent, arg);
160
+ });
161
+ };
162
+ Material.prototype.minBy = function (selector) {
163
+ var min = (0, minBy_1.default)(this.entries, function (entry) { return selector(entry[1]); });
164
+ return this.new(min ? [min] : []);
165
+ };
166
+ Material.prototype.sort = function () {
167
+ var selectors = [];
168
+ for (var _i = 0; _i < arguments.length; _i++) {
169
+ selectors[_i] = arguments[_i];
170
+ }
171
+ var orderedItems = (0, orderBy_1.default)(this.entries, selectors.map(function (s) { return function (entry) { return s(entry[1]); }; }));
172
+ return this.new(orderedItems);
173
+ };
174
+ Material.prototype.limit = function (count) {
175
+ return this.new(this.entries.slice(0, count));
176
+ };
177
+ Material.prototype.maxBy = function (selector) {
178
+ var max = (0, maxBy_1.default)(this.entries, function (entry) { return selector(entry[1]); });
179
+ return this.new(max ? [max] : []);
180
+ };
181
+ Material.prototype.selected = function (selected) {
182
+ if (selected === void 0) { selected = true; }
183
+ return this.filter(function (item) { var _a; return ((_a = item.selected) !== null && _a !== void 0 ? _a : false) === selected; });
184
+ };
185
+ Material.prototype.process = function (moves) {
186
+ if (this.processMove) {
187
+ for (var _i = 0, moves_2 = moves; _i < moves_2.length; _i++) {
188
+ var move = moves_2[_i];
189
+ this.processMove(move);
190
+ }
191
+ }
192
+ return moves;
193
+ };
194
+ Material.prototype.createItem = function (item) {
195
+ return this.createItems([item])[0];
196
+ };
197
+ Material.prototype.createItems = function (items) {
198
+ var _this = this;
199
+ return this.process(items.map(function (item) { return ({
200
+ kind: moves_1.MoveKind.ItemMove,
201
+ type: moves_1.ItemMoveType.Create,
202
+ itemType: _this.type,
203
+ item: item
204
+ }); }));
205
+ };
206
+ Material.prototype.createItemsAtOnce = function (items) {
207
+ var move = { kind: moves_1.MoveKind.ItemMove, type: moves_1.ItemMoveType.CreateAtOnce, itemType: this.type, items: items };
208
+ return this.process([move])[0];
209
+ };
210
+ Material.prototype.deleteItem = function (quantity) {
211
+ switch (this.length) {
212
+ case 0:
213
+ throw new Error('You are trying to delete an item that does not exists');
214
+ case 1:
215
+ return this.deleteItems(quantity)[0];
216
+ default:
217
+ return this.limit(1).deleteItems(quantity)[0];
218
+ }
219
+ };
220
+ Material.prototype.deleteItems = function (quantity) {
221
+ var _this = this;
222
+ return this.process(this.entries.map(function (entry) {
223
+ var move = {
224
+ kind: moves_1.MoveKind.ItemMove,
225
+ type: moves_1.ItemMoveType.Delete,
226
+ itemType: _this.type,
227
+ itemIndex: entry[0]
228
+ };
229
+ if (quantity)
230
+ move.quantity = quantity;
231
+ return move;
232
+ }));
233
+ };
234
+ Material.prototype.deleteItemsAtOnce = function () {
235
+ var moves = { kind: moves_1.MoveKind.ItemMove, type: moves_1.ItemMoveType.DeleteAtOnce, itemType: this.type, indexes: this.getIndexes() };
236
+ return this.process([moves])[0];
237
+ };
238
+ Material.prototype.selectItem = function (quantity) {
239
+ switch (this.length) {
240
+ case 0:
241
+ throw new Error('You are trying to select an item that does not exists');
242
+ case 1:
243
+ return this.selectItems(quantity)[0];
244
+ default:
245
+ return this.limit(1).selectItems(quantity)[0];
246
+ }
247
+ };
248
+ Material.prototype.selectItems = function (quantity) {
249
+ var _this = this;
250
+ return this.process(this.entries.map(function (entry) {
251
+ var move = {
252
+ kind: moves_1.MoveKind.ItemMove,
253
+ type: moves_1.ItemMoveType.Select,
254
+ itemType: _this.type,
255
+ itemIndex: entry[0]
256
+ };
257
+ if (quantity)
258
+ move.quantity = quantity;
259
+ return move;
260
+ }));
261
+ };
262
+ Material.prototype.unselectItem = function (quantity) {
263
+ switch (this.length) {
264
+ case 0:
265
+ throw new Error('You are trying to select an item that does not exists');
266
+ case 1:
267
+ return this.unselectItems(quantity)[0];
268
+ default:
269
+ return this.limit(1).unselectItems(quantity)[0];
270
+ }
271
+ };
272
+ Material.prototype.unselectItems = function (quantity) {
273
+ var _this = this;
274
+ return this.process(this.entries.map(function (entry) {
275
+ var move = {
276
+ kind: moves_1.MoveKind.ItemMove,
277
+ type: moves_1.ItemMoveType.Select,
278
+ itemType: _this.type,
279
+ itemIndex: entry[0],
280
+ selected: false
281
+ };
282
+ if (quantity)
283
+ move.quantity = quantity;
284
+ return move;
285
+ }));
286
+ };
287
+ Material.prototype.moveItem = function (location, quantity) {
288
+ switch (this.length) {
289
+ case 0:
290
+ throw new Error('You are trying to move an item that does not exists');
291
+ case 1:
292
+ return this.moveItems(location, quantity)[0];
293
+ default:
294
+ return this.limit(1).moveItems(location, quantity)[0];
295
+ }
296
+ };
297
+ Material.prototype.moveItems = function (location, quantity) {
298
+ var _this = this;
299
+ var getLocation = typeof location === 'function' ? location : function () { return location; };
300
+ return this.process(this.entries.map(function (entry) {
301
+ var location = getLocation(entry[1], entry[0]);
302
+ var move = {
303
+ kind: moves_1.MoveKind.ItemMove,
304
+ type: moves_1.ItemMoveType.Move,
305
+ itemType: _this.type,
306
+ itemIndex: entry[0],
307
+ location: location
308
+ };
309
+ if (quantity)
310
+ move.quantity = quantity;
311
+ return move;
312
+ }));
313
+ };
314
+ Material.prototype.moveItemsAtOnce = function (location) {
315
+ var move = {
316
+ kind: moves_1.MoveKind.ItemMove,
317
+ type: moves_1.ItemMoveType.MoveAtOnce,
318
+ itemType: this.type,
319
+ indexes: this.entries.map(function (_a) {
320
+ var index = _a[0];
321
+ return index;
322
+ }),
323
+ location: location
324
+ };
325
+ return this.process([move])[0];
326
+ };
327
+ Material.prototype.rotateItem = function (arg) {
328
+ switch (this.length) {
329
+ case 0:
330
+ throw new Error('You are trying to rotate an item that does not exists');
331
+ case 1:
332
+ return this.rotateItems(arg)[0];
333
+ default:
334
+ return this.limit(1).rotateItems(arg)[0];
335
+ }
336
+ };
337
+ Material.prototype.rotateItems = function (arg) {
338
+ return this.moveItems(function (item) {
339
+ var rotation = typeof arg === 'function' ? arg(item) : arg;
340
+ var _a = item.location, oldRotation = _a.rotation, location = __rest(_a, ["rotation"]);
341
+ return rotation !== undefined ? (__assign(__assign({}, location), { rotation: rotation })) : location;
342
+ });
343
+ };
344
+ Material.prototype.shuffle = function () {
345
+ return this.process([{
346
+ kind: moves_1.MoveKind.ItemMove,
347
+ type: moves_1.ItemMoveType.Shuffle,
348
+ itemType: this.type,
349
+ indexes: this.entries.map(function (entry) { return entry[0]; })
350
+ }])[0];
351
+ };
352
+ Material.prototype.rollItem = function (location) {
353
+ switch (this.length) {
354
+ case 0:
355
+ throw new Error('You are trying to roll an item that does not exists');
356
+ case 1:
357
+ return this.rollItems(location)[0];
358
+ default:
359
+ return this.limit(1).rollItems(location)[0];
360
+ }
361
+ };
362
+ Material.prototype.rollItems = function (location) {
363
+ var _this = this;
364
+ if (location === void 0) { location = function (item) { return item.location; }; }
365
+ var getLocation = typeof location === 'function' ? location : function () { return location; };
366
+ return this.process(this.entries.map(function (entry) {
367
+ var location = getLocation(entry[1]);
368
+ return ({
369
+ kind: moves_1.MoveKind.ItemMove,
370
+ type: moves_1.ItemMoveType.Roll,
371
+ itemType: _this.type,
372
+ itemIndex: entry[0],
373
+ location: location
374
+ });
375
+ }));
376
+ };
377
+ Material.prototype.deck = function (selector) {
378
+ if (selector === void 0) { selector = function (item) { return -item.location.x; }; }
379
+ return new MaterialDeck(this.type, this.entries, this.processMove).sort(selector);
380
+ };
381
+ return Material;
382
+ }());
383
+ exports.Material = Material;
384
+ var MaterialDeck = (function (_super) {
385
+ __extends(MaterialDeck, _super);
386
+ function MaterialDeck() {
387
+ return _super !== null && _super.apply(this, arguments) || this;
388
+ }
389
+ MaterialDeck.prototype.deal = function (arg, quantity) {
390
+ if (quantity === void 0) { quantity = 1; }
391
+ return this.new(this.entries.splice(0, quantity)).moveItems(arg);
392
+ };
393
+ MaterialDeck.prototype.dealOne = function (arg) {
394
+ var deal = this.deal(arg);
395
+ if (deal.length === 0) {
396
+ throw new Error('You are trying to deal one card from an empty deck');
397
+ }
398
+ return deal[0];
399
+ };
400
+ MaterialDeck.prototype.dealAtOnce = function (arg, quantity) {
401
+ if (quantity === void 0) { quantity = 1; }
402
+ return this.new(this.entries.splice(0, quantity)).moveItemsAtOnce(arg);
403
+ };
404
+ return MaterialDeck;
405
+ }(Material));
406
+ exports.MaterialDeck = MaterialDeck;
377
407
  //# sourceMappingURL=Material.js.map