isaacscript-common 1.2.108 → 1.2.109

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.
@@ -2,11 +2,13 @@
2
2
  local ____lualib = require("lualib_bundle")
3
3
  local Map = ____lualib.Map
4
4
  local __TS__New = ____lualib.__TS__New
5
+ local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
6
+ local __TS__ArrayMap = ____lualib.__TS__ArrayMap
7
+ local Set = ____lualib.Set
5
8
  local __TS__Iterator = ____lualib.__TS__Iterator
6
9
  local __TS__ArrayFind = ____lualib.__TS__ArrayFind
7
- local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
8
10
  local ____exports = {}
9
- local hasSubscriptions, postUpdate, checkPickupsPurchased, getPlayerThatIsNoLongerHoldingAnItem, storePickupsInMap, storePlayersInMap, pickupAtIndexStillExists, v
11
+ local hasSubscriptions, postUpdate, checkPickupsPurchased, checkCollectiblesPurchased, getPlayerThatIsNoLongerHoldingAnItem, storePickupsInMap, storeCollectiblesInMap, storePlayersInMap, v
10
12
  local ____exports = require("features.saveDataManager.exports")
11
13
  local saveDataManager = ____exports.saveDataManager
12
14
  local ____pickups = require("functions.pickups")
@@ -14,6 +16,10 @@ local getPickups = ____pickups.getPickups
14
16
  local ____player = require("functions.player")
15
17
  local getPlayerIndex = ____player.getPlayerIndex
16
18
  local getPlayers = ____player.getPlayers
19
+ local ____DefaultMap = require("types.DefaultMap")
20
+ local DefaultMap = ____DefaultMap.DefaultMap
21
+ local ____PickupDescription = require("types.PickupDescription")
22
+ local getPickupDescription = ____PickupDescription.getPickupDescription
17
23
  local ____postPurchase = require("callbacks.subscriptions.postPurchase")
18
24
  local postPurchaseFire = ____postPurchase.postPurchaseFire
19
25
  local postPurchaseHasSubscriptions = ____postPurchase.postPurchaseHasSubscriptions
@@ -25,72 +31,99 @@ function postUpdate(self)
25
31
  return
26
32
  end
27
33
  local pickups = getPickups(nil)
34
+ local pickupsWithPrice = __TS__ArrayFilter(
35
+ pickups,
36
+ function(____, pickup) return pickup:Exists() and pickup.Price ~= 0 end
37
+ )
38
+ local nonCollectiblesWithPrice = __TS__ArrayFilter(
39
+ pickupsWithPrice,
40
+ function(____, pickup) return pickup.Variant ~= PickupVariant.PICKUP_COLLECTIBLE end
41
+ )
42
+ local collectiblesWithPrice = __TS__ArrayFilter(
43
+ pickupsWithPrice,
44
+ function(____, pickup) return pickup.Variant == PickupVariant.PICKUP_COLLECTIBLE end
45
+ )
28
46
  local players = getPlayers(nil)
29
- checkPickupsPurchased(nil, pickups, players)
30
- storePickupsInMap(nil, pickups)
47
+ checkPickupsPurchased(nil, nonCollectiblesWithPrice, players)
48
+ checkCollectiblesPurchased(nil, collectiblesWithPrice, players)
49
+ storePickupsInMap(nil, nonCollectiblesWithPrice)
50
+ storeCollectiblesInMap(nil, collectiblesWithPrice)
31
51
  storePlayersInMap(nil, players)
32
52
  end
33
- function checkPickupsPurchased(self, pickups, players)
53
+ function checkPickupsPurchased(self, nonCollectiblesWithPrice, players)
54
+ local pickupIndexes = __TS__ArrayMap(
55
+ nonCollectiblesWithPrice,
56
+ function(____, pickup) return pickup.Index end
57
+ )
58
+ local pickupIndexSet = __TS__New(Set, pickupIndexes)
34
59
  for ____, ____value in __TS__Iterator(v.room.pickupMap:entries()) do
35
60
  local index = ____value[1]
36
61
  local pickupDescription = ____value[2]
37
62
  do
38
- if pickupAtIndexStillExists(nil, index, pickups) then
39
- goto __continue7
63
+ if pickupIndexSet:has(index) then
64
+ goto __continue11
40
65
  end
41
- v.room.pickupMap:delete(index)
42
66
  local player = getPlayerThatIsNoLongerHoldingAnItem(nil, players)
43
67
  if player ~= nil then
44
68
  postPurchaseFire(nil, player, pickupDescription)
45
69
  end
46
70
  end
47
- ::__continue7::
71
+ ::__continue11::
72
+ end
73
+ end
74
+ function checkCollectiblesPurchased(self, collectiblesWithPrice, players)
75
+ for ____, collectible in ipairs(collectiblesWithPrice) do
76
+ do
77
+ local pickupDescription = v.room.collectibleMap:get(collectible.Index)
78
+ if pickupDescription == nil then
79
+ goto __continue16
80
+ end
81
+ if pickupDescription.subType ~= collectible.SubType and collectible.SubType == CollectibleType.COLLECTIBLE_NULL then
82
+ local player = getPlayerThatIsNoLongerHoldingAnItem(nil, players)
83
+ if player ~= nil then
84
+ postPurchaseFire(nil, player, pickupDescription)
85
+ end
86
+ end
87
+ end
88
+ ::__continue16::
48
89
  end
49
90
  end
50
91
  function getPlayerThatIsNoLongerHoldingAnItem(self, players)
51
92
  return __TS__ArrayFind(
52
93
  players,
53
94
  function(____, player)
54
- local playerHoldingItem = player:IsHoldingItem()
95
+ local playerHoldingItemNow = player:IsHoldingItem()
55
96
  local playerIndex = getPlayerIndex(nil, player)
56
- local playerHoldingItemLastFrame = v.room.playerHoldingItemLastFrameMap:get(playerIndex)
57
- return playerHoldingItemLastFrame == false and playerHoldingItem
97
+ local playerHoldingItemOnLastFrame = v.room.playersHoldingItemOnLastFrameMap:getAndSetDefault(playerIndex)
98
+ return not playerHoldingItemOnLastFrame and playerHoldingItemNow
58
99
  end
59
100
  )
60
101
  end
61
- function storePickupsInMap(self, pickups)
62
- local pickupsWithPrice = __TS__ArrayFilter(
63
- pickups,
64
- function(____, pickup) return pickup.Price ~= 0 end
65
- )
66
- for ____, pickup in ipairs(pickupsWithPrice) do
67
- v.room.pickupMap:set(pickup.Index, {
68
- variant = pickup.Variant,
69
- subType = pickup.SubType,
70
- position = pickup.Position,
71
- velocity = pickup.Velocity,
72
- price = pickup.Price,
73
- initSeed = pickup.InitSeed
74
- })
102
+ function storePickupsInMap(self, nonCollectiblesWithPrice)
103
+ v.room.pickupMap:clear()
104
+ for ____, pickup in ipairs(nonCollectiblesWithPrice) do
105
+ local pickupDescription = getPickupDescription(nil, pickup)
106
+ v.room.pickupMap:set(pickup.Index, pickupDescription)
107
+ end
108
+ end
109
+ function storeCollectiblesInMap(self, collectiblesWithPrice)
110
+ v.room.collectibleMap:clear()
111
+ for ____, collectible in ipairs(collectiblesWithPrice) do
112
+ local pickupDescription = getPickupDescription(nil, collectible)
113
+ v.room.collectibleMap:set(collectible.Index, pickupDescription)
75
114
  end
76
115
  end
77
116
  function storePlayersInMap(self, players)
78
117
  for ____, player in ipairs(players) do
79
118
  local playerIndex = getPlayerIndex(nil, player)
80
119
  local holdingItem = player:IsHoldingItem()
81
- v.room.playerHoldingItemLastFrameMap:set(playerIndex, holdingItem)
120
+ v.room.playersHoldingItemOnLastFrameMap:set(playerIndex, holdingItem)
82
121
  end
83
122
  end
84
- function pickupAtIndexStillExists(self, index, pickups)
85
- local pickupAtIndex = __TS__ArrayFind(
86
- pickups,
87
- function(____, pickup) return pickup.Index end
88
- )
89
- return pickupAtIndex ~= nil and pickupAtIndex:Exists()
90
- end
91
123
  v = {room = {
92
124
  pickupMap = __TS__New(Map),
93
- playerHoldingItemLastFrameMap = __TS__New(Map)
125
+ collectibleMap = __TS__New(Map),
126
+ playersHoldingItemOnLastFrameMap = __TS__New(DefaultMap, false)
94
127
  }}
95
128
  function ____exports.postPurchaseCallbackInit(self, mod)
96
129
  saveDataManager(nil, "postPurchase", v, hasSubscriptions)
@@ -6,6 +6,8 @@ local ____exports = {}
6
6
  local postPickupInitCollectible, v
7
7
  local ____errors = require("errors")
8
8
  local getUpgradeErrorMsg = ____errors.getUpgradeErrorMsg
9
+ local ____entity = require("functions.entity")
10
+ local getEntityID = ____entity.getEntityID
9
11
  local ____rooms = require("functions.rooms")
10
12
  local getRoomItemPoolType = ____rooms.getRoomItemPoolType
11
13
  local ____exports = require("features.saveDataManager.exports")
@@ -31,7 +33,8 @@ function ____exports.getCollectibleItemPoolType(self, collectible)
31
33
  error(msg)
32
34
  end
33
35
  if collectible.Type ~= EntityType.ENTITY_PICKUP or collectible.Variant ~= PickupVariant.PICKUP_COLLECTIBLE then
34
- error((((("The \"getCollectibleItemPoolType()\" function was given a non-collectible: " .. tostring(collectible.Type)) .. ".") .. tostring(collectible.Variant)) .. ".") .. tostring(collectible.SubType))
36
+ local entityID = getEntityID(nil, collectible)
37
+ error("The \"getCollectibleItemPoolType()\" function was given a non-collectible: " .. entityID)
35
38
  end
36
39
  local ptrHash = GetPtrHash(collectible)
37
40
  local itemPoolType = v.run.collectibleItemPoolTypeMap:get(ptrHash)
@@ -1,4 +1,5 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ import { CollectiblePedestalType } from "../types/CollectiblePedestalType";
2
3
  export declare function collectibleHasTag(collectibleType: CollectibleType | int, tag: ItemConfigTag): boolean;
3
4
  export declare function clearCollectibleSprite(collectible: EntityPickup): void;
4
5
  export declare function collectibleHasCacheFlag(collectibleType: CollectibleType | int, cacheFlag: CacheFlag): boolean;
@@ -48,6 +49,7 @@ export declare function getCollectibleMaxCharges(collectibleType: CollectibleTyp
48
49
  * ```
49
50
  */
50
51
  export declare function getCollectibleName(collectibleType: CollectibleType | int): string;
52
+ export declare function getCollectiblePedestalType(collectible: EntityPickup): CollectiblePedestalType;
51
53
  /** Helper function to get all of the collectible entities in the room. */
52
54
  export declare function getCollectibles(matchingSubType?: number): EntityPickup[];
53
55
  export declare function getMaxCollectibleType(): int;
@@ -56,7 +58,7 @@ export declare function getMaxCollectibleType(): int;
56
58
  * glitched items once a player has TMTRAINER. However, glitched items can also "naturally" appear
57
59
  * in secret rooms and I AM ERROR rooms if the "Corrupted Data" achievement is unlocked.
58
60
  */
59
- export declare function isGlitchedCollectible(entity: Entity): boolean;
61
+ export declare function isGlitchedCollectible(pickup: EntityPickup): boolean;
60
62
  /**
61
63
  * Returns true if the item type in the item config is equal to `ItemType.ITEM_PASSIVE` or
62
64
  * `ItemType.ITEM_FAMILIAR`.
@@ -138,6 +138,13 @@ function ____exports.getCollectibleName(self, collectibleType)
138
138
  end
139
139
  return itemConfigItem.Name
140
140
  end
141
+ function ____exports.getCollectiblePedestalType(self, collectible)
142
+ if collectible.Variant ~= PickupVariant.PICKUP_COLLECTIBLE then
143
+ error("You cannot get the pedestal type for pickups of variant: " .. tostring(collectible.Variant))
144
+ end
145
+ local sprite = collectible:GetSprite()
146
+ return sprite:GetOverlayFrame()
147
+ end
141
148
  function ____exports.getCollectibles(self, matchingSubType)
142
149
  if matchingSubType == nil then
143
150
  matchingSubType = -1
@@ -148,8 +155,8 @@ function ____exports.getMaxCollectibleType(self)
148
155
  local itemConfig = Isaac.GetItemConfig()
149
156
  return itemConfig:GetCollectibles().Size - 1
150
157
  end
151
- function ____exports.isGlitchedCollectible(self, entity)
152
- return entity.Type == EntityType.ENTITY_PICKUP and entity.Variant == PickupVariant.PICKUP_COLLECTIBLE and entity.SubType > GLITCHED_ITEM_THRESHOLD
158
+ function ____exports.isGlitchedCollectible(self, pickup)
159
+ return pickup.Variant == PickupVariant.PICKUP_COLLECTIBLE and pickup.SubType > GLITCHED_ITEM_THRESHOLD
153
160
  end
154
161
  function ____exports.isPassiveCollectible(self, collectibleType)
155
162
  local itemType = ____exports.getCollectibleItemType(nil, collectibleType)
@@ -53,6 +53,8 @@ export declare function getFilteredNewEntities<T extends AnyEntity>(oldEntities:
53
53
  * returned. False by default. Will only be taken into account if `matchingEntityType` is specified.
54
54
  */
55
55
  export declare function getEntities(matchingEntityType?: EntityType | int, matchingVariant?: number, matchingSubType?: number, ignoreFriendly?: boolean): Entity[];
56
+ /** Helper function to return a string containing an entity's type, variant, and sub-type. */
57
+ export declare function getEntityID(entity: Entity): string;
56
58
  /**
57
59
  * Helper function to measure an entity's velocity to see if it is moving.
58
60
  *
@@ -88,6 +88,9 @@ function ____exports.getEntities(self, matchingEntityType, matchingVariant, matc
88
88
  end
89
89
  return Isaac.FindByType(matchingEntityType, matchingVariant, matchingSubType, ignoreFriendly)
90
90
  end
91
+ function ____exports.getEntityID(self, entity)
92
+ return (((tostring(entity.Type) .. ".") .. tostring(entity.Variant)) .. ".") .. tostring(entity.SubType)
93
+ end
91
94
  function ____exports.isEntityMoving(self, entity, threshold)
92
95
  if threshold == nil then
93
96
  threshold = 0.01
package/dist/index.lua CHANGED
@@ -674,6 +674,14 @@ do
674
674
  end
675
675
  end
676
676
  end
677
+ do
678
+ local ____export = require("types.PickupDescription")
679
+ for ____exportKey, ____exportValue in pairs(____export) do
680
+ if ____exportKey ~= "default" then
681
+ ____exports[____exportKey] = ____exportValue
682
+ end
683
+ end
684
+ end
677
685
  do
678
686
  local ____export = require("types.PillEffectClass")
679
687
  for ____exportKey, ____exportValue in pairs(____export) do
@@ -0,0 +1,38 @@
1
+ /** Corresponds to the overlay frame number in "005.100_collectible.anm2". */
2
+ export declare enum CollectiblePedestalType {
3
+ /**
4
+ * Used for e.g. shop collectibles. In the "005.100_collectible.anm2" file, this is represented by
5
+ * the final frame.
6
+ */
7
+ NONE = -1,
8
+ /** The normal grey pedestal. */
9
+ NORMAL = 0,
10
+ /** From SlotVariant.FORTUNE_TELLING_MACHINE (3) */
11
+ FORTUNE_TELLING_MACHINE = 1,
12
+ /** From SlotVariant.BLOOD_DONATION_MACHINE (2) */
13
+ BLOOD_DONATION_MACHINE = 2,
14
+ /** From SlotVariant.SLOT_MACHINE (1) */
15
+ SLOT_MACHINE = 3,
16
+ /** From PickupVariant.LOCKEDCHEST (60) */
17
+ LOCKEDCHEST = 4,
18
+ /** From PickupVariant.PICKUP_REDCHEST (360) */
19
+ REDCHEST = 5,
20
+ /** From PickupVariant.PICKUP_BOMBCHEST (51) */
21
+ BOMBCHEST = 6,
22
+ /** From PickupVariant.PICKUP_SPIKEDCHEST (52) */
23
+ SPIKEDCHEST = 7,
24
+ /** From PickupVariant.PICKUP_ETERNALCHEST (53) */
25
+ ETERNALCHEST = 8,
26
+ /** From SlotVariant.MOMS_DRESSING_TABLE (12) */
27
+ MOMS_DRESSING_TABLE = 9,
28
+ /** From PickupVariant.PICKUP_CHEST (50) */
29
+ CHEST = 10,
30
+ /** From PickupVariant.PICKUP_MOMSCHEST (390) */
31
+ MOMSCHEST = 11,
32
+ /** From PickupVariant.PICKUP_OLDCHEST (55) */
33
+ OLDCHEST = 12,
34
+ /** From PickupVariant.PICKUP_WOODENCHEST (56) */
35
+ WOODENCHEST = 13,
36
+ /** From PickupVariant.PICKUP_MEGACHEST (57) */
37
+ MEGACHEST = 14
38
+ }
@@ -0,0 +1,36 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____exports = {}
3
+ ____exports.CollectiblePedestalType = CollectiblePedestalType or ({})
4
+ ____exports.CollectiblePedestalType.NONE = -1
5
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.NONE] = "NONE"
6
+ ____exports.CollectiblePedestalType.NORMAL = 0
7
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.NORMAL] = "NORMAL"
8
+ ____exports.CollectiblePedestalType.FORTUNE_TELLING_MACHINE = 1
9
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.FORTUNE_TELLING_MACHINE] = "FORTUNE_TELLING_MACHINE"
10
+ ____exports.CollectiblePedestalType.BLOOD_DONATION_MACHINE = 2
11
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.BLOOD_DONATION_MACHINE] = "BLOOD_DONATION_MACHINE"
12
+ ____exports.CollectiblePedestalType.SLOT_MACHINE = 3
13
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.SLOT_MACHINE] = "SLOT_MACHINE"
14
+ ____exports.CollectiblePedestalType.LOCKEDCHEST = 4
15
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.LOCKEDCHEST] = "LOCKEDCHEST"
16
+ ____exports.CollectiblePedestalType.REDCHEST = 5
17
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.REDCHEST] = "REDCHEST"
18
+ ____exports.CollectiblePedestalType.BOMBCHEST = 6
19
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.BOMBCHEST] = "BOMBCHEST"
20
+ ____exports.CollectiblePedestalType.SPIKEDCHEST = 7
21
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.SPIKEDCHEST] = "SPIKEDCHEST"
22
+ ____exports.CollectiblePedestalType.ETERNALCHEST = 8
23
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.ETERNALCHEST] = "ETERNALCHEST"
24
+ ____exports.CollectiblePedestalType.MOMS_DRESSING_TABLE = 9
25
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.MOMS_DRESSING_TABLE] = "MOMS_DRESSING_TABLE"
26
+ ____exports.CollectiblePedestalType.CHEST = 10
27
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.CHEST] = "CHEST"
28
+ ____exports.CollectiblePedestalType.MOMSCHEST = 11
29
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.MOMSCHEST] = "MOMSCHEST"
30
+ ____exports.CollectiblePedestalType.OLDCHEST = 12
31
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.OLDCHEST] = "OLDCHEST"
32
+ ____exports.CollectiblePedestalType.WOODENCHEST = 13
33
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.WOODENCHEST] = "WOODENCHEST"
34
+ ____exports.CollectiblePedestalType.MEGACHEST = 14
35
+ ____exports.CollectiblePedestalType[____exports.CollectiblePedestalType.MEGACHEST] = "MEGACHEST"
36
+ return ____exports
@@ -7,3 +7,4 @@ export interface PickupDescription {
7
7
  price: int;
8
8
  initSeed: int;
9
9
  }
10
+ export declare function getPickupDescription(pickup: EntityPickup): PickupDescription;
@@ -1,3 +1,13 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____exports = {}
3
+ function ____exports.getPickupDescription(self, pickup)
4
+ return {
5
+ variant = pickup.Variant,
6
+ subType = pickup.SubType,
7
+ position = pickup.Position,
8
+ velocity = pickup.Velocity,
9
+ price = pickup.Price,
10
+ initSeed = pickup.InitSeed
11
+ }
12
+ end
3
13
  return ____exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.108",
3
+ "version": "1.2.109",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",