isaacscript-common 1.2.71 → 1.2.74

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.
@@ -11,6 +11,8 @@ local ____exports = {}
11
11
  local ____random = require("functions.random")
12
12
  local getRandomInt = ____random.getRandomInt
13
13
  local nextSeed = ____random.nextSeed
14
+ local ____utils = require("functions.utils")
15
+ local ____repeat = ____utils["repeat"]
14
16
  function ____exports.shuffleArrayInPlace(self, array, seed)
15
17
  if seed == nil then
16
18
  seed = Random()
@@ -66,13 +68,13 @@ function ____exports.arrayEquals(self, array1, array2)
66
68
  end
67
69
  function ____exports.initArray(self, defaultValue, size)
68
70
  local array = {}
69
- do
70
- local i = 0
71
- while i < size do
71
+ ____repeat(
72
+ nil,
73
+ size,
74
+ function()
72
75
  __TS__ArrayPush(array, defaultValue)
73
- i = i + 1
74
76
  end
75
- end
77
+ )
76
78
  return array
77
79
  end
78
80
  function ____exports.isArrayInArray(self, arrayToMatch, parentArray)
@@ -15,6 +15,7 @@ local ____set = require("functions.set")
15
15
  local copySet = ____set.copySet
16
16
  local ____utils = require("functions.utils")
17
17
  local getEnumValues = ____utils.getEnumValues
18
+ local ____repeat = ____utils["repeat"]
18
19
  local CACHE_FLAG_TO_COLLECTIBLES_MAP = __TS__New(Map)
19
20
  local function initCacheFlagMap(self)
20
21
  local maxCollectibleType = getMaxCollectibleType(nil)
@@ -43,13 +44,13 @@ function ____exports.getPlayerCollectiblesForCacheFlag(self, player, cacheFlag)
43
44
  local playerCollectibles = {}
44
45
  for ____, collectibleType in __TS__Iterator(collectiblesForCacheFlag:values()) do
45
46
  local numCollectibles = player:GetCollectibleNum(collectibleType)
46
- do
47
- local i = 0
48
- while i < numCollectibles do
47
+ ____repeat(
48
+ nil,
49
+ numCollectibles,
50
+ function()
49
51
  __TS__ArrayPush(playerCollectibles, collectibleType)
50
- i = i + 1
51
52
  end
52
- end
53
+ )
53
54
  end
54
55
  return playerCollectibles
55
56
  end
@@ -12,6 +12,8 @@ local STORY_BOSSES = ____constants.STORY_BOSSES
12
12
  local ____random = require("functions.random")
13
13
  local getRandom = ____random.getRandom
14
14
  local nextSeed = ____random.nextSeed
15
+ local ____utils = require("functions.utils")
16
+ local ____repeat = ____utils["repeat"]
15
17
  function ____exports.getEntities(self, matchingEntityType, matchingVariant, matchingSubType, ignoreFriendly)
16
18
  if matchingVariant == nil then
17
19
  matchingVariant = -1
@@ -227,16 +229,11 @@ function ____exports.removeEntities(self, entities, cap)
227
229
  return false
228
230
  end
229
231
  local numEntitiesRemoved = 0
230
- do
231
- local i = 0
232
- while i < #entities do
233
- local entity = entities[i + 1]
234
- entity:Remove()
235
- numEntitiesRemoved = numEntitiesRemoved + 1
236
- if cap ~= nil and numEntitiesRemoved >= cap then
237
- return true
238
- end
239
- i = i + 1
232
+ for ____, entity in ipairs(entities) do
233
+ entity:Remove()
234
+ numEntitiesRemoved = numEntitiesRemoved + 1
235
+ if cap ~= nil and numEntitiesRemoved >= cap then
236
+ return true
240
237
  end
241
238
  end
242
239
  return true
@@ -311,15 +308,15 @@ end
311
308
  function ____exports.setEntityRandomColor(self, entity)
312
309
  local colorValues = {}
313
310
  local seed = entity.InitSeed
314
- do
315
- local i = 0
316
- while i < 3 do
311
+ ____repeat(
312
+ nil,
313
+ 3,
314
+ function()
317
315
  seed = nextSeed(nil, seed)
318
316
  local randomColorValue = getRandom(nil, seed)
319
317
  __TS__ArrayPush(colorValues, randomColorValue)
320
- i = i + 1
321
318
  end
322
- end
319
+ )
323
320
  local color = Color(colorValues[1], colorValues[2], colorValues[3])
324
321
  entity:SetColor(
325
322
  color,
@@ -8,6 +8,8 @@ local FAMILIARS_THAT_SHOOT_PLAYER_TEARS = ____constants.FAMILIARS_THAT_SHOOT_PLA
8
8
  local ____entity = require("functions.entity")
9
9
  local getEntities = ____entity.getEntities
10
10
  local removeEntities = ____entity.removeEntities
11
+ local ____utils = require("functions.utils")
12
+ local ____repeat = ____utils["repeat"]
11
13
  function ____exports.getFamiliars(self, matchingVariant, matchingSubType)
12
14
  if matchingVariant == nil then
13
15
  matchingVariant = -1
@@ -52,9 +54,10 @@ function ____exports.checkFamiliar(self, player, collectibleType, numTargetFamil
52
54
  local numFamiliarsToSpawn = numTargetFamiliars - #familiarsForThisPlayer
53
55
  local collectibleRNG = player:GetCollectibleRNG(collectibleType)
54
56
  local familiarSubTypeToUse = familiarSubType == nil and 0 or familiarSubType
55
- do
56
- local i = 0
57
- while i < numFamiliarsToSpawn do
57
+ ____repeat(
58
+ nil,
59
+ numFamiliarsToSpawn,
60
+ function()
58
61
  collectibleRNG:Next()
59
62
  local familiar = game:Spawn(
60
63
  EntityType.ENTITY_FAMILIAR,
@@ -68,9 +71,8 @@ function ____exports.checkFamiliar(self, player, collectibleType, numTargetFamil
68
71
  if familiar ~= nil then
69
72
  familiar.Player = player
70
73
  end
71
- i = i + 1
72
74
  end
73
- end
75
+ )
74
76
  return numFamiliarsToSpawn
75
77
  end
76
78
  function ____exports.checkFamiliarFromCollectibles(self, player, collectibleType, familiarVariant, familiarSubType)
@@ -39,6 +39,15 @@ export declare function getSurroundingGridEntities(gridEntity: GridEntity): Grid
39
39
  * Returns true if there are no pressure plates in the room.
40
40
  */
41
41
  export declare function isAllPressurePlatesPushed(): boolean;
42
+ export declare function isGridEntityBreakableByExplosion(gridEntity: GridEntity): boolean;
43
+ /**
44
+ * Helper function to see if the provided gridEntity is in its respective broken state. See the
45
+ * `GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP` constant for more details.
46
+ *
47
+ * Note that in the case of `GridEntityType.GRID_LOCK` (11), the state will turn to being broken
48
+ * before the actual collision for the entity is removed.
49
+ */
50
+ export declare function isGridEntityBroken(gridEntity: GridEntity): boolean;
42
51
  /**
43
52
  * Helper function to detect whether a given Void Portal is one that randomly spawns after a boss is
44
53
  * defeated or is one that naturally spawns in the room after Hush. (This is determined by looking
@@ -1,13 +1,15 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____lualib = require("lualib_bundle")
3
- local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
4
3
  local Set = ____lualib.Set
5
4
  local __TS__New = ____lualib.__TS__New
5
+ local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
6
6
  local __TS__ArrayPush = ____lualib.__TS__ArrayPush
7
7
  local __TS__ArrayEvery = ____lualib.__TS__ArrayEvery
8
8
  local ____exports = {}
9
9
  local ____constants = require("constants")
10
10
  local DISTANCE_OF_GRID_TILE = ____constants.DISTANCE_OF_GRID_TILE
11
+ local ____gridEntityTypeToBrokenStateMap = require("maps.gridEntityTypeToBrokenStateMap")
12
+ local GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP = ____gridEntityTypeToBrokenStateMap.GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP
11
13
  local ____gridEntityXMLMap = require("maps.gridEntityXMLMap")
12
14
  local GRID_ENTITY_XML_MAP = ____gridEntityXMLMap.GRID_ENTITY_XML_MAP
13
15
  local ____roomShapeToTopLeftWallGridIndexMap = require("maps.roomShapeToTopLeftWallGridIndexMap")
@@ -61,6 +63,23 @@ function ____exports.spawnGridEntityWithVariant(self, gridEntityType, variant, g
61
63
  end
62
64
  return gridEntity
63
65
  end
66
+ local BREAKABLE_GRID_ENTITY_TYPES_BY_EXPLOSIONS = __TS__New(Set, {
67
+ GridEntityType.GRID_ROCK,
68
+ GridEntityType.GRID_ROCKT,
69
+ GridEntityType.GRID_ROCK_BOMB,
70
+ GridEntityType.GRID_ROCK_ALT,
71
+ GridEntityType.GRID_SPIDERWEB,
72
+ GridEntityType.GRID_TNT,
73
+ GridEntityType.GRID_POOP,
74
+ GridEntityType.GRID_ROCK_SS,
75
+ GridEntityType.GRID_ROCK_SPIKED,
76
+ GridEntityType.GRID_ROCK_ALT2,
77
+ GridEntityType.GRID_ROCK_GOLD
78
+ })
79
+ local BREAKABLE_GRID_ENTITY_TYPES_VARIANTS_BY_EXPLOSIONS = __TS__New(
80
+ Set,
81
+ {(tostring(GridEntityType.GRID_STATUE) .. ".") .. 1}
82
+ )
64
83
  function ____exports.convertXMLGridEntityType(self, gridEntityXMLType, gridEntityXMLVariant)
65
84
  if gridEntityXMLType == EntityType.ENTITY_TRIGGER_OUTPUT then
66
85
  return nil
@@ -167,6 +186,17 @@ function ____exports.isAllPressurePlatesPushed(self)
167
186
  end
168
187
  )
169
188
  end
189
+ function ____exports.isGridEntityBreakableByExplosion(self, gridEntity)
190
+ local gridEntityType = gridEntity:GetType()
191
+ local gridEntityVariant = gridEntity:GetVariant()
192
+ local gridEntityTypeVariant = (tostring(gridEntityType) .. ".") .. tostring(gridEntityVariant)
193
+ return BREAKABLE_GRID_ENTITY_TYPES_BY_EXPLOSIONS:has(gridEntityType) or BREAKABLE_GRID_ENTITY_TYPES_VARIANTS_BY_EXPLOSIONS:has(gridEntityTypeVariant)
194
+ end
195
+ function ____exports.isGridEntityBroken(self, gridEntity)
196
+ local gridEntityType = gridEntity:GetType()
197
+ local brokenState = GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP:get(gridEntityType)
198
+ return gridEntity.State == brokenState
199
+ end
170
200
  function ____exports.isPostBossVoidPortal(self, gridEntity)
171
201
  local saveState = gridEntity:GetSaveState()
172
202
  return saveState.VarData == 1
@@ -10,6 +10,8 @@ local ____collectibles = require("functions.collectibles")
10
10
  local getCollectibleName = ____collectibles.getCollectibleName
11
11
  local ____flag = require("functions.flag")
12
12
  local hasFlag = ____flag.hasFlag
13
+ local ____player = require("functions.player")
14
+ local getEffectsList = ____player.getEffectsList
13
15
  local ____trinkets = require("functions.trinkets")
14
16
  local getTrinketName = ____trinkets.getTrinketName
15
17
  function ____exports.getDebugPrependString(self, msg, numParentFunctions)
@@ -146,34 +148,27 @@ function ____exports.logTable(____table, parentTables)
146
148
  end
147
149
  end
148
150
  function ____exports.logTemporaryEffects(player)
149
- local effects = player:GetEffects()
150
- local effectsList = effects:GetEffectsList()
151
+ local effects = getEffectsList(nil, player)
151
152
  ____exports.log("Logging all player temporary effects:")
152
- if effectsList.Size == 0 then
153
+ if #effects == 0 then
153
154
  ____exports.log(" n/a (no temporary effects)")
154
155
  return
155
156
  end
156
157
  do
157
158
  local i = 0
158
- while i < effectsList.Size do
159
- do
160
- local effect = effectsList:Get(i)
161
- if effect == nil then
162
- goto __continue38
163
- end
164
- if effect.Item:IsCollectible() then
165
- local collectibleName = getCollectibleName(nil, effect.Item.ID)
166
- ____exports.log(((" " .. tostring(i + 1)) .. ") ") .. collectibleName)
167
- elseif effect.Item:IsTrinket() then
168
- local trinketName = getTrinketName(nil, effect.Item.ID)
169
- ____exports.log(((" " .. tostring(i + 1)) .. ") ") .. trinketName)
170
- elseif effect.Item:IsNull() then
171
- ____exports.log(((" " .. tostring(i + 1)) .. ") Null item: ") .. tostring(effect.Item.ID))
172
- else
173
- ____exports.log(((" " .. tostring(i + 1)) .. ") Unknown type of temporary effect: ") .. tostring(effect.Item.ID))
174
- end
159
+ while i < #effects do
160
+ local effect = effects[i + 1]
161
+ if effect.Item:IsCollectible() then
162
+ local collectibleName = getCollectibleName(nil, effect.Item.ID)
163
+ ____exports.log(((" " .. tostring(i + 1)) .. ") ") .. collectibleName)
164
+ elseif effect.Item:IsTrinket() then
165
+ local trinketName = getTrinketName(nil, effect.Item.ID)
166
+ ____exports.log(((" " .. tostring(i + 1)) .. ") ") .. trinketName)
167
+ elseif effect.Item:IsNull() then
168
+ ____exports.log(((" " .. tostring(i + 1)) .. ") Null item: ") .. tostring(effect.Item.ID))
169
+ else
170
+ ____exports.log(((" " .. tostring(i + 1)) .. ") Unknown type of temporary effect: ") .. tostring(effect.Item.ID))
175
171
  end
176
- ::__continue38::
177
172
  i = i + 1
178
173
  end
179
174
  end
@@ -67,6 +67,11 @@ export declare function getClosestPlayer(position: Vector): EntityPlayer;
67
67
  * Tainted Forgotten have a 20 frame death animation (i.e. the "ForgottenDeath" animation).
68
68
  */
69
69
  export declare function getDeathAnimationName(player: EntityPlayer): string;
70
+ /**
71
+ * Helper function to get an array of temporary effects for a player. This is helpful so that you
72
+ * don't have to manually create an array from an `EffectsList` object.
73
+ */
74
+ export declare function getEffectsList(player: EntityPlayer): TemporaryEffect[];
70
75
  /**
71
76
  * Helper function to return the player with the highest ID, according to the `Isaac.GetPlayer()`
72
77
  * method.
@@ -4,10 +4,10 @@ local Set = ____lualib.Set
4
4
  local __TS__New = ____lualib.__TS__New
5
5
  local __TS__ArraySome = ____lualib.__TS__ArraySome
6
6
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
7
+ local __TS__ArrayPush = ____lualib.__TS__ArrayPush
7
8
  local __TS__ArrayFind = ____lualib.__TS__ArrayFind
8
9
  local Map = ____lualib.Map
9
10
  local __TS__Iterator = ____lualib.__TS__Iterator
10
- local __TS__ArrayPush = ____lualib.__TS__ArrayPush
11
11
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
12
12
  local ____exports = {}
13
13
  local getPlayerIndexCollectibleType, getAdjustedPlayerName, isTaintedModded, DEFAULT_COLLECTIBLE_TYPE, EXCLUDED_CHARACTERS
@@ -74,15 +74,15 @@ end
74
74
  function getPlayerIndexCollectibleType(self, player, differentiateForgottenAndSoul)
75
75
  local character = player:GetPlayerType()
76
76
  repeat
77
- local ____switch59 = character
78
- local ____cond59 = ____switch59 == PlayerType.PLAYER_THESOUL
79
- if ____cond59 then
77
+ local ____switch62 = character
78
+ local ____cond62 = ____switch62 == PlayerType.PLAYER_THESOUL
79
+ if ____cond62 then
80
80
  do
81
81
  return differentiateForgottenAndSoul and CollectibleType.COLLECTIBLE_SPOON_BENDER or DEFAULT_COLLECTIBLE_TYPE
82
82
  end
83
83
  end
84
- ____cond59 = ____cond59 or ____switch59 == PlayerType.PLAYER_LAZARUS2_B
85
- if ____cond59 then
84
+ ____cond62 = ____cond62 or ____switch62 == PlayerType.PLAYER_LAZARUS2_B
85
+ if ____cond62 then
86
86
  do
87
87
  return CollectibleType.COLLECTIBLE_INNER_EYE
88
88
  end
@@ -110,39 +110,39 @@ end
110
110
  function getAdjustedPlayerName(self, player)
111
111
  local character = player:GetPlayerType()
112
112
  repeat
113
- local ____switch72 = character
114
- local ____cond72 = ____switch72 == PlayerType.PLAYER_BLUEBABY or ____switch72 == PlayerType.PLAYER_BLUEBABY_B
115
- if ____cond72 then
113
+ local ____switch75 = character
114
+ local ____cond75 = ____switch75 == PlayerType.PLAYER_BLUEBABY or ____switch75 == PlayerType.PLAYER_BLUEBABY_B
115
+ if ____cond75 then
116
116
  do
117
117
  return "Blue Baby"
118
118
  end
119
119
  end
120
- ____cond72 = ____cond72 or ____switch72 == PlayerType.PLAYER_LAZARUS2
121
- if ____cond72 then
120
+ ____cond75 = ____cond75 or ____switch75 == PlayerType.PLAYER_LAZARUS2
121
+ if ____cond75 then
122
122
  do
123
123
  return "Lazarus II"
124
124
  end
125
125
  end
126
- ____cond72 = ____cond72 or ____switch72 == PlayerType.PLAYER_BLACKJUDAS
127
- if ____cond72 then
126
+ ____cond75 = ____cond75 or ____switch75 == PlayerType.PLAYER_BLACKJUDAS
127
+ if ____cond75 then
128
128
  do
129
129
  return "Dark Judas"
130
130
  end
131
131
  end
132
- ____cond72 = ____cond72 or ____switch72 == PlayerType.PLAYER_JACOB
133
- if ____cond72 then
132
+ ____cond75 = ____cond75 or ____switch75 == PlayerType.PLAYER_JACOB
133
+ if ____cond75 then
134
134
  do
135
135
  return "Jacob & Esau"
136
136
  end
137
137
  end
138
- ____cond72 = ____cond72 or ____switch72 == PlayerType.PLAYER_LAZARUS2_B
139
- if ____cond72 then
138
+ ____cond75 = ____cond75 or ____switch75 == PlayerType.PLAYER_LAZARUS2_B
139
+ if ____cond75 then
140
140
  do
141
141
  return "Dead Tainted Lazarus"
142
142
  end
143
143
  end
144
- ____cond72 = ____cond72 or ____switch72 == PlayerType.PLAYER_JACOB2_B
145
- if ____cond72 then
144
+ ____cond75 = ____cond75 or ____switch75 == PlayerType.PLAYER_JACOB2_B
145
+ if ____cond75 then
146
146
  do
147
147
  return "Dead Tainted Jacob"
148
148
  end
@@ -159,22 +159,23 @@ function ____exports.getPlayers(self, performExclusions)
159
159
  performExclusions = false
160
160
  end
161
161
  local game = Game()
162
+ local numPlayers = game:GetNumPlayers()
162
163
  local players = {}
163
164
  do
164
165
  local i = 0
165
- while i < game:GetNumPlayers() do
166
+ while i < numPlayers do
166
167
  do
167
168
  local player = Isaac.GetPlayer(i)
168
169
  if ____exports.isChildPlayer(nil, player) then
169
- goto __continue82
170
+ goto __continue85
170
171
  end
171
172
  local character = player:GetPlayerType()
172
173
  if performExclusions and EXCLUDED_CHARACTERS:has(character) then
173
- goto __continue82
174
+ goto __continue85
174
175
  end
175
176
  __TS__ArrayPush(players, player)
176
177
  end
177
- ::__continue82::
178
+ ::__continue85::
178
179
  i = i + 1
179
180
  end
180
181
  end
@@ -311,6 +312,22 @@ function ____exports.getDeathAnimationName(self, player)
311
312
  end
312
313
  return "Death"
313
314
  end
315
+ function ____exports.getEffectsList(self, player)
316
+ local effects = player:GetEffects()
317
+ local effectsList = effects:GetEffectsList()
318
+ local effectArray = {}
319
+ do
320
+ local i = 0
321
+ while i < effectsList.Size do
322
+ local effect = effectsList:Get(i)
323
+ if effect ~= nil then
324
+ __TS__ArrayPush(effectArray, effect)
325
+ end
326
+ i = i + 1
327
+ end
328
+ end
329
+ return effectArray
330
+ end
314
331
  function ____exports.getFinalPlayer(self)
315
332
  local players = ____exports.getPlayers(nil)
316
333
  return players[#players]
@@ -408,10 +425,11 @@ function ____exports.getPlayerFromIndex(self, playerIndex)
408
425
  end
409
426
  function ____exports.getPlayerIndexVanilla(self, playerToFind)
410
427
  local game = Game()
428
+ local numPlayers = game:GetNumPlayers()
411
429
  local playerToFindHash = GetPtrHash(playerToFind)
412
430
  do
413
431
  local i = 0
414
- while i < game:GetNumPlayers() do
432
+ while i < numPlayers do
415
433
  local player = Isaac.GetPlayer(i)
416
434
  local playerHash = GetPtrHash(player)
417
435
  if playerHash == playerToFindHash then
@@ -548,9 +566,9 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
548
566
  itemPool:RemoveCollectible(collectibleType)
549
567
  end
550
568
  repeat
551
- local ____switch118 = activeSlot
552
- local ____cond118 = ____switch118 == ActiveSlot.SLOT_PRIMARY
553
- if ____cond118 then
569
+ local ____switch121 = activeSlot
570
+ local ____cond121 = ____switch121 == ActiveSlot.SLOT_PRIMARY
571
+ if ____cond121 then
554
572
  do
555
573
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
556
574
  player:RemoveCollectible(primaryCollectibleType)
@@ -559,8 +577,8 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
559
577
  break
560
578
  end
561
579
  end
562
- ____cond118 = ____cond118 or ____switch118 == ActiveSlot.SLOT_SECONDARY
563
- if ____cond118 then
580
+ ____cond121 = ____cond121 or ____switch121 == ActiveSlot.SLOT_SECONDARY
581
+ if ____cond121 then
564
582
  do
565
583
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
566
584
  player:RemoveCollectible(primaryCollectibleType)
@@ -575,16 +593,16 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
575
593
  break
576
594
  end
577
595
  end
578
- ____cond118 = ____cond118 or ____switch118 == ActiveSlot.SLOT_POCKET
579
- if ____cond118 then
596
+ ____cond121 = ____cond121 or ____switch121 == ActiveSlot.SLOT_POCKET
597
+ if ____cond121 then
580
598
  do
581
599
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
582
600
  player:SetActiveCharge(charge, activeSlot)
583
601
  break
584
602
  end
585
603
  end
586
- ____cond118 = ____cond118 or ____switch118 == ActiveSlot.SLOT_POCKET2
587
- if ____cond118 then
604
+ ____cond121 = ____cond121 or ____switch121 == ActiveSlot.SLOT_POCKET2
605
+ if ____cond121 then
588
606
  do
589
607
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
590
608
  break
@@ -7,6 +7,7 @@ local anyEntityCloserThan = ____entity.anyEntityCloserThan
7
7
  local getEffects = ____entity.getEffects
8
8
  local ____player = require("functions.player")
9
9
  local getPlayerCloserThan = ____player.getPlayerCloserThan
10
+ local MAX_FIND_FREE_POSITION_ATTEMPTS = 100
10
11
  function ____exports.findFreePosition(self, startingPosition, avoidActiveEntities)
11
12
  if avoidActiveEntities == nil then
12
13
  avoidActiveEntities = false
@@ -16,7 +17,7 @@ function ____exports.findFreePosition(self, startingPosition, avoidActiveEntitie
16
17
  local heavenDoors = getEffects(nil, EffectVariant.HEAVEN_LIGHT_DOOR, 0)
17
18
  do
18
19
  local i = 0
19
- while i < 100 do
20
+ while i < MAX_FIND_FREE_POSITION_ATTEMPTS do
20
21
  do
21
22
  local position = room:FindFreePickupSpawnPosition(startingPosition, i, avoidActiveEntities)
22
23
  local closePlayer = getPlayerCloserThan(nil, position, DISTANCE_OF_GRID_TILE)
@@ -10,13 +10,13 @@ local range = ____math.range
10
10
  local ____set = require("functions.set")
11
11
  local copySet = ____set.copySet
12
12
  local ____trinkets = require("functions.trinkets")
13
- local getMaxTrinketID = ____trinkets.getMaxTrinketID
13
+ local getMaxTrinketType = ____trinkets.getMaxTrinketType
14
14
  local trinketHasCacheFlag = ____trinkets.trinketHasCacheFlag
15
15
  local ____utils = require("functions.utils")
16
16
  local getEnumValues = ____utils.getEnumValues
17
17
  local CACHE_FLAG_TO_TRINKETS_MAP = __TS__New(Map)
18
18
  local function initCacheFlagMap(self)
19
- local maxTrinketID = getMaxTrinketID(nil)
19
+ local maxTrinketID = getMaxTrinketType(nil)
20
20
  for ____, cacheFlag in ipairs(getEnumValues(nil, CacheFlag)) do
21
21
  local trinketsSet = __TS__New(Set)
22
22
  for ____, trinketType in ipairs(range(nil, 1, maxTrinketID)) do
@@ -4,6 +4,8 @@ local ____constants = require("constants")
4
4
  local GOLDEN_TRINKET_SHIFT = ____constants.GOLDEN_TRINKET_SHIFT
5
5
  local ____player = require("functions.player")
6
6
  local useActiveItemTemp = ____player.useActiveItemTemp
7
+ local ____utils = require("functions.utils")
8
+ local ____repeat = ____utils["repeat"]
7
9
  function ____exports.temporarilyRemoveTrinket(self, player, trinketType)
8
10
  if not player:HasTrinket(trinketType) then
9
11
  return nil
@@ -52,14 +54,14 @@ function ____exports.giveTrinketsBack(self, player, trinketSituation)
52
54
  if trinket2 ~= TrinketType.TRINKET_NULL then
53
55
  player:TryRemoveTrinket(trinket2)
54
56
  end
55
- do
56
- local i = 0
57
- while i < trinketSituation.numSmeltedTrinkets do
57
+ ____repeat(
58
+ nil,
59
+ trinketSituation.numSmeltedTrinkets,
60
+ function()
58
61
  player:AddTrinket(trinketSituation.trinketTypeRemoved, false)
59
62
  useActiveItemTemp(nil, player, CollectibleType.COLLECTIBLE_SMELTER)
60
- i = i + 1
61
63
  end
62
- end
64
+ )
63
65
  if trinketSituation.trinket1 ~= TrinketType.TRINKET_NULL then
64
66
  player:AddTrinket(trinketSituation.trinket1, false)
65
67
  end
@@ -3,21 +3,20 @@ local ____lualib = require("lualib_bundle")
3
3
  local Set = ____lualib.Set
4
4
  local __TS__New = ____lualib.__TS__New
5
5
  local ____exports = {}
6
+ local ____math = require("functions.math")
7
+ local range = ____math.range
6
8
  local ____set = require("functions.set")
7
9
  local copySet = ____set.copySet
8
10
  local ____trinkets = require("functions.trinkets")
9
- local getMaxTrinketID = ____trinkets.getMaxTrinketID
11
+ local getMaxTrinketType = ____trinkets.getMaxTrinketType
10
12
  local TRINKET_SET = __TS__New(Set)
11
13
  local function initTrinketSet(self)
12
14
  local itemConfig = Isaac.GetItemConfig()
13
- do
14
- local trinketType = 1
15
- while trinketType <= getMaxTrinketID(nil) do
16
- local itemConfigTrinket = itemConfig:GetTrinket(trinketType)
17
- if itemConfigTrinket ~= nil then
18
- TRINKET_SET:add(trinketType)
19
- end
20
- trinketType = trinketType + 1
15
+ local maxTrinketID = getMaxTrinketType(nil)
16
+ for ____, trinketType in ipairs(range(nil, 1, maxTrinketID)) do
17
+ local itemConfigTrinket = itemConfig:GetTrinket(trinketType)
18
+ if itemConfigTrinket ~= nil then
19
+ TRINKET_SET:add(trinketType)
21
20
  end
22
21
  end
23
22
  end
@@ -1,5 +1,5 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
- export declare function getMaxTrinketID(): int;
2
+ export declare function getMaxTrinketType(): int;
3
3
  /**
4
4
  * Returns the slot number corresponding to where a trinket can be safely inserted.
5
5
  *
@@ -15,7 +15,9 @@ local useActiveItemTemp = ____player.useActiveItemTemp
15
15
  local ____trinketGive = require("functions.trinketGive")
16
16
  local giveTrinketsBack = ____trinketGive.giveTrinketsBack
17
17
  local temporarilyRemoveTrinkets = ____trinketGive.temporarilyRemoveTrinkets
18
- function ____exports.getMaxTrinketID(self)
18
+ local ____utils = require("functions.utils")
19
+ local ____repeat = ____utils["repeat"]
20
+ function ____exports.getMaxTrinketType(self)
19
21
  local itemConfig = Isaac.GetItemConfig()
20
22
  return itemConfig:GetTrinkets().Size - 1
21
23
  end
@@ -88,14 +90,14 @@ function ____exports.smeltTrinket(self, player, trinketType, numTrinkets)
88
90
  numTrinkets = 1
89
91
  end
90
92
  local trinketSituation = temporarilyRemoveTrinkets(nil, player)
91
- do
92
- local i = 0
93
- while i < numTrinkets do
93
+ ____repeat(
94
+ nil,
95
+ numTrinkets,
96
+ function()
94
97
  player:AddTrinket(trinketType)
95
98
  useActiveItemTemp(nil, player, CollectibleType.COLLECTIBLE_SMELTER)
96
- i = i + 1
97
99
  end
98
- end
100
+ )
99
101
  giveTrinketsBack(nil, player, trinketSituation)
100
102
  end
101
103
  function ____exports.trinketHasCacheFlag(self, trinketType, cacheFlag)
@@ -82,5 +82,21 @@ export declare function onSetSeed(): boolean;
82
82
  export declare function printConsole(msg: string): void;
83
83
  /**
84
84
  * Helper function to repeat code N times. This is faster to type and cleaner than using a for loop.
85
+ *
86
+ * Example:
87
+ * ```ts
88
+ * const player = Isaac.GetPlayer();
89
+ * repeat(10, () => {
90
+ * player.AddCollectible(CollectibleType.COLLECTIBLE_STEVEN);
91
+ * });
92
+ * ```
93
+ *
94
+ * The repeated function is passed the index of the iteration, if needed:
95
+ *
96
+ * ```ts
97
+ * repeat(3, (i) => {
98
+ * print(i); // Prints "0", "1", "2"
99
+ * });
100
+ * ```
85
101
  */
86
102
  export declare function repeat(n: int, func: (i: int) => void): void;
package/dist/index.d.ts CHANGED
@@ -61,14 +61,19 @@ export * from "./functions/trinketSet";
61
61
  export * from "./functions/ui";
62
62
  export * from "./functions/utils";
63
63
  export * from "./functions/vector";
64
+ export * from "./maps/cardDescriptionMap";
64
65
  export * from "./maps/cardNameMap";
66
+ export * from "./maps/challengeNameMap";
67
+ export * from "./maps/collectibleDescriptionMap";
65
68
  export * from "./maps/collectibleNameMap";
69
+ export * from "./maps/gridEntityTypeToBrokenStateMap";
66
70
  export * from "./maps/gridEntityXMLMap";
67
71
  export * from "./maps/pillEffectClassMap";
68
72
  export * from "./maps/pillEffectNameMap";
69
73
  export * from "./maps/pillEffectTypeMap";
70
74
  export * from "./maps/roomShapeToTopLeftWallGridIndexMap";
71
75
  export * from "./maps/transformationNameMap";
76
+ export * from "./maps/trinketDescriptionMap";
72
77
  export * from "./maps/trinketNameMap";
73
78
  export * from "./sets/cards";
74
79
  export * from "./types/AnyEntity";
package/dist/index.lua CHANGED
@@ -498,6 +498,14 @@ do
498
498
  end
499
499
  end
500
500
  end
501
+ do
502
+ local ____export = require("maps.cardDescriptionMap")
503
+ for ____exportKey, ____exportValue in pairs(____export) do
504
+ if ____exportKey ~= "default" then
505
+ ____exports[____exportKey] = ____exportValue
506
+ end
507
+ end
508
+ end
501
509
  do
502
510
  local ____export = require("maps.cardNameMap")
503
511
  for ____exportKey, ____exportValue in pairs(____export) do
@@ -506,6 +514,22 @@ do
506
514
  end
507
515
  end
508
516
  end
517
+ do
518
+ local ____export = require("maps.challengeNameMap")
519
+ for ____exportKey, ____exportValue in pairs(____export) do
520
+ if ____exportKey ~= "default" then
521
+ ____exports[____exportKey] = ____exportValue
522
+ end
523
+ end
524
+ end
525
+ do
526
+ local ____export = require("maps.collectibleDescriptionMap")
527
+ for ____exportKey, ____exportValue in pairs(____export) do
528
+ if ____exportKey ~= "default" then
529
+ ____exports[____exportKey] = ____exportValue
530
+ end
531
+ end
532
+ end
509
533
  do
510
534
  local ____export = require("maps.collectibleNameMap")
511
535
  for ____exportKey, ____exportValue in pairs(____export) do
@@ -514,6 +538,14 @@ do
514
538
  end
515
539
  end
516
540
  end
541
+ do
542
+ local ____export = require("maps.gridEntityTypeToBrokenStateMap")
543
+ for ____exportKey, ____exportValue in pairs(____export) do
544
+ if ____exportKey ~= "default" then
545
+ ____exports[____exportKey] = ____exportValue
546
+ end
547
+ end
548
+ end
517
549
  do
518
550
  local ____export = require("maps.gridEntityXMLMap")
519
551
  for ____exportKey, ____exportValue in pairs(____export) do
@@ -562,6 +594,14 @@ do
562
594
  end
563
595
  end
564
596
  end
597
+ do
598
+ local ____export = require("maps.trinketDescriptionMap")
599
+ for ____exportKey, ____exportValue in pairs(____export) do
600
+ if ____exportKey ~= "default" then
601
+ ____exports[____exportKey] = ____exportValue
602
+ end
603
+ end
604
+ end
565
605
  do
566
606
  local ____export = require("maps.trinketNameMap")
567
607
  for ____exportKey, ____exportValue in pairs(____export) do
@@ -0,0 +1,2 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ export declare const GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP: ReadonlyMap<GridEntityType, int>;
@@ -0,0 +1,20 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____lualib = require("lualib_bundle")
3
+ local Map = ____lualib.Map
4
+ local __TS__New = ____lualib.__TS__New
5
+ local ____exports = {}
6
+ ____exports.GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP = __TS__New(Map, {
7
+ {GridEntityType.GRID_ROCK, 2},
8
+ {GridEntityType.GRID_ROCKT, 2},
9
+ {GridEntityType.GRID_ROCK_BOMB, 2},
10
+ {GridEntityType.GRID_ROCK_ALT, 2},
11
+ {GridEntityType.GRID_SPIDERWEB, 1},
12
+ {GridEntityType.GRID_LOCK, 1},
13
+ {GridEntityType.GRID_TNT, 4},
14
+ {GridEntityType.GRID_POOP, 1000},
15
+ {GridEntityType.GRID_ROCK_SS, 2},
16
+ {GridEntityType.GRID_ROCK_SPIKED, 2},
17
+ {GridEntityType.GRID_ROCK_ALT2, 2},
18
+ {GridEntityType.GRID_ROCK_GOLD, 2}
19
+ })
20
+ return ____exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.71",
3
+ "version": "1.2.74",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "devDependencies": {
28
28
  "@zamiell/typescript-to-lua": "^1.4.0",
29
- "isaac-typescript-definitions": "^1.0.349",
29
+ "isaac-typescript-definitions": "^1.0.353",
30
30
  "isaacscript-lint": "^1.0.81",
31
31
  "isaacscript-tsconfig": "^1.1.8",
32
32
  "typedoc": "^0.22.12",