@gamepark/rules-api 6.24.2 → 6.25.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/Action.d.ts +7 -0
- package/dist/Bot.d.ts +21 -0
- package/dist/Bot.js +18 -2
- package/dist/Bot.js.map +1 -1
- package/dist/Competitive.d.ts +45 -0
- package/dist/Competitive.js +15 -0
- package/dist/Competitive.js.map +1 -1
- package/dist/Eliminations.d.ts +17 -0
- package/dist/Eliminations.js +5 -0
- package/dist/Eliminations.js.map +1 -1
- package/dist/GameSetup.d.ts +14 -0
- package/dist/HiddenInformation.d.ts +22 -0
- package/dist/HiddenInformation.js +5 -0
- package/dist/HiddenInformation.js.map +1 -1
- package/dist/LocalMovePreview.d.ts +14 -0
- package/dist/LocalMovePreview.js +5 -0
- package/dist/LocalMovePreview.js.map +1 -1
- package/dist/RandomMove.d.ts +20 -2
- package/dist/Rules.d.ts +119 -0
- package/dist/Rules.js +102 -1
- package/dist/Rules.js.map +1 -1
- package/dist/SecretInformation.d.ts +39 -0
- package/dist/SecretInformation.js +5 -0
- package/dist/SecretInformation.js.map +1 -1
- package/dist/TimeLimit.d.ts +22 -0
- package/dist/TimeLimit.js +5 -0
- package/dist/TimeLimit.js.map +1 -1
- package/dist/Undo.d.ts +18 -0
- package/dist/Undo.js +6 -0
- package/dist/Undo.js.map +1 -1
- package/dist/UnpredictableMove.d.ts +19 -0
- package/dist/UnpredictableMove.js +5 -0
- package/dist/UnpredictableMove.js.map +1 -1
- package/dist/material/HiddenMaterialRules.d.ts +49 -1
- package/dist/material/HiddenMaterialRules.js +56 -13
- package/dist/material/HiddenMaterialRules.js.map +1 -1
- package/dist/material/MaterialGame.d.ts +12 -0
- package/dist/material/MaterialGameSetup.d.ts +74 -0
- package/dist/material/MaterialGameSetup.js +68 -5
- package/dist/material/MaterialGameSetup.js.map +1 -1
- package/dist/material/MaterialRules.d.ts +133 -1
- package/dist/material/MaterialRules.js +131 -5
- package/dist/material/MaterialRules.js.map +1 -1
- package/dist/material/SecretMaterialRules.d.ts +31 -0
- package/dist/material/SecretMaterialRules.js +23 -1
- package/dist/material/SecretMaterialRules.js.map +1 -1
- package/dist/material/items/Material.d.ts +265 -5
- package/dist/material/items/Material.js +266 -7
- package/dist/material/items/Material.js.map +1 -1
- package/dist/material/items/MaterialDeck.d.ts +34 -1
- package/dist/material/items/MaterialDeck.js +36 -3
- package/dist/material/items/MaterialDeck.js.map +1 -1
- package/dist/material/items/MaterialItem.d.ts +12 -0
- package/dist/material/items/MaterialMoney.d.ts +81 -0
- package/dist/material/items/MaterialMoney.js +288 -0
- package/dist/material/items/MaterialMoney.js.map +1 -0
- package/dist/material/items/MaterialMutator.d.ts +39 -0
- package/dist/material/items/MaterialMutator.js +44 -5
- package/dist/material/items/MaterialMutator.js.map +1 -1
- package/dist/material/items/index.d.ts +2 -1
- package/dist/material/items/index.js +3 -1
- package/dist/material/items/index.js.map +1 -1
- package/dist/material/location/Location.d.ts +28 -0
- package/dist/material/location/Location.js +5 -0
- package/dist/material/location/Location.js.map +1 -1
- package/dist/material/location/LocationBuilder.js +1 -1
- package/dist/material/location/strategy/FillGapStrategy.d.ts +4 -0
- package/dist/material/location/strategy/FillGapStrategy.js +5 -1
- package/dist/material/location/strategy/FillGapStrategy.js.map +1 -1
- package/dist/material/location/strategy/LocationStrategy.d.ts +20 -0
- package/dist/material/location/strategy/PositiveSequenceStrategy.d.ts +4 -0
- package/dist/material/location/strategy/PositiveSequenceStrategy.js +5 -1
- package/dist/material/location/strategy/PositiveSequenceStrategy.js.map +1 -1
- package/dist/material/memory/GameMemory.d.ts +21 -0
- package/dist/material/memory/GameMemory.js +22 -1
- package/dist/material/memory/GameMemory.js.map +1 -1
- package/dist/material/memory/PlayerMemory.d.ts +22 -0
- package/dist/material/memory/PlayerMemory.js +23 -1
- package/dist/material/memory/PlayerMemory.js.map +1 -1
- package/dist/material/moves/CustomMove.d.ts +18 -0
- package/dist/material/moves/CustomMove.js +13 -0
- package/dist/material/moves/CustomMove.js.map +1 -1
- package/dist/material/moves/MaterialMove.d.ts +9 -0
- package/dist/material/moves/MaterialMoveBuilder.d.ts +36 -0
- package/dist/material/moves/MaterialMoveBuilder.js +36 -0
- package/dist/material/moves/MaterialMoveBuilder.js.map +1 -1
- package/dist/material/moves/MoveKind.d.ts +3 -0
- package/dist/material/moves/MoveKind.js +3 -0
- package/dist/material/moves/MoveKind.js.map +1 -1
- package/dist/material/moves/items/CreateItem.d.ts +13 -0
- package/dist/material/moves/items/CreateItem.js +10 -0
- package/dist/material/moves/items/CreateItem.js.map +1 -1
- package/dist/material/moves/items/CreateItemsAtOnce.d.ts +14 -0
- package/dist/material/moves/items/CreateItemsAtOnce.js +10 -0
- package/dist/material/moves/items/CreateItemsAtOnce.js.map +1 -1
- package/dist/material/moves/items/DeleteItem.d.ts +18 -0
- package/dist/material/moves/items/DeleteItem.js +11 -0
- package/dist/material/moves/items/DeleteItem.js.map +1 -1
- package/dist/material/moves/items/DeleteItemsAtOnce.d.ts +17 -0
- package/dist/material/moves/items/DeleteItemsAtOnce.js +10 -0
- package/dist/material/moves/items/DeleteItemsAtOnce.js.map +1 -1
- package/dist/material/moves/items/ItemMove.d.ts +12 -0
- package/dist/material/moves/items/ItemMoveType.d.ts +3 -0
- package/dist/material/moves/items/ItemMoveType.js +3 -0
- package/dist/material/moves/items/ItemMoveType.js.map +1 -1
- package/dist/material/moves/items/MoveItem.d.ts +20 -0
- package/dist/material/moves/items/MoveItem.js +11 -0
- package/dist/material/moves/items/MoveItem.js.map +1 -1
- package/dist/material/moves/items/MoveItemsAtOnce.d.ts +20 -0
- package/dist/material/moves/items/MoveItemsAtOnce.js +10 -0
- package/dist/material/moves/items/MoveItemsAtOnce.js.map +1 -1
- package/dist/material/moves/items/RollItem.d.ts +19 -0
- package/dist/material/moves/items/RollItem.js +10 -0
- package/dist/material/moves/items/RollItem.js.map +1 -1
- package/dist/material/moves/items/SelectItem.d.ts +20 -0
- package/dist/material/moves/items/SelectItem.js +11 -0
- package/dist/material/moves/items/SelectItem.js.map +1 -1
- package/dist/material/moves/items/Shuffle.d.ts +26 -0
- package/dist/material/moves/items/Shuffle.js +15 -0
- package/dist/material/moves/items/Shuffle.js.map +1 -1
- package/dist/material/moves/local/CloseTutorialPopup.d.ts +8 -0
- package/dist/material/moves/local/CloseTutorialPopup.js +5 -0
- package/dist/material/moves/local/CloseTutorialPopup.js.map +1 -1
- package/dist/material/moves/local/DisplayHelp.d.ts +18 -0
- package/dist/material/moves/local/DisplayHelp.js +3 -0
- package/dist/material/moves/local/DisplayHelp.js.map +1 -1
- package/dist/material/moves/local/DropItem.d.ts +9 -0
- package/dist/material/moves/local/LocalMove.d.ts +6 -0
- package/dist/material/moves/local/LocalMove.js +3 -0
- package/dist/material/moves/local/LocalMove.js.map +1 -1
- package/dist/material/moves/local/SetTutorialStep.d.ts +8 -0
- package/dist/material/moves/local/SetTutorialStep.js +5 -0
- package/dist/material/moves/local/SetTutorialStep.js.map +1 -1
- package/dist/material/rules/MaterialRulesPart.d.ts +76 -0
- package/dist/material/rules/MaterialRulesPart.js +75 -3
- package/dist/material/rules/MaterialRulesPart.js.map +1 -1
- package/dist/material/rules/PlayerTurnRule.d.ts +19 -0
- package/dist/material/rules/PlayerTurnRule.js +20 -1
- package/dist/material/rules/PlayerTurnRule.js.map +1 -1
- package/dist/material/rules/RuleStep.d.ts +3 -0
- package/dist/material/rules/SimultaneousRule.d.ts +25 -0
- package/dist/material/rules/SimultaneousRule.js +21 -1
- package/dist/material/rules/SimultaneousRule.js.map +1 -1
- package/dist/material/tutorial/TutorialState.d.ts +7 -0
- package/dist/options/OptionsValidationError.js +1 -1
- package/dist/options/PlayerEnumOption.js +3 -0
- package/dist/options/PlayerEnumOption.js.map +1 -1
- package/dist/utils/action-view.util.js +3 -1
- package/dist/utils/action-view.util.js.map +1 -1
- package/dist/utils/action.util.js +1 -1
- package/dist/utils/action.util.js.map +1 -1
- package/dist/utils/enum.util.d.ts +27 -0
- package/dist/utils/enum.util.js +24 -0
- package/dist/utils/enum.util.js.map +1 -1
- package/dist/utils/grid.squares.util.d.ts +26 -0
- package/dist/utils/grid.squares.util.js +26 -0
- package/dist/utils/grid.squares.util.js.map +1 -1
- package/dist/utils/grid.util.d.ts +8 -0
- package/dist/utils/grid.util.js +5 -0
- package/dist/utils/grid.util.js.map +1 -1
- package/dist/utils/listing.util.d.ts +12 -0
- package/dist/utils/listing.util.js +12 -0
- package/dist/utils/listing.util.js.map +1 -1
- package/dist/utils/money.util.d.ts +42 -4
- package/dist/utils/money.util.js +39 -1
- package/dist/utils/money.util.js.map +1 -1
- package/dist/utils/random.util.d.ts +6 -2
- package/dist/utils/random.util.js +6 -10
- package/dist/utils/random.util.js.map +1 -1
- package/package.json +1 -1
|
@@ -16,16 +16,49 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
16
16
|
})();
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.MaterialDeck = void 0;
|
|
19
|
-
var
|
|
20
|
-
|
|
19
|
+
var index_1 = require("./index");
|
|
20
|
+
/**
|
|
21
|
+
* This subclass of {@link Material} is design to solve one major issue: when creating moves, the material items remains unchanged (Material is immutable),
|
|
22
|
+
* so you cannot easily deal cards to multiple players at once: you will deal the first X cards all the time if you try to move items multiple time one
|
|
23
|
+
* the same Material instance.
|
|
24
|
+
*
|
|
25
|
+
* MaterialDeck is designed to mutate every time the {@link deal}, {@link dealOne} or {@link dealAtOnce} function are executed, allowing to deal cards
|
|
26
|
+
* successively to the players, without having to remove the previously dealt card all the time.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* In this example, we deal the first 5 cards to the player 1, then the next 5 cards to player 2.
|
|
30
|
+
* Using "move" instead of "deal" would give the 5 same cards to both players,
|
|
31
|
+
* so player 1 would get the cards for a very short time, then player 2 would receive them.
|
|
32
|
+
* ```
|
|
33
|
+
* const deck = this.material(MaterialType.Card).deck()
|
|
34
|
+
* return [
|
|
35
|
+
* deck.deal({type: LocationType.PlayerHand, player: player1}, 5)
|
|
36
|
+
* deck.deal({type: LocationType.PlayerHand, player: player2}, 5)
|
|
37
|
+
* ]
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
var MaterialDeck = /** @class */ (function (_super) {
|
|
21
41
|
__extends(MaterialDeck, _super);
|
|
22
42
|
function MaterialDeck() {
|
|
23
43
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
24
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Prepare moves that will change the location of the first X items AND mutate this MaterialDeck instance to remove the items that will move.
|
|
47
|
+
*
|
|
48
|
+
* @param {Location | function} arg The new location of the item. It can be a function to process the location based on the item current state.
|
|
49
|
+
* @param quantity The number of items to move
|
|
50
|
+
* @returns {MoveItem[]} the move that will change the location of the item (or a part of its quantity) when executed
|
|
51
|
+
*/
|
|
25
52
|
MaterialDeck.prototype.deal = function (arg, quantity) {
|
|
26
53
|
if (quantity === void 0) { quantity = 1; }
|
|
27
54
|
return this.new(this.entries.splice(0, quantity)).moveItems(arg);
|
|
28
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* Prepare a move that will change the location of the first item AND mutate this MaterialDeck instance to remove this items
|
|
58
|
+
*
|
|
59
|
+
* @param {Location | function} arg The new location of the item. It can be a function to process the location based on the item current state.
|
|
60
|
+
* @returns {MoveItem} the move that will change the location of the item (or a part of its quantity) when executed
|
|
61
|
+
*/
|
|
29
62
|
MaterialDeck.prototype.dealOne = function (arg) {
|
|
30
63
|
var deal = this.deal(arg);
|
|
31
64
|
if (deal.length === 0) {
|
|
@@ -38,6 +71,6 @@ var MaterialDeck = (function (_super) {
|
|
|
38
71
|
return this.new(this.entries.splice(0, quantity)).moveItemsAtOnce(arg);
|
|
39
72
|
};
|
|
40
73
|
return MaterialDeck;
|
|
41
|
-
}(
|
|
74
|
+
}(index_1.Material));
|
|
42
75
|
exports.MaterialDeck = MaterialDeck;
|
|
43
76
|
//# sourceMappingURL=MaterialDeck.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MaterialDeck.js","sourceRoot":"","sources":["../../../src/material/items/MaterialDeck.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAEA,
|
|
1
|
+
{"version":3,"file":"MaterialDeck.js","sourceRoot":"","sources":["../../../src/material/items/MaterialDeck.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAEA,iCAAkC;AAGlC;;;;;;;;;;;;;;;;;;;GAmBG;AACH;IAAmH,gCAAiB;IAApI;;IA6BA,CAAC;IA5BC;;;;;;OAMG;IACH,2BAAI,GAAJ,UAAK,GAAoE,EAAE,QAAoB;QAApB,yBAAA,EAAA,YAAoB;QAC7F,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IAClE,CAAC;IAED;;;;;OAKG;IACH,8BAAO,GAAP,UAAQ,GAAoE;QAC1E,IAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC3B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;QACvE,CAAC;QACD,OAAO,IAAI,CAAC,CAAC,CAAC,CAAA;IAChB,CAAC;IAED,iCAAU,GAAV,UAAW,GAAmB,EAAE,QAAoB;QAApB,yBAAA,EAAA,YAAoB;QAClD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;IACxE,CAAC;IACH,mBAAC;AAAD,CAAC,AA7BD,CAAmH,gBAAQ,GA6B1H;AA7BY,oCAAY"}
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { Location } from '../location';
|
|
2
|
+
/**
|
|
3
|
+
* A material item is a piece of material in a game
|
|
4
|
+
*
|
|
5
|
+
* @typeparam P - identifier of a player. Either a number or a numeric enum (eg: PlayerColor)
|
|
6
|
+
* @typeparam L - Numeric enum of the types of location in the game where the material can be located
|
|
7
|
+
* @typeparam Id - Type of id property of the item. Must be JSON serializable.
|
|
8
|
+
*
|
|
9
|
+
* @property id Optional item identifier. Meant to identify the item, but not in a unique way. For example, two identical cards in a game should have the same id.
|
|
10
|
+
* @property quantity Quantity of the item. An item without a quantity will be considered to have a quantity of 1.
|
|
11
|
+
* @property {Location} location Location of the item in the game (in a player's hand, on the table...). See {@link Location}.
|
|
12
|
+
* @property {number | boolean | undefined} selected Flag the item if selected. Items with a quantity can be partially selected using a number of select items.
|
|
13
|
+
*/
|
|
2
14
|
export type MaterialItem<P extends number = number, L extends number = number, Id = any> = {
|
|
3
15
|
id?: Id;
|
|
4
16
|
quantity?: number;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Location } from '../location';
|
|
2
|
+
import { ItemMove } from '../moves';
|
|
3
|
+
import { ItemEntry, Material } from './index';
|
|
4
|
+
import { MaterialItem } from './MaterialItem';
|
|
5
|
+
/**
|
|
6
|
+
* This subclass of {@link Material} is design to handle counting and moving Money with different units: coins of 5 and 1 for instance.
|
|
7
|
+
* It also keeps track of how much money is left after spending moves are create so that it is easy to spend money multiple time at once,
|
|
8
|
+
* without risking spending the same coins twice because the moves are no immediately executed.
|
|
9
|
+
*/
|
|
10
|
+
export declare class MaterialMoney<P extends number = number, M extends number = number, L extends number = number, Unit extends number = number> extends Material<P, M, L> {
|
|
11
|
+
readonly type: M;
|
|
12
|
+
units: Unit[];
|
|
13
|
+
protected items: MaterialItem<P, L>[];
|
|
14
|
+
protected readonly processMove?: ((move: ItemMove<P, M, L>) => void) | undefined;
|
|
15
|
+
entries: ItemEntry<P, L>[];
|
|
16
|
+
private pendingMoves;
|
|
17
|
+
/**
|
|
18
|
+
* Construct a new Material Money helper instance
|
|
19
|
+
* @param {number} type Type of items this instance will work on
|
|
20
|
+
* @param {MaterialItem[]} items The complete list of items of this type in current game state.
|
|
21
|
+
* @param {number[]} units The different units that exists in stock to count this money
|
|
22
|
+
* @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
|
|
23
|
+
* @param {function} processMove if provided, this function will be executed on every move created with this instance
|
|
24
|
+
*/
|
|
25
|
+
constructor(type: M, units: Unit[], items?: MaterialItem<P, L>[], processMove?: ((move: ItemMove<P, M, L>) => void) | undefined, entries?: ItemEntry<P, L>[]);
|
|
26
|
+
/**
|
|
27
|
+
* Helper function to return a new instance of the same class (works also for children class)
|
|
28
|
+
* @param {ItemEntry[]} entries Filtered entries for the new class
|
|
29
|
+
* @returns {this} the new Material instance
|
|
30
|
+
* @protected
|
|
31
|
+
*/
|
|
32
|
+
protected new(entries: ItemEntry<P, L>[]): this;
|
|
33
|
+
/**
|
|
34
|
+
* We need to apply the pending moves before any filtering is done to get the right count for instance.
|
|
35
|
+
*/
|
|
36
|
+
filter(predicate: (item: MaterialItem<P, L>, index: number) => boolean): this;
|
|
37
|
+
/**
|
|
38
|
+
* Count the total value of a material instance
|
|
39
|
+
* @returns the sum of each item id multiplied by its quantity
|
|
40
|
+
*/
|
|
41
|
+
get count(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Create an amount of Money and put it in given location
|
|
44
|
+
* @param amount Amount to gain
|
|
45
|
+
* @param location The location to filter material onto, and to create new items in
|
|
46
|
+
* @returns the moves that need to be played to perform the operation
|
|
47
|
+
*/
|
|
48
|
+
addMoney(amount: number, location: Location<P, L>): ItemMove<P, M, L>[];
|
|
49
|
+
/**
|
|
50
|
+
* Remove an amount of Money from given location
|
|
51
|
+
* @param amount Amount to spend
|
|
52
|
+
* @param location The location to filter material onto, and to create new items in
|
|
53
|
+
* @returns the moves that need to be played to perform the operation
|
|
54
|
+
*/
|
|
55
|
+
removeMoney(amount: number, location: Location<P, L>): ItemMove<P, M, L>[];
|
|
56
|
+
/**
|
|
57
|
+
* Move an amount of money from a place to another place. It searches after the easiest way to do it, making money with the bank only if necessary.
|
|
58
|
+
* @param origin Location to remove money from
|
|
59
|
+
* @param target Location to move money to
|
|
60
|
+
* @param amount Amount of money to transfer
|
|
61
|
+
* @returns the moves that need to be played to perform the operation
|
|
62
|
+
*/
|
|
63
|
+
moveMoney(origin: Location<P, L>, target: Location<P, L>, amount: number): ItemMove<P, M, L>[];
|
|
64
|
+
/**
|
|
65
|
+
* Return the best way to gain an amount, prioritizing the highest unit values
|
|
66
|
+
* @param amount Amount to gain, default 1
|
|
67
|
+
* @returns the record of coins to earn (only positive values)
|
|
68
|
+
*/
|
|
69
|
+
private getGainMap;
|
|
70
|
+
/**
|
|
71
|
+
* Return the best way to spend an amount of owned units, prioritizing the smallest unit values
|
|
72
|
+
* @param amount Amount to gain, default 1
|
|
73
|
+
* @returns the record of coins to give away and eventually take (positive and negative values)
|
|
74
|
+
*/
|
|
75
|
+
private getSpendMap;
|
|
76
|
+
/**
|
|
77
|
+
* Mutate the entries to get the state after
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
private applyPendingMoves;
|
|
81
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
+
if (ar || !(i in from)) {
|
|
20
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
+
ar[i] = from[i];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
+
};
|
|
26
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.MaterialMoney = void 0;
|
|
31
|
+
var lodash_1 = require("lodash");
|
|
32
|
+
var isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
33
|
+
var keyBy_1 = __importDefault(require("lodash/keyBy"));
|
|
34
|
+
var mapValues_1 = __importDefault(require("lodash/mapValues"));
|
|
35
|
+
var sumBy_1 = __importDefault(require("lodash/sumBy"));
|
|
36
|
+
var index_1 = require("./index");
|
|
37
|
+
var MaterialMutator_1 = require("./MaterialMutator");
|
|
38
|
+
/**
|
|
39
|
+
* This subclass of {@link Material} is design to handle counting and moving Money with different units: coins of 5 and 1 for instance.
|
|
40
|
+
* It also keeps track of how much money is left after spending moves are create so that it is easy to spend money multiple time at once,
|
|
41
|
+
* without risking spending the same coins twice because the moves are no immediately executed.
|
|
42
|
+
*/
|
|
43
|
+
var MaterialMoney = /** @class */ (function (_super) {
|
|
44
|
+
__extends(MaterialMoney, _super);
|
|
45
|
+
/**
|
|
46
|
+
* Construct a new Material Money helper instance
|
|
47
|
+
* @param {number} type Type of items this instance will work on
|
|
48
|
+
* @param {MaterialItem[]} items The complete list of items of this type in current game state.
|
|
49
|
+
* @param {number[]} units The different units that exists in stock to count this money
|
|
50
|
+
* @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
|
|
51
|
+
* @param {function} processMove if provided, this function will be executed on every move created with this instance
|
|
52
|
+
*/
|
|
53
|
+
function MaterialMoney(type, units, items, processMove, entries) {
|
|
54
|
+
if (items === void 0) { items = []; }
|
|
55
|
+
if (entries === void 0) { entries = Array.from(items.entries()).filter(function (entry) { return entry[1].quantity !== 0; }); }
|
|
56
|
+
var _this = _super.call(this, type, items, processMove, entries) || this;
|
|
57
|
+
_this.type = type;
|
|
58
|
+
_this.units = units;
|
|
59
|
+
_this.items = items;
|
|
60
|
+
_this.processMove = processMove;
|
|
61
|
+
_this.entries = entries;
|
|
62
|
+
_this.pendingMoves = [];
|
|
63
|
+
if (_this.units[0] === 1) {
|
|
64
|
+
_this.units = __spreadArray([], units, true);
|
|
65
|
+
_this.units.sort(function (a, b) { return b - a; }); // Sort units from highest to 1
|
|
66
|
+
}
|
|
67
|
+
if (_this.units[_this.units.length - 1] !== 1)
|
|
68
|
+
console.warn('Money without 1 in the possible values will produce unexpected outcomes');
|
|
69
|
+
return _this;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Helper function to return a new instance of the same class (works also for children class)
|
|
73
|
+
* @param {ItemEntry[]} entries Filtered entries for the new class
|
|
74
|
+
* @returns {this} the new Material instance
|
|
75
|
+
* @protected
|
|
76
|
+
*/
|
|
77
|
+
MaterialMoney.prototype.new = function (entries) {
|
|
78
|
+
var Class = this.constructor;
|
|
79
|
+
return new Class(this.type, this.units, this.items, this.processMove, entries);
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* We need to apply the pending moves before any filtering is done to get the right count for instance.
|
|
83
|
+
*/
|
|
84
|
+
MaterialMoney.prototype.filter = function (predicate) {
|
|
85
|
+
this.applyPendingMoves();
|
|
86
|
+
return _super.prototype.filter.call(this, predicate);
|
|
87
|
+
};
|
|
88
|
+
Object.defineProperty(MaterialMoney.prototype, "count", {
|
|
89
|
+
/**
|
|
90
|
+
* Count the total value of a material instance
|
|
91
|
+
* @returns the sum of each item id multiplied by its quantity
|
|
92
|
+
*/
|
|
93
|
+
get: function () {
|
|
94
|
+
this.applyPendingMoves();
|
|
95
|
+
return (0, sumBy_1.default)(this.getItems(), function (item) { var _a, _b; return ((_a = item.id) !== null && _a !== void 0 ? _a : 1) * ((_b = item.quantity) !== null && _b !== void 0 ? _b : 1); });
|
|
96
|
+
},
|
|
97
|
+
enumerable: false,
|
|
98
|
+
configurable: true
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* Create an amount of Money and put it in given location
|
|
102
|
+
* @param amount Amount to gain
|
|
103
|
+
* @param location The location to filter material onto, and to create new items in
|
|
104
|
+
* @returns the moves that need to be played to perform the operation
|
|
105
|
+
*/
|
|
106
|
+
MaterialMoney.prototype.addMoney = function (amount, location) {
|
|
107
|
+
var _a;
|
|
108
|
+
if (amount === 0)
|
|
109
|
+
return [];
|
|
110
|
+
if (amount < 0)
|
|
111
|
+
return this.removeMoney(-amount, location);
|
|
112
|
+
var moves = [];
|
|
113
|
+
var gainMap = this.getGainMap(amount);
|
|
114
|
+
for (var _i = 0, _b = this.units; _i < _b.length; _i++) {
|
|
115
|
+
var unit = _b[_i];
|
|
116
|
+
if (gainMap[unit] > 0) {
|
|
117
|
+
moves.push(this.createItem({ id: unit, location: location, quantity: gainMap[unit] }));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
(_a = this.pendingMoves).push.apply(_a, moves);
|
|
121
|
+
return moves;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Remove an amount of Money from given location
|
|
125
|
+
* @param amount Amount to spend
|
|
126
|
+
* @param location The location to filter material onto, and to create new items in
|
|
127
|
+
* @returns the moves that need to be played to perform the operation
|
|
128
|
+
*/
|
|
129
|
+
MaterialMoney.prototype.removeMoney = function (amount, location) {
|
|
130
|
+
var _a;
|
|
131
|
+
if (amount === 0)
|
|
132
|
+
return [];
|
|
133
|
+
if (amount < 0)
|
|
134
|
+
return this.addMoney(-amount, location);
|
|
135
|
+
this.applyPendingMoves();
|
|
136
|
+
if (this.entries.some(function (_a) {
|
|
137
|
+
var item = _a[1];
|
|
138
|
+
return !(0, isEqual_1.default)(item.location, location);
|
|
139
|
+
})) {
|
|
140
|
+
return this.location(function (l) { return (0, isEqual_1.default)(l, location); }).removeMoney(amount, location);
|
|
141
|
+
}
|
|
142
|
+
var moves = [];
|
|
143
|
+
var spendMap = this.getSpendMap(amount);
|
|
144
|
+
for (var _i = 0, _b = this.units; _i < _b.length; _i++) {
|
|
145
|
+
var unit = _b[_i];
|
|
146
|
+
if (spendMap[unit] < 0) {
|
|
147
|
+
moves.push(this.id(unit).deleteItem(-spendMap[unit]));
|
|
148
|
+
}
|
|
149
|
+
else if (spendMap[unit] > 0) {
|
|
150
|
+
moves.push(this.createItem({ id: unit, location: location, quantity: spendMap[unit] }));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
(_a = this.pendingMoves).push.apply(_a, moves);
|
|
154
|
+
return moves;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Move an amount of money from a place to another place. It searches after the easiest way to do it, making money with the bank only if necessary.
|
|
158
|
+
* @param origin Location to remove money from
|
|
159
|
+
* @param target Location to move money to
|
|
160
|
+
* @param amount Amount of money to transfer
|
|
161
|
+
* @returns the moves that need to be played to perform the operation
|
|
162
|
+
*/
|
|
163
|
+
MaterialMoney.prototype.moveMoney = function (origin, target, amount) {
|
|
164
|
+
var _a;
|
|
165
|
+
if (amount === 0)
|
|
166
|
+
return [];
|
|
167
|
+
if (amount < 0)
|
|
168
|
+
return this.moveMoney(target, origin, -amount);
|
|
169
|
+
this.applyPendingMoves();
|
|
170
|
+
var moves = [];
|
|
171
|
+
var originMoney = this.location(function (l) { return (0, isEqual_1.default)(l, origin); });
|
|
172
|
+
var targetMoney = this.location(function (l) { return (0, isEqual_1.default)(l, target); });
|
|
173
|
+
var originDelta = originMoney.getSpendMap(amount);
|
|
174
|
+
var targetDelta = targetMoney.getGainMap(amount);
|
|
175
|
+
for (var _i = 0, _b = this.units; _i < _b.length; _i++) {
|
|
176
|
+
var unit = _b[_i];
|
|
177
|
+
if (originDelta[unit] < 0) {
|
|
178
|
+
var _loop_1 = function () {
|
|
179
|
+
var lowerUnits = this_1.units.slice(this_1.units.indexOf(unit) + 1);
|
|
180
|
+
var targetResultDelta = targetMoney.getSpendMap(unit);
|
|
181
|
+
var valueSpent = (0, sumBy_1.default)(lowerUnits, function (unit) { return -targetResultDelta[unit] * unit; });
|
|
182
|
+
if (valueSpent === unit && lowerUnits.every(function (lowerUnit) { return targetResultDelta[lowerUnit] < 0; })) {
|
|
183
|
+
targetDelta[unit]++;
|
|
184
|
+
for (var _c = 0, lowerUnits_1 = lowerUnits; _c < lowerUnits_1.length; _c++) {
|
|
185
|
+
var lowerUnit = lowerUnits_1[_c];
|
|
186
|
+
targetDelta[lowerUnit] += targetResultDelta[lowerUnit];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else
|
|
190
|
+
return "break";
|
|
191
|
+
};
|
|
192
|
+
var this_1 = this;
|
|
193
|
+
while (targetDelta[unit] < -originDelta[unit]) {
|
|
194
|
+
var state_1 = _loop_1();
|
|
195
|
+
if (state_1 === "break")
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
var moveAmount = Math.min(-originDelta[unit], targetDelta[unit]);
|
|
199
|
+
targetDelta[unit] -= moveAmount;
|
|
200
|
+
var originMaterialUnit = originMoney.id(unit);
|
|
201
|
+
if (moveAmount > 0) {
|
|
202
|
+
moves.push(originMaterialUnit.moveItem(target, moveAmount));
|
|
203
|
+
}
|
|
204
|
+
if (moveAmount < -originDelta[unit]) {
|
|
205
|
+
moves.push(originMaterialUnit.deleteItem(-originDelta[unit] - moveAmount));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else if (originDelta[unit] > 0) {
|
|
209
|
+
if (targetDelta[unit] < 0) {
|
|
210
|
+
moves.push(targetMoney.id(unit).moveItem(origin, -targetDelta[unit]));
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
moves.push(originMoney.createItem({ id: unit, location: origin, quantity: originDelta[unit] }));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (targetDelta[unit] > 0) {
|
|
217
|
+
moves.push(targetMoney.createItem({ id: unit, location: target, quantity: targetDelta[unit] }));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
(_a = this.pendingMoves).push.apply(_a, moves);
|
|
221
|
+
return moves;
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Return the best way to gain an amount, prioritizing the highest unit values
|
|
225
|
+
* @param amount Amount to gain, default 1
|
|
226
|
+
* @returns the record of coins to earn (only positive values)
|
|
227
|
+
*/
|
|
228
|
+
MaterialMoney.prototype.getGainMap = function (amount) {
|
|
229
|
+
var map = (0, mapValues_1.default)((0, keyBy_1.default)(this.units), function (_) { return 0; });
|
|
230
|
+
for (var _i = 0, _a = this.units; _i < _a.length; _i++) {
|
|
231
|
+
var unit = _a[_i];
|
|
232
|
+
map[unit] = Math.floor(amount / unit);
|
|
233
|
+
amount %= unit;
|
|
234
|
+
}
|
|
235
|
+
return map;
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Return the best way to spend an amount of owned units, prioritizing the smallest unit values
|
|
239
|
+
* @param amount Amount to gain, default 1
|
|
240
|
+
* @returns the record of coins to give away and eventually take (positive and negative values)
|
|
241
|
+
*/
|
|
242
|
+
MaterialMoney.prototype.getSpendMap = function (amount) {
|
|
243
|
+
var _this = this;
|
|
244
|
+
var owned = (0, mapValues_1.default)((0, keyBy_1.default)(this.units), function (unit) { return _this.id(unit).getQuantity(); });
|
|
245
|
+
var map = (0, mapValues_1.default)((0, keyBy_1.default)(this.units), function (_) { return 0; });
|
|
246
|
+
for (var _1 = 0; _1 < amount; _1++) {
|
|
247
|
+
for (var i = this.units.length - 1; i >= 0; i--) {
|
|
248
|
+
var unit = this.units[i];
|
|
249
|
+
if (owned[unit] + map[unit] > 0) {
|
|
250
|
+
map[unit]--;
|
|
251
|
+
if (unit > 1) {
|
|
252
|
+
var rest = unit - 1;
|
|
253
|
+
for (var _i = 0, _a = this.units.slice(i + 1); _i < _a.length; _i++) {
|
|
254
|
+
var lowerUnit = _a[_i];
|
|
255
|
+
if (lowerUnit <= rest) {
|
|
256
|
+
map[lowerUnit] += Math.floor(rest / lowerUnit);
|
|
257
|
+
rest -= rest % lowerUnit;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return map;
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* Mutate the entries to get the state after
|
|
269
|
+
* @private
|
|
270
|
+
*/
|
|
271
|
+
MaterialMoney.prototype.applyPendingMoves = function () {
|
|
272
|
+
var _this = this;
|
|
273
|
+
if (!this.pendingMoves.length)
|
|
274
|
+
return;
|
|
275
|
+
if (this.items.some(function (item, index) { return item.quantity !== 0 && !_this.entries.some(function (entry) { return entry[0] === index; }); })) {
|
|
276
|
+
console.warn('MaterialMoney cannot track the state of the items on filtered instances, the filter will be cancelled');
|
|
277
|
+
}
|
|
278
|
+
this.items = (0, lodash_1.cloneDeep)(this.items);
|
|
279
|
+
var mutator = new MaterialMutator_1.MaterialMutator(this.type, this.items);
|
|
280
|
+
while (this.pendingMoves.length > 0) {
|
|
281
|
+
mutator.applyMove(this.pendingMoves.shift());
|
|
282
|
+
}
|
|
283
|
+
this.entries = Array.from(this.items.entries()).filter(function (entry) { return entry[1].quantity !== 0; });
|
|
284
|
+
};
|
|
285
|
+
return MaterialMoney;
|
|
286
|
+
}(index_1.Material));
|
|
287
|
+
exports.MaterialMoney = MaterialMoney;
|
|
288
|
+
//# sourceMappingURL=MaterialMoney.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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C,CAAA;QAC1D,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,EAAG,CAAC,CAAA;QAC/C,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,CAAC,EAAvB,CAAuB,CAAC,CAAA;IAC1F,CAAC;IACH,oBAAC;AAAD,CAAC,AArND,CACU,gBAAQ,GAoNjB;AArNY,sCAAa"}
|
|
@@ -1,15 +1,43 @@
|
|
|
1
1
|
import { LocationStrategy } from '../location';
|
|
2
2
|
import { ItemMoveRandomized, ItemMoveView, MoveItem, MoveItemsAtOnce } from '../moves';
|
|
3
3
|
import { MaterialItem } from './index';
|
|
4
|
+
/**
|
|
5
|
+
* Helper class to change the state of any {@link MaterialItem} in a game implemented with {@link MaterialRules}.
|
|
6
|
+
*
|
|
7
|
+
* @typeparam P - identifier of a player. Either a number or a numeric enum (eg: PlayerColor)
|
|
8
|
+
* @typeparam M - Numeric enum of the types of material manipulated in the game
|
|
9
|
+
* @typeparam L - Numeric enum of the types of location in the game where the material can be located
|
|
10
|
+
*/
|
|
4
11
|
export declare class MaterialMutator<P extends number = number, M extends number = number, L extends number = number> {
|
|
5
12
|
private readonly type;
|
|
6
13
|
private readonly items;
|
|
7
14
|
private readonly locationsStrategies;
|
|
8
15
|
private readonly canMerge;
|
|
16
|
+
/**
|
|
17
|
+
* @param type Type of items this mutator will work on
|
|
18
|
+
* @param items Items to work with
|
|
19
|
+
* @param locationsStrategies The strategies that these items must follow
|
|
20
|
+
* @param canMerge Whether to items at the exact same location can merge into one item with a quantity
|
|
21
|
+
*/
|
|
9
22
|
constructor(type: M, items: MaterialItem<P, L>[], locationsStrategies?: Partial<Record<L, LocationStrategy<P, M, L>>>, canMerge?: boolean);
|
|
23
|
+
/**
|
|
24
|
+
* Executes a move on the game items
|
|
25
|
+
* @param move
|
|
26
|
+
*/
|
|
10
27
|
applyMove(move: ItemMoveRandomized<P, M, L> | ItemMoveView<P, M, L>): void;
|
|
28
|
+
/**
|
|
29
|
+
* Find the index of an existing item we could merge a new item with (create a single item with a quantity)
|
|
30
|
+
*
|
|
31
|
+
* @param newItem An item to compare with existing items
|
|
32
|
+
* @returns {number} Index of the existing item we can merge with, or -1 if there is no possible merge
|
|
33
|
+
*/
|
|
11
34
|
findMergeIndex(newItem: MaterialItem<P, L>): number;
|
|
12
35
|
private addItem;
|
|
36
|
+
/**
|
|
37
|
+
* Provides the index that the new item will have
|
|
38
|
+
* @param newItem An item that is going to be created
|
|
39
|
+
* @returns {number} the future index of that item
|
|
40
|
+
*/
|
|
13
41
|
getItemCreationIndex(newItem: MaterialItem<P, L>): number;
|
|
14
42
|
private applyAddItemStrategy;
|
|
15
43
|
private applyMoveItemStrategy;
|
|
@@ -20,7 +48,18 @@ export declare class MaterialMutator<P extends number = number, M extends number
|
|
|
20
48
|
private roll;
|
|
21
49
|
private moveItem;
|
|
22
50
|
private moveItemsAtOnce;
|
|
51
|
+
/**
|
|
52
|
+
* Provides the state of an item after it is moved
|
|
53
|
+
* @param move The move that is going to happen
|
|
54
|
+
* @return {MaterialItem} state of the item after the move is executed
|
|
55
|
+
*/
|
|
23
56
|
getItemAfterMove(move: MoveItem<P, M, L>): MaterialItem<P, L>;
|
|
57
|
+
/**
|
|
58
|
+
* Provides the state of an item after it is moved
|
|
59
|
+
* @param move The move that is going to happen
|
|
60
|
+
* @param index Index of the item to consider
|
|
61
|
+
* @return {MaterialItem} state of the item after the move is executed
|
|
62
|
+
*/
|
|
24
63
|
getItemAfterMoveAtOnce(move: MoveItemsAtOnce<P, M, L>, index: number): MaterialItem<P, L>;
|
|
25
64
|
private getItemWithLocation;
|
|
26
65
|
private delete;
|
|
@@ -31,7 +31,20 @@ var merge_1 = __importDefault(require("lodash/merge"));
|
|
|
31
31
|
var location_1 = require("../location");
|
|
32
32
|
var moves_1 = require("../moves");
|
|
33
33
|
var index_1 = require("./index");
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Helper class to change the state of any {@link MaterialItem} in a game implemented with {@link MaterialRules}.
|
|
36
|
+
*
|
|
37
|
+
* @typeparam P - identifier of a player. Either a number or a numeric enum (eg: PlayerColor)
|
|
38
|
+
* @typeparam M - Numeric enum of the types of material manipulated in the game
|
|
39
|
+
* @typeparam L - Numeric enum of the types of location in the game where the material can be located
|
|
40
|
+
*/
|
|
41
|
+
var MaterialMutator = /** @class */ (function () {
|
|
42
|
+
/**
|
|
43
|
+
* @param type Type of items this mutator will work on
|
|
44
|
+
* @param items Items to work with
|
|
45
|
+
* @param locationsStrategies The strategies that these items must follow
|
|
46
|
+
* @param canMerge Whether to items at the exact same location can merge into one item with a quantity
|
|
47
|
+
*/
|
|
35
48
|
function MaterialMutator(type, items, locationsStrategies, canMerge) {
|
|
36
49
|
if (locationsStrategies === void 0) { locationsStrategies = {}; }
|
|
37
50
|
if (canMerge === void 0) { canMerge = true; }
|
|
@@ -40,6 +53,10 @@ var MaterialMutator = (function () {
|
|
|
40
53
|
this.locationsStrategies = locationsStrategies;
|
|
41
54
|
this.canMerge = canMerge;
|
|
42
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Executes a move on the game items
|
|
58
|
+
* @param move
|
|
59
|
+
*/
|
|
43
60
|
MaterialMutator.prototype.applyMove = function (move) {
|
|
44
61
|
switch (move.type) {
|
|
45
62
|
case moves_1.ItemMoveType.Create:
|
|
@@ -77,6 +94,12 @@ var MaterialMutator = (function () {
|
|
|
77
94
|
break;
|
|
78
95
|
}
|
|
79
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* Find the index of an existing item we could merge a new item with (create a single item with a quantity)
|
|
99
|
+
*
|
|
100
|
+
* @param newItem An item to compare with existing items
|
|
101
|
+
* @returns {number} Index of the existing item we can merge with, or -1 if there is no possible merge
|
|
102
|
+
*/
|
|
80
103
|
MaterialMutator.prototype.findMergeIndex = function (newItem) {
|
|
81
104
|
if (!this.canMerge)
|
|
82
105
|
return -1;
|
|
@@ -96,6 +119,11 @@ var MaterialMutator = (function () {
|
|
|
96
119
|
this.items.push(item);
|
|
97
120
|
}
|
|
98
121
|
};
|
|
122
|
+
/**
|
|
123
|
+
* Provides the index that the new item will have
|
|
124
|
+
* @param newItem An item that is going to be created
|
|
125
|
+
* @returns {number} the future index of that item
|
|
126
|
+
*/
|
|
99
127
|
MaterialMutator.prototype.getItemCreationIndex = function (newItem) {
|
|
100
128
|
var mergeIndex = this.findMergeIndex(newItem);
|
|
101
129
|
if (mergeIndex !== -1)
|
|
@@ -109,7 +137,7 @@ var MaterialMutator = (function () {
|
|
|
109
137
|
if (item.location.type in this.locationsStrategies) {
|
|
110
138
|
var strategy = this.locationsStrategies[item.location.type];
|
|
111
139
|
if (strategy.addItem) {
|
|
112
|
-
var material = new index_1.Material(this.type,
|
|
140
|
+
var material = new index_1.Material(this.type, this.items)
|
|
113
141
|
.location(item.location.type).player(item.location.player).locationId(item.location.id).parent(item.location.parent);
|
|
114
142
|
strategy.addItem(material, item);
|
|
115
143
|
}
|
|
@@ -119,7 +147,7 @@ var MaterialMutator = (function () {
|
|
|
119
147
|
if (item.location.type in this.locationsStrategies) {
|
|
120
148
|
var strategy = this.locationsStrategies[item.location.type];
|
|
121
149
|
if (strategy.moveItem) {
|
|
122
|
-
var material = new index_1.Material(this.type,
|
|
150
|
+
var material = new index_1.Material(this.type, this.items)
|
|
123
151
|
.location(item.location.type).player(item.location.player).locationId(item.location.id).parent(item.location.parent);
|
|
124
152
|
strategy.moveItem(material, item, index);
|
|
125
153
|
}
|
|
@@ -137,7 +165,7 @@ var MaterialMutator = (function () {
|
|
|
137
165
|
if (item.location.type in this.locationsStrategies) {
|
|
138
166
|
var strategy = this.locationsStrategies[item.location.type];
|
|
139
167
|
if (strategy.removeItem) {
|
|
140
|
-
var material = new index_1.Material(this.type,
|
|
168
|
+
var material = new index_1.Material(this.type, this.items)
|
|
141
169
|
.location(item.location.type).player(item.location.player).locationId(item.location.id).parent(item.location.parent);
|
|
142
170
|
strategy.removeItem(material, item);
|
|
143
171
|
}
|
|
@@ -212,6 +240,11 @@ var MaterialMutator = (function () {
|
|
|
212
240
|
}
|
|
213
241
|
}
|
|
214
242
|
};
|
|
243
|
+
/**
|
|
244
|
+
* Provides the state of an item after it is moved
|
|
245
|
+
* @param move The move that is going to happen
|
|
246
|
+
* @return {MaterialItem} state of the item after the move is executed
|
|
247
|
+
*/
|
|
215
248
|
MaterialMutator.prototype.getItemAfterMove = function (move) {
|
|
216
249
|
var item = this.getItemWithLocation(move.location, move.itemIndex);
|
|
217
250
|
if (move.reveal) {
|
|
@@ -225,6 +258,12 @@ var MaterialMutator = (function () {
|
|
|
225
258
|
}
|
|
226
259
|
return item;
|
|
227
260
|
};
|
|
261
|
+
/**
|
|
262
|
+
* Provides the state of an item after it is moved
|
|
263
|
+
* @param move The move that is going to happen
|
|
264
|
+
* @param index Index of the item to consider
|
|
265
|
+
* @return {MaterialItem} state of the item after the move is executed
|
|
266
|
+
*/
|
|
228
267
|
MaterialMutator.prototype.getItemAfterMoveAtOnce = function (move, index) {
|
|
229
268
|
var item = this.getItemWithLocation(move.location, index);
|
|
230
269
|
if (move.reveal && move.reveal[index]) {
|
|
@@ -244,7 +283,7 @@ var MaterialMutator = (function () {
|
|
|
244
283
|
MaterialMutator.prototype.shuffle = function (move) {
|
|
245
284
|
var _this = this;
|
|
246
285
|
if (!(0, moves_1.isShuffleRandomized)(move))
|
|
247
|
-
return;
|
|
286
|
+
return; // Nothing to do on front-end side for a shuffle. The index swap is only required on the backend.
|
|
248
287
|
var shuffledItems = move.indexes.map(function (index) { return _this.items[index]; });
|
|
249
288
|
move.newIndexes.forEach(function (newIndex, i) {
|
|
250
289
|
_this.items[newIndex] = __assign(__assign({}, shuffledItems[i]), { location: _this.items[newIndex].location });
|