isaacscript-common 1.2.61 → 1.2.64

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.
@@ -1,6 +1,5 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____lualib = require("lualib_bundle")
3
- local Map = ____lualib.Map
4
3
  local __TS__New = ____lualib.__TS__New
5
4
  local ____exports = {}
6
5
  local hasSubscriptions, entityTakeDmgPlayer, v
@@ -9,9 +8,11 @@ local saveDataManager = ____exports.saveDataManager
9
8
  local ____player = require("functions.player")
10
9
  local getPlayerIndex = ____player.getPlayerIndex
11
10
  local isChildPlayer = ____player.isChildPlayer
12
- local isDamageToPlayerFatal = ____player.isDamageToPlayerFatal
13
11
  local ____revive = require("functions.revive")
12
+ local isDamageToPlayerFatal = ____revive.isDamageToPlayerFatal
14
13
  local willPlayerRevive = ____revive.willPlayerRevive
14
+ local ____DefaultMap = require("types.DefaultMap")
15
+ local DefaultMap = ____DefaultMap.DefaultMap
15
16
  local ____postPlayerFatalDamage = require("callbacks.subscriptions.postPlayerFatalDamage")
16
17
  local postPlayerFatalDamageFire = ____postPlayerFatalDamage.postPlayerFatalDamageFire
17
18
  local postPlayerFatalDamageHasSubscriptions = ____postPlayerFatalDamage.postPlayerFatalDamageHasSubscriptions
@@ -32,8 +33,7 @@ function entityTakeDmgPlayer(self, tookDamage, damageAmount, damageFlags, damage
32
33
  local game = Game()
33
34
  local gameFrameCount = game:GetFrameCount()
34
35
  local playerIndex = getPlayerIndex(nil, player)
35
- local lastDamageFrame = v.run.playerLastDamageFrame:get(playerIndex)
36
- v.run.playerLastDamageFrame:set(playerIndex, gameFrameCount)
36
+ local lastDamageGameFrame = v.run.playersLastDamageGameFrame:getAndSetDefault(playerIndex, gameFrameCount)
37
37
  if willPlayerRevive(nil, player) then
38
38
  return nil
39
39
  end
@@ -42,7 +42,7 @@ function entityTakeDmgPlayer(self, tookDamage, damageAmount, damageFlags, damage
42
42
  player,
43
43
  damageAmount,
44
44
  damageSource,
45
- lastDamageFrame
45
+ lastDamageGameFrame
46
46
  ) then
47
47
  return nil
48
48
  end
@@ -59,7 +59,10 @@ function entityTakeDmgPlayer(self, tookDamage, damageAmount, damageFlags, damage
59
59
  end
60
60
  return nil
61
61
  end
62
- v = {run = {playerLastDamageFrame = __TS__New(Map)}}
62
+ v = {run = {playersLastDamageGameFrame = __TS__New(
63
+ DefaultMap,
64
+ function(____, _key, gameFrameCount) return gameFrameCount end
65
+ )}}
63
66
  function ____exports.postPlayerFatalDamageCallbackInit(self, mod)
64
67
  saveDataManager(nil, "postPlayerFatalDamage", v)
65
68
  mod:AddCallback(ModCallbacks.MC_ENTITY_TAKE_DMG, entityTakeDmgPlayer, EntityType.ENTITY_PLAYER)
@@ -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
@@ -210,8 +210,6 @@ export declare function isBethany(player: EntityPlayer): boolean;
210
210
  * (For example, the Strawman Keeper.)
211
211
  */
212
212
  export declare function isChildPlayer(player: EntityPlayer): boolean;
213
- /** Uses the player's current health and character to determine if incoming damage will be fatal. */
214
- export declare function isDamageToPlayerFatal(player: EntityPlayer, damageAmount: int, damageSource: EntityRef, lastDamageFrame?: int): boolean;
215
213
  export declare function isFirstPlayer(player: EntityPlayer): boolean;
216
214
  /**
217
215
  * Helper function for detecting when a player is Jacob or Esau. This will only match the
@@ -484,44 +484,6 @@ function ____exports.isBethany(self, player)
484
484
  local character = player:GetPlayerType()
485
485
  return character == PlayerType.PLAYER_BETHANY or character == PlayerType.PLAYER_BETHANY_B
486
486
  end
487
- function ____exports.isDamageToPlayerFatal(self, player, damageAmount, damageSource, lastDamageFrame)
488
- local game = Game()
489
- local gameFrameCount = game:GetFrameCount()
490
- local character = player:GetPlayerType()
491
- local effects = player:GetEffects()
492
- local isBerserk = effects:HasCollectibleEffect(CollectibleType.COLLECTIBLE_BERSERK)
493
- if character == PlayerType.PLAYER_JACOB_B and damageSource.Type == EntityType.ENTITY_DARK_ESAU then
494
- return false
495
- end
496
- if isBerserk then
497
- return false
498
- end
499
- if character == PlayerType.PLAYER_JACOB2_B then
500
- return true
501
- end
502
- if ____exports.hasLostCurse(nil, player) then
503
- return true
504
- end
505
- local playerNumAllHearts = ____exports.getPlayerNumHitsRemaining(nil, player)
506
- if damageAmount < playerNumAllHearts then
507
- return false
508
- end
509
- local playerAvailableHeartSlots = ____exports.getPlayerAvailableHeartSlots(nil, player)
510
- if player:HasCollectible(CollectibleType.COLLECTIBLE_HEARTBREAK) and playerAvailableHeartSlots >= 2 then
511
- return false
512
- end
513
- if player:HasCollectible(CollectibleType.COLLECTIBLE_BROKEN_GLASS_CANNON) and gameFrameCount == lastDamageFrame then
514
- return false
515
- end
516
- local hearts = player:GetHearts()
517
- local eternalHearts = player:GetEternalHearts()
518
- local soulHearts = player:GetSoulHearts()
519
- local boneHearts = player:GetBoneHearts()
520
- if hearts > 0 and soulHearts > 0 or hearts > 0 and boneHearts > 0 or soulHearts > 0 and boneHearts > 0 or soulHearts > 0 and eternalHearts > 0 or boneHearts >= 2 then
521
- return false
522
- end
523
- return true
524
- end
525
487
  function ____exports.isFirstPlayer(self, player)
526
488
  return ____exports.getPlayerIndexVanilla(nil, player) == 0
527
489
  end
@@ -586,9 +548,9 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
586
548
  itemPool:RemoveCollectible(collectibleType)
587
549
  end
588
550
  repeat
589
- local ____switch127 = activeSlot
590
- local ____cond127 = ____switch127 == ActiveSlot.SLOT_PRIMARY
591
- if ____cond127 then
551
+ local ____switch118 = activeSlot
552
+ local ____cond118 = ____switch118 == ActiveSlot.SLOT_PRIMARY
553
+ if ____cond118 then
592
554
  do
593
555
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
594
556
  player:RemoveCollectible(primaryCollectibleType)
@@ -597,8 +559,8 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
597
559
  break
598
560
  end
599
561
  end
600
- ____cond127 = ____cond127 or ____switch127 == ActiveSlot.SLOT_SECONDARY
601
- if ____cond127 then
562
+ ____cond118 = ____cond118 or ____switch118 == ActiveSlot.SLOT_SECONDARY
563
+ if ____cond118 then
602
564
  do
603
565
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
604
566
  player:RemoveCollectible(primaryCollectibleType)
@@ -613,16 +575,16 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
613
575
  break
614
576
  end
615
577
  end
616
- ____cond127 = ____cond127 or ____switch127 == ActiveSlot.SLOT_POCKET
617
- if ____cond127 then
578
+ ____cond118 = ____cond118 or ____switch118 == ActiveSlot.SLOT_POCKET
579
+ if ____cond118 then
618
580
  do
619
581
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
620
582
  player:SetActiveCharge(charge, activeSlot)
621
583
  break
622
584
  end
623
585
  end
624
- ____cond127 = ____cond127 or ____switch127 == ActiveSlot.SLOT_POCKET2
625
- if ____cond127 then
586
+ ____cond118 = ____cond118 or ____switch118 == ActiveSlot.SLOT_POCKET2
587
+ if ____cond118 then
626
588
  do
627
589
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
628
590
  break
@@ -1,4 +1,9 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /**
3
+ * Uses the player's current health and other miscellaneous things to determine if incoming damage
4
+ * will be fatal.
5
+ */
6
+ export declare function isDamageToPlayerFatal(player: EntityPlayer, damageAmount: int, damageSource: EntityRef, lastDamageGameFrame: int): boolean;
2
7
  /**
3
8
  * The `EntityPlayer.WillPlayerRevive()` function does not properly account for Mysterious Paper,
4
9
  * so use this helper function instead for more robust revival detection.
@@ -2,6 +2,9 @@
2
2
  local ____exports = {}
3
3
  local ____player = require("functions.player")
4
4
  local getDeathAnimationName = ____player.getDeathAnimationName
5
+ local getPlayerAvailableHeartSlots = ____player.getPlayerAvailableHeartSlots
6
+ local getPlayerNumHitsRemaining = ____player.getPlayerNumHitsRemaining
7
+ local hasLostCurse = ____player.hasLostCurse
5
8
  local ____sprite = require("functions.sprite")
6
9
  local getFinalFrameOfAnimation = ____sprite.getFinalFrameOfAnimation
7
10
  local ____trinketGive = require("functions.trinketGive")
@@ -16,12 +19,6 @@ function ____exports.willMysteriousPaperRevive(self, player)
16
19
  local frameOfDeath = gameFrameCount + deathAnimationFrames + 1
17
20
  return frameOfDeath % 4 == 3
18
21
  end
19
- function ____exports.willPlayerRevive(self, player)
20
- local trinketSituation = temporarilyRemoveTrinket(nil, player, TrinketType.TRINKET_MYSTERIOUS_PAPER)
21
- local willRevive = player:WillPlayerRevive() or trinketSituation ~= nil and ____exports.willMysteriousPaperRevive(nil, player)
22
- giveTrinketsBack(nil, player, trinketSituation)
23
- return willRevive
24
- end
25
22
  function ____exports.willReviveFromSpiritShackles(self, player)
26
23
  if not player:HasCollectible(CollectibleType.COLLECTIBLE_SPIRIT_SHACKLES) then
27
24
  return false
@@ -31,4 +28,51 @@ function ____exports.willReviveFromSpiritShackles(self, player)
31
28
  local playerInSoulForm = effects:HasNullEffect(NullItemID.ID_SPIRIT_SHACKLES_SOUL)
32
29
  return spiritShacklesEnabled and not playerInSoulForm
33
30
  end
31
+ function ____exports.isDamageToPlayerFatal(self, player, damageAmount, damageSource, lastDamageGameFrame)
32
+ local game = Game()
33
+ local gameFrameCount = game:GetFrameCount()
34
+ local character = player:GetPlayerType()
35
+ local effects = player:GetEffects()
36
+ local isBerserk = effects:HasCollectibleEffect(CollectibleType.COLLECTIBLE_BERSERK)
37
+ if character == PlayerType.PLAYER_JACOB_B and damageSource.Type == EntityType.ENTITY_DARK_ESAU then
38
+ return false
39
+ end
40
+ if isBerserk then
41
+ return false
42
+ end
43
+ if ____exports.willReviveFromSpiritShackles(nil, player) then
44
+ return false
45
+ end
46
+ if character == PlayerType.PLAYER_JACOB2_B then
47
+ return true
48
+ end
49
+ if hasLostCurse(nil, player) then
50
+ return true
51
+ end
52
+ local playerNumAllHearts = getPlayerNumHitsRemaining(nil, player)
53
+ if damageAmount < playerNumAllHearts then
54
+ return false
55
+ end
56
+ local playerAvailableHeartSlots = getPlayerAvailableHeartSlots(nil, player)
57
+ if player:HasCollectible(CollectibleType.COLLECTIBLE_HEARTBREAK) and playerAvailableHeartSlots >= 2 then
58
+ return false
59
+ end
60
+ if player:HasCollectible(CollectibleType.COLLECTIBLE_BROKEN_GLASS_CANNON) and gameFrameCount == lastDamageGameFrame then
61
+ return false
62
+ end
63
+ local hearts = player:GetHearts()
64
+ local eternalHearts = player:GetEternalHearts()
65
+ local soulHearts = player:GetSoulHearts()
66
+ local boneHearts = player:GetBoneHearts()
67
+ if hearts > 0 and soulHearts > 0 or hearts > 0 and boneHearts > 0 or soulHearts > 0 and boneHearts > 0 or soulHearts > 0 and eternalHearts > 0 or boneHearts >= 2 then
68
+ return false
69
+ end
70
+ return true
71
+ end
72
+ function ____exports.willPlayerRevive(self, player)
73
+ local trinketSituation = temporarilyRemoveTrinket(nil, player, TrinketType.TRINKET_MYSTERIOUS_PAPER)
74
+ local willRevive = player:WillPlayerRevive() or trinketSituation ~= nil and ____exports.willMysteriousPaperRevive(nil, player)
75
+ giveTrinketsBack(nil, player, trinketSituation)
76
+ return willRevive
77
+ end
34
78
  return ____exports
@@ -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, A extends unknown[]> = (k: K, ...extraArgs: A) => V;
2
+ declare type FirstArg<K, V, A extends unknown[]> = Iterable<[K, V]> | V | FactoryFunction<K, V, A>;
3
+ declare type SecondArg<K, V, A extends unknown[]> = V | FactoryFunction<K, V, A>;
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,25 +30,46 @@ 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 always 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
+ * ```
41
+ *
42
+ * You can also specify a factory function that takes a generic amount of arguments beyond the
43
+ * first:
44
+ *
45
+ * ```ts
46
+ * const defaultMapWithExtraArgs = new DefaultMap<string, string>((_key: string, arg2: boolean) => {
47
+ * return arg2 ? 0 : 1;
48
+ * })
49
+ * ```
32
50
  */
33
- export declare class DefaultMap<K, V> extends Map<K, V> {
51
+ export declare class DefaultMap<K, V, A extends unknown[] = []> extends Map<K, V> {
34
52
  private defaultValue;
35
53
  private defaultValueFactory;
36
54
  /**
37
55
  * See the DefaultMap documentation:
38
56
  * https://isaacscript.github.io/isaacscript-common/classes/types_DefaultMap.DefaultMap.html
39
57
  */
40
- constructor(iterableOrDefaultValueOrDefaultValueFactory: FirstArg<K, V>, defaultValueOrDefaultValueFactory?: SecondArg<K, V>);
58
+ constructor(iterableOrDefaultValueOrDefaultValueFactory: FirstArg<K, V, A>, defaultValueOrDefaultValueFactory?: SecondArg<K, V, A>);
41
59
  /**
42
60
  * If the key exists, this will return the same thing as the `get` method. Otherwise, it will set
43
61
  * a default value to the key, and then return the default value.
44
62
  */
45
- getAndSetDefault(key: K): V;
63
+ getAndSetDefault(key: K, ...extraArgs: A): V;
46
64
  /**
47
65
  * Returns the default value to be used for a new key. (If a factory function was provided during
48
66
  * instantiation, this will execute the factory function.)
49
67
  */
50
- getDefaultValue(key: K): V;
51
- getConstructorArg(): V | ((k: K) => V);
68
+ getDefaultValue(key: K, ...extraArgs: A): V;
69
+ /**
70
+ * Helper method for cloning the map. Returns either the default value or a reference to the
71
+ * factory function.
72
+ */
73
+ getConstructorArg(): V | FactoryFunction<K, V, A>;
52
74
  }
53
75
  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
@@ -54,21 +55,21 @@ function DefaultMap.prototype.____constructor(self, iterableOrDefaultValueOrDefa
54
55
  self.defaultValue = defaultValue
55
56
  self.defaultValueFactory = defaultValueFactory
56
57
  end
57
- function DefaultMap.prototype.getAndSetDefault(self, key)
58
+ function DefaultMap.prototype.getAndSetDefault(self, key, ...)
58
59
  local value = self:get(key)
59
60
  if value ~= nil then
60
61
  return value
61
62
  end
62
- local defaultValue = self:getDefaultValue(key)
63
+ local defaultValue = self:getDefaultValue(key, ...)
63
64
  self:set(key, defaultValue)
64
65
  return defaultValue
65
66
  end
66
- function DefaultMap.prototype.getDefaultValue(self, key)
67
+ function DefaultMap.prototype.getDefaultValue(self, key, ...)
67
68
  if self.defaultValue ~= nil then
68
69
  return self.defaultValue
69
70
  end
70
71
  if self.defaultValueFactory ~= nil then
71
- return self:defaultValueFactory(key)
72
+ return self:defaultValueFactory(key, ...)
72
73
  end
73
74
  return error("A DefaultMap was incorrectly instantiated.")
74
75
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.61",
3
+ "version": "1.2.64",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -27,7 +27,7 @@
27
27
  "devDependencies": {
28
28
  "@zamiell/typescript-to-lua": "^1.4.0",
29
29
  "isaac-typescript-definitions": "^1.0.349",
30
- "isaacscript-lint": "^1.0.79",
30
+ "isaacscript-lint": "^1.0.81",
31
31
  "isaacscript-tsconfig": "^1.1.8",
32
32
  "typedoc": "^0.22.12",
33
33
  "typescript": "^4.5.5"