isaacscript-common 1.2.61 → 1.2.62

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.
@@ -3,8 +3,10 @@ local ____lualib = require("lualib_bundle")
3
3
  local Map = ____lualib.Map
4
4
  local __TS__New = ____lualib.__TS__New
5
5
  local __TS__Iterator = ____lualib.__TS__Iterator
6
+ local __TS__ArrayFind = ____lualib.__TS__ArrayFind
7
+ local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
6
8
  local ____exports = {}
7
- local hasSubscriptions, postUpdate, checkPickupsPurchased, storePickupsInMap, storePlayersInMap, pickupIndexExists, v
9
+ local hasSubscriptions, postUpdate, checkPickupsPurchased, getPlayerThatIsNoLongerHoldingAnItem, storePickupsInMap, storePlayersInMap, pickupAtIndexStillExists, v
8
10
  local ____exports = require("features.saveDataManager.exports")
9
11
  local saveDataManager = ____exports.saveDataManager
10
12
  local ____entity = require("functions.entity")
@@ -33,44 +35,42 @@ function checkPickupsPurchased(self, pickups, players)
33
35
  local index = ____value[1]
34
36
  local pickupDescription = ____value[2]
35
37
  do
36
- if pickupIndexExists(nil, index, pickups) then
38
+ if pickupAtIndexStillExists(nil, index, pickups) then
37
39
  goto __continue7
38
40
  end
39
41
  v.room.pickupMap:delete(index)
40
- for ____, player in ipairs(players) do
41
- do
42
- local playerHoldingItem = player:IsHoldingItem()
43
- local playerIndex = getPlayerIndex(nil, player)
44
- local playerHoldingItemLastFrame = v.room.playerHoldingItemLastFrameMap:get(playerIndex)
45
- if playerHoldingItemLastFrame == nil then
46
- goto __continue9
47
- end
48
- if not playerHoldingItemLastFrame and playerHoldingItem then
49
- postPurchaseFire(
50
- nil,
51
- player,
52
- pickupDescription.variant,
53
- pickupDescription.subtype,
54
- pickupDescription.price
55
- )
56
- break
57
- end
58
- end
59
- ::__continue9::
42
+ local player = getPlayerThatIsNoLongerHoldingAnItem(nil, players)
43
+ if player ~= nil then
44
+ postPurchaseFire(
45
+ nil,
46
+ player,
47
+ pickupDescription.variant,
48
+ pickupDescription.subtype,
49
+ pickupDescription.price
50
+ )
60
51
  end
61
52
  end
62
53
  ::__continue7::
63
54
  end
64
55
  end
65
- function storePickupsInMap(self, pickups)
66
- for ____, pickup in ipairs(pickups) do
67
- do
68
- if pickup.Price == 0 then
69
- goto __continue15
70
- end
71
- v.room.pickupMap:set(pickup.Index, {variant = pickup.Variant, subtype = pickup.SubType, price = pickup.Price})
56
+ function getPlayerThatIsNoLongerHoldingAnItem(self, players)
57
+ return __TS__ArrayFind(
58
+ players,
59
+ function(____, player)
60
+ local playerHoldingItem = player:IsHoldingItem()
61
+ local playerIndex = getPlayerIndex(nil, player)
62
+ local playerHoldingItemLastFrame = v.room.playerHoldingItemLastFrameMap:get(playerIndex)
63
+ return playerHoldingItemLastFrame == false and playerHoldingItem
72
64
  end
73
- ::__continue15::
65
+ )
66
+ end
67
+ function storePickupsInMap(self, pickups)
68
+ local pickupsWithPrice = __TS__ArrayFilter(
69
+ pickups,
70
+ function(____, pickup) return pickup.Price ~= 0 end
71
+ )
72
+ for ____, pickup in ipairs(pickupsWithPrice) do
73
+ v.room.pickupMap:set(pickup.Index, {variant = pickup.Variant, subtype = pickup.SubType, price = pickup.Price})
74
74
  end
75
75
  end
76
76
  function storePlayersInMap(self, players)
@@ -80,13 +80,12 @@ function storePlayersInMap(self, players)
80
80
  v.room.playerHoldingItemLastFrameMap:set(playerIndex, holdingItem)
81
81
  end
82
82
  end
83
- function pickupIndexExists(self, index, pickups)
84
- for ____, pickup in ipairs(pickups) do
85
- if pickup.Index == index and pickup:Exists() then
86
- return true
87
- end
88
- end
89
- return false
83
+ function pickupAtIndexStillExists(self, index, pickups)
84
+ local pickupAtIndex = __TS__ArrayFind(
85
+ pickups,
86
+ function(____, pickup) return pickup.Index end
87
+ )
88
+ return pickupAtIndex ~= nil and pickupAtIndex:Exists()
90
89
  end
91
90
  v = {room = {
92
91
  pickupMap = __TS__New(Map),
@@ -2,13 +2,13 @@
2
2
  local ____lualib = require("lualib_bundle")
3
3
  local Set = ____lualib.Set
4
4
  local __TS__New = ____lualib.__TS__New
5
- local __TS__ArrayPush = ____lualib.__TS__ArrayPush
5
+ local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
6
6
  local ____exports = {}
7
7
  local hasSubscriptions, postPEffectUpdateReordered, VALID_TRANSFORMATIONS, v
8
8
  local ____exports = require("features.saveDataManager.exports")
9
9
  local saveDataManager = ____exports.saveDataManager
10
- local ____array = require("functions.array")
11
- local copyArray = ____array.copyArray
10
+ local ____math = require("functions.math")
11
+ local range = ____math.range
12
12
  local ____player = require("functions.player")
13
13
  local getPlayerIndex = ____player.getPlayerIndex
14
14
  local ____DefaultMap = require("types.DefaultMap")
@@ -37,17 +37,11 @@ function postPEffectUpdateReordered(self, player)
37
37
  end
38
38
  end
39
39
  local UNUSED_TRANSFORMATIONS = __TS__New(Set, {PlayerForm.PLAYERFORM_FLIGHT})
40
- local tempTransformations = {}
41
- do
42
- local i = 0
43
- while i < PlayerForm.NUM_PLAYER_FORMS do
44
- if not UNUSED_TRANSFORMATIONS:has(i) then
45
- __TS__ArrayPush(tempTransformations, i)
46
- end
47
- i = i + 1
48
- end
49
- end
50
- VALID_TRANSFORMATIONS = copyArray(nil, tempTransformations)
40
+ local ALL_TRANSFORMATIONS = range(nil, 0, PlayerForm.NUM_PLAYER_FORMS - 1)
41
+ VALID_TRANSFORMATIONS = __TS__ArrayFilter(
42
+ ALL_TRANSFORMATIONS,
43
+ function(____, playerForm) return not UNUSED_TRANSFORMATIONS:has(playerForm) end
44
+ )
51
45
  v = {run = {playersTransformationsMap = __TS__New(
52
46
  DefaultMap,
53
47
  function() return __TS__New(DefaultMap, false) end
@@ -164,8 +164,7 @@ function ____exports.isArray(self, ____table)
164
164
  local numEntries = 0
165
165
  for key in pairs(____table) do
166
166
  numEntries = numEntries + 1
167
- local keyType = type(key)
168
- if keyType ~= "number" then
167
+ if type(key) ~= "number" then
169
168
  return false
170
169
  end
171
170
  end
@@ -1,7 +1,8 @@
1
- declare type FirstArg<K, V> = Iterable<[K, V]> | V | ((k: K) => V);
2
- declare type SecondArg<K, V> = V | ((k: K) => V);
1
+ declare type FactoryFunction<K, V> = (k: K) => V;
2
+ declare type FirstArg<K, V> = Iterable<[K, V]> | V | FactoryFunction<K, V>;
3
+ declare type SecondArg<K, V> = V | FactoryFunction<K, V>;
3
4
  /**
4
- * An extended Map with two new methods:
5
+ * An extended Map with some new methods:
5
6
  *
6
7
  * - `getAndSetDefault` - If the key exists, this will return the same thing as the `get` method.
7
8
  * Otherwise, it will set a default value to the key, and then return the default value.
@@ -20,7 +21,7 @@ declare type SecondArg<K, V> = V | ((k: K) => V);
20
21
  *
21
22
  * // Initializes a new empty DefaultMap with a default value of a new Map
22
23
  * const defaultMapWithFactory = new DefaultMap<string, Map<string, string>>(() => {
23
- * return new Map<string, string>();
24
+ * return new Map();
24
25
  * })
25
26
  *
26
27
  * // Initializes a DefaultMap with some initial values and a default value of "bar"
@@ -29,6 +30,14 @@ declare type SecondArg<K, V> = V | ((k: K) => V);
29
30
  * ["b1", "b2"],
30
31
  * ], "bar");
31
32
  * ```
33
+ *
34
+ * If specified, the first argument of a factory function must be equal to the key:
35
+ *
36
+ * ```ts
37
+ * const defaultMapWithConditionalDefaultValue = new DefaultMap<number, number>((key: number) => {
38
+ * return isOdd(key) ? 0 : 1;
39
+ * });
40
+ * ```
32
41
  */
33
42
  export declare class DefaultMap<K, V> extends Map<K, V> {
34
43
  private defaultValue;
@@ -48,6 +57,10 @@ export declare class DefaultMap<K, V> extends Map<K, V> {
48
57
  * instantiation, this will execute the factory function.)
49
58
  */
50
59
  getDefaultValue(key: K): V;
51
- getConstructorArg(): V | ((k: K) => V);
60
+ /**
61
+ * Helper method for cloning the map. Returns either the default value or a reference to the
62
+ * factory function.
63
+ */
64
+ getConstructorArg(): V | FactoryFunction<K, V>;
52
65
  }
53
66
  export {};
@@ -3,13 +3,15 @@ local ____lualib = require("lualib_bundle")
3
3
  local __TS__Class = ____lualib.__TS__Class
4
4
  local Map = ____lualib.Map
5
5
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
6
+ local __TS__TypeOf = ____lualib.__TS__TypeOf
6
7
  local ____exports = {}
7
8
  local parseArguments, parseArgumentsOne, parseArgumentsTwo, parseDefaultValueOrDefaultValueFactory
8
9
  function parseArguments(self, firstArg, secondArg)
9
10
  return secondArg == nil and parseArgumentsOne(nil, firstArg) or parseArgumentsTwo(nil, firstArg, secondArg)
10
11
  end
11
12
  function parseArgumentsOne(self, firstArg)
12
- local ____parseDefaultValueOrDefaultValueFactory_result_1 = parseDefaultValueOrDefaultValueFactory(nil, firstArg)
13
+ local arg = firstArg
14
+ local ____parseDefaultValueOrDefaultValueFactory_result_1 = parseDefaultValueOrDefaultValueFactory(nil, arg)
13
15
  local defaultValue = ____parseDefaultValueOrDefaultValueFactory_result_1.defaultValue
14
16
  local defaultValueFactory = ____parseDefaultValueOrDefaultValueFactory_result_1.defaultValueFactory
15
17
  return {iterable = nil, defaultValue = defaultValue, defaultValueFactory = defaultValueFactory}
@@ -17,7 +19,7 @@ end
17
19
  function parseArgumentsTwo(self, firstArg, secondArg)
18
20
  local firstArgType = type(firstArg)
19
21
  if firstArgType ~= "table" then
20
- error("A DefaultMap constructor with two arguments must have the first argument be an array.")
22
+ error("A DefaultMap constructor with two arguments must have the first argument be the initializer list.")
21
23
  end
22
24
  local ____parseDefaultValueOrDefaultValueFactory_result_2 = parseDefaultValueOrDefaultValueFactory(nil, secondArg)
23
25
  local defaultValue = ____parseDefaultValueOrDefaultValueFactory_result_2.defaultValue
@@ -25,14 +27,13 @@ function parseArgumentsTwo(self, firstArg, secondArg)
25
27
  return {iterable = firstArg, defaultValue = defaultValue, defaultValueFactory = defaultValueFactory}
26
28
  end
27
29
  function parseDefaultValueOrDefaultValueFactory(self, arg)
28
- local argType = type(arg)
29
- if argType == "function" then
30
+ if type(arg) == "function" then
30
31
  return {defaultValue = nil, defaultValueFactory = arg}
31
32
  end
32
- if argType == "boolean" or argType == "number" or argType == "string" then
33
+ if type(arg) == "boolean" or type(arg) == "number" or type(arg) == "string" then
33
34
  return {defaultValue = arg, defaultValueFactory = nil}
34
35
  end
35
- return error("A DefaultMap was instantiated with an unknown type of: " .. argType)
36
+ return error("A DefaultMap was instantiated with an unknown type of: " .. __TS__TypeOf(arg))
36
37
  end
37
38
  ____exports.DefaultMap = __TS__Class()
38
39
  local DefaultMap = ____exports.DefaultMap
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.61",
3
+ "version": "1.2.62",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",