isaacscript-common 2.3.1 → 3.1.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.
Files changed (327) hide show
  1. package/cachedClasses.d.ts +6 -4
  2. package/cachedClasses.lua +24 -0
  3. package/callbacks/customRevive.lua +2 -0
  4. package/callbacks/itemPickup.lua +2 -0
  5. package/callbacks/postBombInitLate.lua +2 -0
  6. package/callbacks/postBoneSwing.lua +2 -0
  7. package/callbacks/postCollectibleInitFirst.lua +2 -0
  8. package/callbacks/postCursedTeleport.lua +2 -0
  9. package/callbacks/postCustomDoorEnter.lua +44 -0
  10. package/callbacks/postDoorRender.lua +2 -0
  11. package/callbacks/postDoorUpdate.lua +2 -0
  12. package/callbacks/postEffectInitLate.lua +2 -0
  13. package/callbacks/postEffectStateChanged.lua +2 -0
  14. package/callbacks/postEsauJr.lua +2 -0
  15. package/callbacks/postFamiliarInitLate.lua +2 -0
  16. package/callbacks/postFamiliarStateChanged.lua +2 -0
  17. package/callbacks/postFlip.lua +2 -0
  18. package/callbacks/postGreedModeWave.lua +2 -0
  19. package/callbacks/postGridEntity.lua +2 -0
  20. package/callbacks/postGridEntityCollision.lua +2 -0
  21. package/callbacks/postGridEntityRender.lua +2 -0
  22. package/callbacks/postHolyMantleRemoved.lua +2 -0
  23. package/callbacks/postKnifeInitLate.lua +2 -0
  24. package/callbacks/postLaserInitLate.lua +2 -0
  25. package/callbacks/postNPCInitLate.lua +2 -0
  26. package/callbacks/postNPCStateChanged.lua +2 -0
  27. package/callbacks/postNewRoomEarly.lua +2 -0
  28. package/callbacks/postPickupCollect.lua +2 -0
  29. package/callbacks/postPickupInitLate.lua +2 -0
  30. package/callbacks/postPickupStateChanged.lua +2 -0
  31. package/callbacks/postPitRender.lua +2 -0
  32. package/callbacks/postPitUpdate.lua +2 -0
  33. package/callbacks/postPlayerChangeHealth.lua +2 -0
  34. package/callbacks/postPlayerChangeType.lua +2 -0
  35. package/callbacks/postPlayerFatalDamage.lua +2 -0
  36. package/callbacks/postPlayerInitLate.lua +2 -0
  37. package/callbacks/postPlayerReordered.lua +2 -0
  38. package/callbacks/postPoopRender.lua +2 -0
  39. package/callbacks/postPoopUpdate.lua +2 -0
  40. package/callbacks/postPressurePlateRender.lua +2 -0
  41. package/callbacks/postPressurePlateUpdate.lua +2 -0
  42. package/callbacks/postProjectileInitLate.lua +2 -0
  43. package/callbacks/postPurchase.lua +2 -0
  44. package/callbacks/postRockRender.lua +2 -0
  45. package/callbacks/postRockUpdate.lua +2 -0
  46. package/callbacks/postRoomClearChanged.lua +2 -0
  47. package/callbacks/postSacrifice.lua +2 -0
  48. package/callbacks/postSlotDestroyed.d.ts +1 -0
  49. package/callbacks/postSlotDestroyed.lua +66 -0
  50. package/callbacks/postSlotInitUpdate.lua +2 -0
  51. package/callbacks/postSlotRender.lua +5 -21
  52. package/callbacks/postSpikesRender.lua +2 -0
  53. package/callbacks/postSpikesUpdate.lua +2 -0
  54. package/callbacks/postTNTRender.lua +2 -0
  55. package/callbacks/postTNTUpdate.lua +2 -0
  56. package/callbacks/postTearInitLate.lua +2 -0
  57. package/callbacks/postTearInitVeryLate.lua +2 -0
  58. package/callbacks/postTransformation.lua +2 -0
  59. package/callbacks/postTrinketBreak.lua +2 -0
  60. package/callbacks/preBerserkDeath.lua +2 -0
  61. package/callbacks/preNewLevel.lua +2 -0
  62. package/callbacks/reorderedCallbacks.lua +16 -0
  63. package/callbacks/subscriptions/postBombInitLate.lua +6 -0
  64. package/callbacks/subscriptions/postBoneSwing.lua +6 -0
  65. package/callbacks/subscriptions/postCollectibleInitFirst.lua +6 -0
  66. package/callbacks/subscriptions/postCursedTeleport.lua +6 -0
  67. package/callbacks/subscriptions/postCustomDoorEnter.lua +6 -0
  68. package/callbacks/subscriptions/postCustomRevive.d.ts +1 -0
  69. package/callbacks/subscriptions/postCustomRevive.lua +6 -0
  70. package/callbacks/subscriptions/postDoorRender.d.ts +1 -0
  71. package/callbacks/subscriptions/postDoorRender.lua +6 -0
  72. package/callbacks/subscriptions/postDoorUpdate.d.ts +1 -0
  73. package/callbacks/subscriptions/postDoorUpdate.lua +6 -0
  74. package/callbacks/subscriptions/postEffectInitLate.lua +6 -0
  75. package/callbacks/subscriptions/postEffectStateChanged.lua +6 -0
  76. package/callbacks/subscriptions/postEsauJr.lua +6 -0
  77. package/callbacks/subscriptions/postFamiliarInitLate.lua +6 -0
  78. package/callbacks/subscriptions/postFamiliarStateChanged.lua +6 -0
  79. package/callbacks/subscriptions/postFirstEsauJr.lua +6 -0
  80. package/callbacks/subscriptions/postFirstFlip.lua +6 -0
  81. package/callbacks/subscriptions/postFlip.lua +6 -0
  82. package/callbacks/subscriptions/postGameStartedReordered.lua +6 -0
  83. package/callbacks/subscriptions/postGreedModeWave.lua +6 -0
  84. package/callbacks/subscriptions/postGridEntityBroken.lua +6 -0
  85. package/callbacks/subscriptions/postGridEntityCollision.lua +6 -0
  86. package/callbacks/subscriptions/postGridEntityInit.lua +6 -0
  87. package/callbacks/subscriptions/postGridEntityRemove.lua +6 -0
  88. package/callbacks/subscriptions/postGridEntityRender.lua +6 -0
  89. package/callbacks/subscriptions/postGridEntityStateChanged.lua +6 -0
  90. package/callbacks/subscriptions/postGridEntityUpdate.lua +6 -0
  91. package/callbacks/subscriptions/postHolyMantleRemoved.lua +6 -0
  92. package/callbacks/subscriptions/postItemDischarged.lua +6 -0
  93. package/callbacks/subscriptions/postItemPickup.lua +6 -0
  94. package/callbacks/subscriptions/postKnifeInitLate.lua +6 -0
  95. package/callbacks/subscriptions/postLaserInitLate.lua +6 -0
  96. package/callbacks/subscriptions/postNPCInitLate.lua +6 -0
  97. package/callbacks/subscriptions/postNPCStateChanged.lua +6 -0
  98. package/callbacks/subscriptions/postNewLevelReordered.lua +6 -0
  99. package/callbacks/subscriptions/postNewRoomEarly.lua +6 -0
  100. package/callbacks/subscriptions/postNewRoomReordered.lua +6 -0
  101. package/callbacks/subscriptions/postPEffectUpdateReordered.lua +6 -0
  102. package/callbacks/subscriptions/postPickupCollect.d.ts +1 -0
  103. package/callbacks/subscriptions/postPickupCollect.lua +6 -0
  104. package/callbacks/subscriptions/postPickupInitLate.lua +6 -0
  105. package/callbacks/subscriptions/postPickupStateChanged.d.ts +1 -0
  106. package/callbacks/subscriptions/postPickupStateChanged.lua +6 -0
  107. package/callbacks/subscriptions/postPitRender.d.ts +1 -0
  108. package/callbacks/subscriptions/postPitRender.lua +6 -0
  109. package/callbacks/subscriptions/postPitUpdate.d.ts +1 -0
  110. package/callbacks/subscriptions/postPitUpdate.lua +6 -0
  111. package/callbacks/subscriptions/postPlayerChangeHealth.lua +6 -0
  112. package/callbacks/subscriptions/postPlayerChangeType.lua +6 -0
  113. package/callbacks/subscriptions/postPlayerFatalDamage.lua +6 -0
  114. package/callbacks/subscriptions/postPlayerInitLate.lua +6 -0
  115. package/callbacks/subscriptions/postPlayerInitReordered.lua +6 -0
  116. package/callbacks/subscriptions/postPlayerRenderReordered.lua +6 -0
  117. package/callbacks/subscriptions/postPlayerUpdateReordered.lua +6 -0
  118. package/callbacks/subscriptions/postPoopRender.d.ts +1 -0
  119. package/callbacks/subscriptions/postPoopRender.lua +6 -0
  120. package/callbacks/subscriptions/postPoopUpdate.d.ts +1 -0
  121. package/callbacks/subscriptions/postPoopUpdate.lua +6 -0
  122. package/callbacks/subscriptions/postPressurePlateRender.d.ts +1 -0
  123. package/callbacks/subscriptions/postPressurePlateRender.lua +6 -0
  124. package/callbacks/subscriptions/postPressurePlateUpdate.d.ts +1 -0
  125. package/callbacks/subscriptions/postPressurePlateUpdate.lua +6 -0
  126. package/callbacks/subscriptions/postProjectileInitLate.lua +6 -0
  127. package/callbacks/subscriptions/postPurchase.lua +6 -0
  128. package/callbacks/subscriptions/postRockRender.d.ts +1 -0
  129. package/callbacks/subscriptions/postRockRender.lua +6 -0
  130. package/callbacks/subscriptions/postRockUpdate.d.ts +1 -0
  131. package/callbacks/subscriptions/postRockUpdate.lua +6 -0
  132. package/callbacks/subscriptions/postRoomClearChanged.lua +6 -0
  133. package/callbacks/subscriptions/postSacrifice.lua +6 -0
  134. package/callbacks/subscriptions/postSlotAnimationChanged.lua +6 -0
  135. package/callbacks/subscriptions/postSlotDestroyed.lua +6 -0
  136. package/callbacks/subscriptions/postSlotInit.lua +6 -0
  137. package/callbacks/subscriptions/postSlotRender.lua +6 -0
  138. package/callbacks/subscriptions/postSlotUpdate.lua +6 -0
  139. package/callbacks/subscriptions/postSpikesRender.d.ts +1 -0
  140. package/callbacks/subscriptions/postSpikesRender.lua +6 -0
  141. package/callbacks/subscriptions/postSpikesUpdate.d.ts +1 -0
  142. package/callbacks/subscriptions/postSpikesUpdate.lua +6 -0
  143. package/callbacks/subscriptions/postTNTRender.d.ts +1 -0
  144. package/callbacks/subscriptions/postTNTRender.lua +6 -0
  145. package/callbacks/subscriptions/postTNTUpdate.d.ts +1 -0
  146. package/callbacks/subscriptions/postTNTUpdate.lua +6 -0
  147. package/callbacks/subscriptions/postTearInitLate.lua +6 -0
  148. package/callbacks/subscriptions/postTearInitVeryLate.lua +6 -0
  149. package/callbacks/subscriptions/postTransformation.lua +6 -0
  150. package/callbacks/subscriptions/postTrinketBreak.lua +6 -0
  151. package/callbacks/subscriptions/preBerserkDeath.lua +6 -0
  152. package/callbacks/subscriptions/preCustomRevive.lua +6 -0
  153. package/callbacks/subscriptions/preItemPickup.lua +6 -0
  154. package/callbacks/subscriptions/preNewLevel.lua +6 -0
  155. package/classes/DefaultMap.d.ts +70 -39
  156. package/classes/DefaultMap.lua +94 -43
  157. package/classes/ModUpgraded.d.ts +3 -3
  158. package/classes/ModUpgraded.lua +5 -0
  159. package/constants.lua +41 -0
  160. package/constantsFirstLast.lua +63 -0
  161. package/enums/HealthType.lua +3 -0
  162. package/enums/ModCallbackCustom.d.ts +1 -1
  163. package/enums/ModCallbackCustom.lua +6 -0
  164. package/enums/private/CopyableIsaacAPIClassType.lua +1 -0
  165. package/enums/private/SerializationBrand.lua +5 -0
  166. package/features/characterHealthConversion.lua +6 -0
  167. package/features/characterStats.lua +17 -0
  168. package/features/debugDisplay/exports.d.ts +17 -0
  169. package/features/debugDisplay/exports.lua +90 -0
  170. package/features/debugDisplay/v.d.ts +17 -0
  171. package/features/deployJSONRoom.d.ts +1 -0
  172. package/features/deployJSONRoom.lua +56 -0
  173. package/features/disableInputs.lua +45 -0
  174. package/features/disableSound.lua +14 -0
  175. package/features/extraConsoleCommands/commandsDisplay.lua +90 -0
  176. package/features/extraConsoleCommands/init.lua +16 -0
  177. package/features/extraConsoleCommands/listCommands.lua +172 -0
  178. package/features/fadeInRemover.lua +10 -0
  179. package/features/fastReset.lua +10 -0
  180. package/features/forgottenSwitch.lua +4 -0
  181. package/features/getCollectibleItemPoolType.lua +5 -0
  182. package/features/playerInventory.lua +18 -0
  183. package/features/ponyDetection.lua +4 -0
  184. package/features/preventCollectibleRotation.lua +9 -0
  185. package/features/runInNFrames.lua +50 -0
  186. package/features/saveDataManager/constants.lua +1 -0
  187. package/features/saveDataManager/exports.lua +115 -0
  188. package/features/saveDataManager/load.lua +12 -8
  189. package/features/saveDataManager/main.lua +16 -3
  190. package/features/saveDataManager/maps.lua +3 -0
  191. package/features/saveDataManager/merge.lua +53 -21
  192. package/features/saveDataManager/save.lua +12 -7
  193. package/features/sirenHelpers.lua +13 -0
  194. package/features/taintedLazarusPlayers.lua +11 -0
  195. package/featuresInitialized.lua +6 -0
  196. package/functions/array.d.ts +2 -0
  197. package/functions/array.lua +85 -0
  198. package/functions/benchmark.lua +6 -0
  199. package/functions/boss.lua +35 -0
  200. package/functions/cacheFlag.lua +4 -0
  201. package/functions/cards.lua +60 -0
  202. package/functions/challenges.lua +1 -0
  203. package/functions/character.lua +23 -0
  204. package/functions/charge.lua +39 -0
  205. package/functions/chargeBar.d.ts +1 -0
  206. package/functions/chargeBar.lua +4 -0
  207. package/functions/collectibleCacheFlag.lua +15 -0
  208. package/functions/collectibleSet.lua +3 -0
  209. package/functions/collectibleTag.lua +9 -0
  210. package/functions/collectibles.d.ts +6 -1
  211. package/functions/collectibles.lua +146 -2
  212. package/functions/color.lua +18 -0
  213. package/functions/debug.lua +18 -0
  214. package/functions/deepCopy.lua +60 -26
  215. package/functions/deepCopyTests.lua +8 -5
  216. package/functions/direction.d.ts +1 -0
  217. package/functions/direction.lua +22 -0
  218. package/functions/doors.d.ts +1 -0
  219. package/functions/doors.lua +58 -0
  220. package/functions/entity.d.ts +4 -4
  221. package/functions/entity.lua +94 -6
  222. package/functions/entitySpecific.d.ts +20 -20
  223. package/functions/entitySpecific.lua +182 -0
  224. package/functions/entityTypes.d.ts +1 -1
  225. package/functions/entityTypes.lua +1 -0
  226. package/functions/enums.d.ts +2 -0
  227. package/functions/enums.lua +62 -0
  228. package/functions/familiars.lua +52 -0
  229. package/functions/flag.lua +77 -0
  230. package/functions/flying.lua +10 -0
  231. package/functions/globals.lua +8 -10
  232. package/functions/gridEntity.lua +105 -0
  233. package/functions/gridEntitySpecific.d.ts +5 -0
  234. package/functions/gridEntitySpecific.lua +8 -0
  235. package/functions/input.lua +11 -0
  236. package/functions/isaacAPIClass.d.ts +4 -4
  237. package/functions/isaacAPIClass.lua +15 -3
  238. package/functions/jsonHelpers.lua +11 -0
  239. package/functions/jsonRoom.d.ts +2 -0
  240. package/functions/jsonRoom.lua +5 -0
  241. package/functions/kColor.lua +9 -0
  242. package/functions/language.lua +5 -0
  243. package/functions/log.lua +31 -3
  244. package/functions/map.lua +18 -0
  245. package/functions/math.lua +26 -0
  246. package/functions/npc.lua +24 -0
  247. package/functions/pickupVariants.d.ts +11 -11
  248. package/functions/pickupVariants.lua +11 -0
  249. package/functions/pickups.d.ts +9 -9
  250. package/functions/pickups.lua +67 -0
  251. package/functions/pills.lua +45 -0
  252. package/functions/player.lua +166 -0
  253. package/functions/playerDataStructures.lua +65 -0
  254. package/functions/playerHealth.d.ts +1 -0
  255. package/functions/playerHealth.lua +10 -0
  256. package/functions/playerIndex.d.ts +2 -0
  257. package/functions/playerIndex.lua +47 -0
  258. package/functions/pocketItems.lua +18 -0
  259. package/functions/positionVelocity.d.ts +3 -0
  260. package/functions/positionVelocity.lua +46 -0
  261. package/functions/random.d.ts +2 -0
  262. package/functions/random.lua +32 -0
  263. package/functions/revive.d.ts +2 -0
  264. package/functions/revive.lua +15 -0
  265. package/functions/rng.d.ts +1 -0
  266. package/functions/rng.lua +19 -0
  267. package/functions/roomData.lua +68 -0
  268. package/functions/roomGrid.lua +21 -0
  269. package/functions/roomShape.lua +22 -0
  270. package/functions/rooms.lua +100 -0
  271. package/functions/run.lua +5 -0
  272. package/functions/seeds.lua +4 -0
  273. package/functions/serialization.lua +6 -2
  274. package/functions/set.d.ts +1 -0
  275. package/functions/set.lua +22 -0
  276. package/functions/spawnCollectible.lua +24 -0
  277. package/functions/sprite.d.ts +2 -0
  278. package/functions/sprite.lua +25 -0
  279. package/functions/stage.lua +16 -0
  280. package/functions/string.lua +6 -0
  281. package/functions/table.d.ts +12 -0
  282. package/functions/table.lua +53 -0
  283. package/functions/tears.d.ts +1 -0
  284. package/functions/tears.lua +12 -0
  285. package/functions/transformations.lua +18 -0
  286. package/functions/trinketCacheFlag.lua +3 -0
  287. package/functions/trinketGive.lua +24 -0
  288. package/functions/trinkets.lua +52 -0
  289. package/functions/tstlClass.d.ts +34 -0
  290. package/functions/tstlClass.lua +63 -9
  291. package/functions/ui.d.ts +2 -0
  292. package/functions/ui.lua +16 -0
  293. package/functions/utils.d.ts +16 -0
  294. package/functions/utils.lua +108 -0
  295. package/functions/vector.lua +13 -16
  296. package/index.d.ts +1 -0
  297. package/initCustomCallbacks.lua +3 -0
  298. package/interfaces/ChargeBarSprites.d.ts +1 -0
  299. package/interfaces/private/TSTLClassMetatable.d.ts +2 -0
  300. package/lualib_bundle.lua +21 -34
  301. package/maps/cardMap.lua +1 -0
  302. package/maps/characterMap.lua +1 -0
  303. package/maps/defaultPlayerStatMap.lua +1 -0
  304. package/maps/gridEntityXMLMap.lua +2 -0
  305. package/maps/pillEffectMap.lua +1 -0
  306. package/maps/roomShapeToTopLeftWallGridIndexMap.lua +2 -0
  307. package/maps/roomTypeMap.lua +1 -0
  308. package/objects/LRoomShapeToRectangles.lua +2 -0
  309. package/objects/colors.lua +4 -0
  310. package/objects/oppositeDoorSlots.d.ts +4 -0
  311. package/objects/oppositeDoorSlots.lua +15 -0
  312. package/objects/roomShapeBounds.lua +2 -0
  313. package/objects/roomShapeLayoutSizes.lua +4 -0
  314. package/objects/roomShapeToBottomRightPosition.lua +2 -0
  315. package/objects/roomShapeToDoorSlotsToGridIndexDelta.lua +2 -0
  316. package/objects/roomShapeToTopLeftPosition.lua +2 -0
  317. package/objects/roomShapeVolumes.lua +3 -0
  318. package/package.json +2 -2
  319. package/patchErrorFunctions.lua +8 -0
  320. package/sets/bossSets.lua +23 -0
  321. package/sets/charactersWithNoRedHeartsSet.lua +2 -0
  322. package/sets/charactersWithNoSoulHeartsSet.lua +2 -0
  323. package/sets/lostStyleCharactersSet.lua +2 -0
  324. package/types/AnyEntity.d.ts +10 -0
  325. package/types/PickingUpItem.lua +7 -0
  326. package/upgradeMod.d.ts +4 -4
  327. package/upgradeMod.lua +18 -0
@@ -68,6 +68,13 @@ local irange = ____utils.irange
68
68
  function ____exports.getRoomShapeNeighborGridIndexDeltas(self, roomShape)
69
69
  return {__TS__Spread(ROOM_SHAPE_TO_DOOR_SLOTS_TO_GRID_INDEX_DELTA[roomShape]:values())}
70
70
  end
71
+ --- Helper function to get the room descriptor for every room on the level. Uses the `Level.GetRooms`
72
+ -- method to accomplish this. Rooms without data are assumed to be non-existent and are not added to
73
+ -- the list.
74
+ --
75
+ -- @param includeExtraDimensionalRooms Optional. On some floors (e.g. Downpour 2, Mines 2),
76
+ -- extra-dimensional rooms are automatically be generated and can be
77
+ -- seen when you iterate over the `RoomList`. Default is false.
71
78
  function ____exports.getRooms(self, includeExtraDimensionalRooms)
72
79
  if includeExtraDimensionalRooms == nil then
73
80
  includeExtraDimensionalRooms = false
@@ -96,15 +103,21 @@ function ____exports.getRooms(self, includeExtraDimensionalRooms)
96
103
  end
97
104
  return {__TS__Spread(roomsMap:values())}
98
105
  end
106
+ --- We cannot use the standard code in the `inDimension` function for this purpose since it is bugged
107
+ -- with the Death Certificate area.
99
108
  function ____exports.inDeathCertificateArea(self)
100
109
  local roomStageID = getRoomStageID(nil)
101
110
  local roomSubType = getRoomSubType(nil)
102
111
  return roomStageID == StageID.HOME and (roomSubType == HomeRoomSubType.DEATH_CERTIFICATE_ENTRANCE or roomSubType == HomeRoomSubType.DEATH_CERTIFICATE_ITEMS)
103
112
  end
113
+ --- Helper function to check if a room exists at the given room grid index.
104
114
  function ____exports.roomExists(self, roomGridIndex)
105
115
  local roomData = getRoomData(nil, roomGridIndex)
106
116
  return roomData ~= nil
107
117
  end
118
+ --- Helper function for quickly switching to a new room without playing a particular animation. Use
119
+ -- this helper function over invoking the `Game.ChangeRoom` method directly to ensure that you do
120
+ -- not forget to set the `LeaveDoor` property and to prevent crashing on invalid room grid indexes.
108
121
  function ____exports.changeRoom(self, roomGridIndex)
109
122
  local level = game:GetLevel()
110
123
  local roomData = getRoomData(nil, roomGridIndex)
@@ -114,6 +127,7 @@ function ____exports.changeRoom(self, roomGridIndex)
114
127
  level.LeaveDoor = DoorSlot.NO_DOOR_SLOT
115
128
  game:ChangeRoom(roomGridIndex)
116
129
  end
130
+ --- Helper function to get an array with every valid `Dimension` (not including `Dimension.CURRENT`).
117
131
  function ____exports.getAllDimensions(self)
118
132
  return erange(nil, NUM_DIMENSIONS)
119
133
  end
@@ -124,6 +138,11 @@ function ____exports.getAllRoomGridIndexes(self)
124
138
  function(____, roomDescriptor) return roomDescriptor.SafeGridIndex end
125
139
  )
126
140
  end
141
+ --- Helper function to get the current dimension. Most of the time, this will be `Dimension.MAIN`,
142
+ -- but it can change if e.g. the player is in the mirror world of Downpour/Dross.
143
+ --
144
+ -- Note that this function correctly handles detecting the Death Certificate dimension, which is
145
+ -- tricky to properly detect.
127
146
  function ____exports.getCurrentDimension(self)
128
147
  local level = game:GetLevel()
129
148
  if ____exports.inDeathCertificateArea(nil) then
@@ -141,10 +160,19 @@ function ____exports.getCurrentDimension(self)
141
160
  end
142
161
  return error("Failed to get the current dimension using the starting room index of: " .. tostring(startingRoomGridIndex))
143
162
  end
163
+ --- Helper function to get the number of rooms that are currently on the floor layout. This does not
164
+ -- include off-grid rooms, like the Devil Room.
144
165
  function ____exports.getNumRooms(self)
145
166
  local rooms = ____exports.getRooms(nil)
146
167
  return #rooms
147
168
  end
169
+ --- Helper function to get an array of all of the safe grid indexes for rooms that match the
170
+ -- specified room type.
171
+ --
172
+ -- This function only searches through rooms in the current dimension.
173
+ --
174
+ -- This function is variadic, meaning that you can specify N arguments to get the combined grid
175
+ -- indexes for N room types.
148
176
  function ____exports.getRoomGridIndexesForType(self, ...)
149
177
  local roomTypesSet = __TS__New(Set, {...})
150
178
  local rooms = ____exports.getRooms(nil)
@@ -157,6 +185,8 @@ function ____exports.getRoomGridIndexesForType(self, ...)
157
185
  function(____, roomDescriptor) return roomDescriptor.SafeGridIndex end
158
186
  )
159
187
  end
188
+ --- Helper function to get the item pool type for the current room. For example, this returns
189
+ -- `ItemPoolType.ItemPoolType.POOL_ANGEL` if you are in an Angel Room.
160
190
  function ____exports.getRoomItemPoolType(self)
161
191
  local itemPool = game:GetItemPool()
162
192
  local room = game:GetRoom()
@@ -164,6 +194,9 @@ function ____exports.getRoomItemPoolType(self)
164
194
  local roomSeed = room:GetSpawnSeed()
165
195
  return itemPool:GetPoolForRoom(roomType, roomSeed)
166
196
  end
197
+ --- Helper function to get the grid indexes of all the rooms connected to the given room index.
198
+ --
199
+ -- @param roomGridIndex Optional. Default is the current room index.
167
200
  function ____exports.getRoomNeighbors(self, roomGridIndex)
168
201
  local roomDescriptor = getRoomDescriptor(nil, roomGridIndex)
169
202
  if roomDescriptor.SafeGridIndex < 0 or roomDescriptor.SafeGridIndex > MAX_LEVEL_GRID_INDEX then
@@ -184,10 +217,18 @@ function ____exports.getRoomNeighbors(self, roomGridIndex)
184
217
  function(____, gridIndex) return ____exports.roomExists(nil, gridIndex) end
185
218
  )
186
219
  end
220
+ --- Helper function to get the proper name of a room type.
221
+ --
222
+ -- For example, `RoomType.TREASURE` will return "Treasure Room".
187
223
  function ____exports.getRoomTypeName(self, roomType)
188
224
  local roomTypeName = ROOM_TYPE_NAMES[roomType]
189
225
  return roomTypeName == nil and DEFAULT_ROOM_TYPE_NAME or roomTypeName
190
226
  end
227
+ --- Helper function to get the room descriptor for every room on the level in a specific dimension.
228
+ -- Uses the `Level.GetRooms` method to accomplish this. Rooms without data are assumed to be
229
+ -- non-existent and are not added to the list.
230
+ --
231
+ -- @returns A map of room ListIndex to RoomDescriptor.
191
232
  function ____exports.getRoomsOfDimension(self, dimension)
192
233
  local level = game:GetLevel()
193
234
  local roomsMap = __TS__New(Map)
@@ -199,6 +240,8 @@ function ____exports.getRoomsOfDimension(self, dimension)
199
240
  end
200
241
  return {__TS__Spread(roomsMap:values())}
201
242
  end
243
+ --- Helper function to determine if the current room shape is equal to `RoomShape.1x2` or
244
+ -- `RoomShape.2x1`.
202
245
  function ____exports.in2x1Room(self)
203
246
  local room = game:GetRoom()
204
247
  local roomShape = room:GetRoomShape()
@@ -216,6 +259,8 @@ function ____exports.inBeastRoom(self)
216
259
  local roomSubType = getRoomSubType(nil)
217
260
  return roomType == RoomType.DUNGEON and roomSubType == DungeonSubType.BEAST_ROOM
218
261
  end
262
+ --- Helper function to check if the current room is a boss room for a particular boss. This will only
263
+ -- work for bosses that have dedicated boss rooms in the "00.special rooms.stb" file.
219
264
  function ____exports.inBossRoomOf(self, bossID)
220
265
  local room = game:GetRoom()
221
266
  local roomType = room:GetType()
@@ -223,12 +268,18 @@ function ____exports.inBossRoomOf(self, bossID)
223
268
  local roomSubType = getRoomSubType(nil)
224
269
  return roomType == RoomType.BOSS and roomStageID == StageID.SPECIAL_ROOMS and roomSubType == bossID
225
270
  end
271
+ --- Helper function for determining whether the current room is a crawlspace. Use this function over
272
+ -- comparing to `RoomType.DUNGEON` or `GridRoom.DUNGEON_IDX` since there is a special case of the
273
+ -- player being in a boss fight that take place in a dungeon.
226
274
  function ____exports.inCrawlspace(self)
227
275
  local room = game:GetRoom()
228
276
  local roomType = room:GetType()
229
277
  local roomSubType = getRoomSubType(nil)
230
278
  return roomType == RoomType.DUNGEON and roomSubType == DungeonSubType.NORMAL
231
279
  end
280
+ --- Helper function to detect if the current room is a Treasure Room created when entering with a
281
+ -- Devil's Crown trinket. Under the hood, this checks for the `RoomDescriptorFlag.DEVIL_TREASURE`
282
+ -- flag.
232
283
  function ____exports.inDevilsCrownTreasureRoom(self)
233
284
  local roomDescriptor = getCurrentRoomDescriptorReadOnly(nil)
234
285
  return hasFlag(nil, roomDescriptor.Flags, RoomDescriptorFlag.DEVIL_TREASURE)
@@ -246,6 +297,7 @@ function ____exports.inGenesisRoom(self)
246
297
  local roomGridIndex = getRoomGridIndex(nil)
247
298
  return roomGridIndex == GridRoom.GENESIS
248
299
  end
300
+ --- Helper function to determine if the current room shape is one of the four L room shapes.
249
301
  function ____exports.inLRoom(self)
250
302
  local room = game:GetRoom()
251
303
  local roomShape = room:GetRoomShape()
@@ -255,11 +307,15 @@ function ____exports.inMegaSatanRoom(self)
255
307
  local roomGridIndex = getRoomGridIndex(nil)
256
308
  return roomGridIndex == GridRoom.MEGA_SATAN
257
309
  end
310
+ --- Helper function to determine if the current room is part of the Repentance "escape sequence" in
311
+ -- the Mines/Ashpit.
258
312
  function ____exports.inMineShaft(self)
259
313
  local roomStageID = getRoomStageID(nil)
260
314
  local roomSubType = getRoomSubType(nil)
261
315
  return (roomStageID == StageID.MINES or roomStageID == StageID.ASHPIT) and MINE_SHAFT_ROOM_SUB_TYPE_SET:has(roomSubType)
262
316
  end
317
+ --- Helper function to check if the current room is a miniboss room for a particular miniboss. This
318
+ -- will only work for mini-bosses that have dedicated boss rooms in the "00.special rooms.stb" file.
263
319
  function ____exports.inMinibossRoomOf(self, minibossID)
264
320
  local room = game:GetRoom()
265
321
  local roomType = room:GetType()
@@ -267,16 +323,31 @@ function ____exports.inMinibossRoomOf(self, minibossID)
267
323
  local roomSubType = getRoomSubType(nil)
268
324
  return roomType == RoomType.MINI_BOSS and roomStageID == StageID.SPECIAL_ROOMS and roomSubType == minibossID
269
325
  end
326
+ --- Helper function for checking if the room is a secret shop (from the Member Card collectible).
327
+ --
328
+ -- Secret shops are simply copies of normal shops, but with the backdrop of a secret room. In other
329
+ -- words, they will have the same room type, room variant, and room sub-type of a normal shop. Thus,
330
+ -- the only way to detect them is by using the grid index.
270
331
  function ____exports.inSecretShop(self)
271
332
  local roomGridIndex = getRoomGridIndex(nil)
272
333
  return roomGridIndex == GridRoom.SECRET_SHOP
273
334
  end
335
+ --- Helper function to determine whether or not the current room is the starting room of a floor. It
336
+ -- only returns true for the starting room of the primary dimension (meaning that being in the
337
+ -- starting room of the mirror world does not count).
274
338
  function ____exports.inStartingRoom(self)
275
339
  local level = game:GetLevel()
276
340
  local startingRoomGridIndex = level:GetStartingRoomIndex()
277
341
  local roomGridIndex = getRoomGridIndex(nil)
278
342
  return roomGridIndex == startingRoomGridIndex and ____exports.inDimension(nil, Dimension.MAIN)
279
343
  end
344
+ --- Helper function to loop through every room on the floor and see if it has been cleared.
345
+ --
346
+ -- This function will only check rooms in the current dimension.
347
+ --
348
+ -- @param onlyCheckRoomTypes Optional. A whitelist of room types. If specified, room types not in
349
+ -- the array will be ignored. If not specified, then all rooms will be
350
+ -- checked. Undefined by default.
280
351
  function ____exports.isAllRoomsClear(self, onlyCheckRoomTypes)
281
352
  local ____temp_0
282
353
  if onlyCheckRoomTypes == nil then
@@ -315,21 +386,36 @@ function ____exports.isDoorSlotValidAtGridIndexForRedRoom(self, doorSlot, roomGr
315
386
  local redRoomGridIndex = roomGridIndex + delta
316
387
  return not ____exports.roomExists(nil, redRoomGridIndex) and redRoomGridIndex >= 0 and redRoomGridIndex <= MAX_LEVEL_GRID_INDEX
317
388
  end
389
+ --- Helper function to detect if the provided room was created by the Red Key item. Under the hood,
390
+ -- this checks for the `RoomDescriptorFlag.FLAG_RED_ROOM` flag.
391
+ --
392
+ -- @param roomGridIndex Optional. Default is the current room index.
318
393
  function ____exports.isRedKeyRoom(self, roomGridIndex)
319
394
  local roomDescriptor = getRoomDescriptor(nil, roomGridIndex)
320
395
  return hasFlag(nil, roomDescriptor.Flags, RoomDescriptorFlag.RED_ROOM)
321
396
  end
397
+ --- Helper function to determine if the provided room is part of the floor layout. For example, Devil
398
+ -- Rooms and the Mega Satan room are not considered to be inside the map.
399
+ --
400
+ -- @param roomGridIndex Optional. Default is the current room index.
322
401
  function ____exports.isRoomInsideMap(self, roomGridIndex)
323
402
  if roomGridIndex == nil then
324
403
  roomGridIndex = getRoomGridIndex(nil)
325
404
  end
326
405
  return roomGridIndex >= 0
327
406
  end
407
+ --- Helper function to get the coordinates of a given grid index. The floor is represented by a 13x13
408
+ -- grid. For example, since the starting room is in the center, the starting room grid index of 84
409
+ -- be equal to coordinates of (?, ?).
328
410
  function ____exports.roomGridIndexToXY(self, roomGridIndex)
329
411
  local x = roomGridIndex % LEVEL_GRID_ROW_WIDTH
330
412
  local y = math.floor(roomGridIndex / LEVEL_GRID_ROW_WIDTH)
331
413
  return {x, y}
332
414
  end
415
+ --- If the `Room.Update` method is called in a PostNewRoom callback, then some entities will slide
416
+ -- around (such as the player). Since those entity velocities are already at zero, setting them to
417
+ -- zero will have no effect. Thus, a generic solution is to record all of the entity
418
+ -- positions/velocities before updating the room, and then restore those positions/velocities.
333
419
  function ____exports.roomUpdateSafe(self)
334
420
  local room = game:GetRoom()
335
421
  local entities = getEntities(nil)
@@ -339,6 +425,9 @@ function ____exports.roomUpdateSafe(self)
339
425
  setEntityPositions(nil, entityPositions, entities)
340
426
  setEntityVelocities(nil, entityVelocities, entities)
341
427
  end
428
+ --- Helper function to convert an uncleared room to a cleared room in the PostNewRoom callback. This
429
+ -- is useful because if enemies are removed in this callback, a room drop will be awarded and the
430
+ -- doors will start closed and then open.
342
431
  function ____exports.setRoomCleared(self)
343
432
  local room = game:GetRoom()
344
433
  local roomClear = room:IsClear()
@@ -359,11 +448,22 @@ function ____exports.setRoomCleared(self)
359
448
  sfxManager:Stop(SoundEffect.DOOR_HEAVY_OPEN)
360
449
  game:ShakeScreen(0)
361
450
  end
451
+ --- Helper function to emulate what happens when you bomb an Angel Statue or push a Reward Plate that
452
+ -- spawns an NPC.
362
453
  function ____exports.setRoomUncleared(self)
363
454
  local room = game:GetRoom()
364
455
  room:SetClear(false)
365
456
  closeAllDoors(nil)
366
457
  end
458
+ --- Helper function to change the current room. It can be used for both teleportation and "normal"
459
+ -- room transitions, depending on what is passed for the `direction` and `roomTransitionAnim`
460
+ -- arguments. Use this function instead of invoking the `Game.StartRoomTransition` method directly
461
+ -- so that you do not forget to set `Level.LeaveDoor` property and to prevent crashing on invalid
462
+ -- room grid indexes.
463
+ --
464
+ -- @param roomGridIndex The room grid index of the destination room.
465
+ -- @param direction Optional. Default is `Direction.NO_DIRECTION`.
466
+ -- @param roomTransitionAnim Optional. Default is `RoomTransitionAnim.TELEPORT`.
367
467
  function ____exports.teleport(self, roomGridIndex, direction, roomTransitionAnim)
368
468
  if direction == nil then
369
469
  direction = Direction.NO_DIRECTION
package/functions/run.lua CHANGED
@@ -7,12 +7,17 @@ local ____constantsFirstLast = require("constantsFirstLast")
7
7
  local FIRST_CHARACTER = ____constantsFirstLast.FIRST_CHARACTER
8
8
  local ____log = require("functions.log")
9
9
  local log = ____log.log
10
+ --- Whether or not the player is playing on a set seed (i.e. that they entered in a specific seed by
11
+ -- pressing tab on the character selection screen). When the player resets the game on a set seed,
12
+ -- the game will not switch to a different seed.
10
13
  function ____exports.onSetSeed(self)
11
14
  local seeds = game:GetSeeds()
12
15
  local customRun = seeds:IsCustomRun()
13
16
  local challenge = Isaac.GetChallenge()
14
17
  return challenge == Challenge.NULL and customRun
15
18
  end
19
+ --- Helper function to restart the game using the console command of "restart". You can optionally
20
+ -- specify a `PlayerType` to restart the game as that character.
16
21
  function ____exports.restart(self, character)
17
22
  if character == nil then
18
23
  log("Restarting.")
@@ -3,10 +3,14 @@ local ____cachedClasses = require("cachedClasses")
3
3
  local game = ____cachedClasses.game
4
4
  local ____rng = require("functions.rng")
5
5
  local newRNG = ____rng.newRNG
6
+ --- Alias for the `Seeds.GetStartSeedString` method.
6
7
  function ____exports.getStartSeedString(self)
7
8
  local seeds = game:GetSeeds()
8
9
  return seeds:GetStartSeedString()
9
10
  end
11
+ --- Helper function to get the next seed value.
12
+ --
13
+ -- This function is useful when you are working with seed values directly over RNG objects.
10
14
  function ____exports.nextSeed(self, seed)
11
15
  local rng = newRNG(nil, seed)
12
16
  rng:Next()
@@ -13,7 +13,7 @@ local ISAAC_API_CLASS_TYPE_TO_COPY_FUNCTION = ____isaacAPIClassTypeToCopyFunctio
13
13
  local ____serializedIsaacAPIClassTypeToIdentityFunction = require("objects.serializedIsaacAPIClassTypeToIdentityFunction")
14
14
  local SERIALIZED_ISAAC_API_CLASS_TYPE_TO_IDENTITY_FUNCTION = ____serializedIsaacAPIClassTypeToIdentityFunction.SERIALIZED_ISAAC_API_CLASS_TYPE_TO_IDENTITY_FUNCTION
15
15
  local ____isaacAPIClass = require("functions.isaacAPIClass")
16
- local getIsaacAPIClassType = ____isaacAPIClass.getIsaacAPIClassType
16
+ local getIsaacAPIClassName = ____isaacAPIClass.getIsaacAPIClassName
17
17
  function getSerializedTableType(self, serializedIsaacAPIClass)
18
18
  for ____, ____value in ipairs(__TS__ObjectEntries(ISAAC_API_CLASS_TYPE_TO_BRAND)) do
19
19
  local copyableIsaacAPIClassType = ____value[1]
@@ -29,7 +29,7 @@ function ____exports.copyIsaacAPIClass(self, isaacAPIClass, serializationType)
29
29
  if objectType ~= "userdata" then
30
30
  error("Failed to copy an Isaac API class since the provided object was of type: " .. objectType)
31
31
  end
32
- local isaacAPIClassType = getIsaacAPIClassType(nil, isaacAPIClass)
32
+ local isaacAPIClassType = getIsaacAPIClassName(nil, isaacAPIClass)
33
33
  if isaacAPIClassType == nil then
34
34
  error("Failed to copy an Isaac API class since it does not have a class type.")
35
35
  end
@@ -40,6 +40,10 @@ function ____exports.copyIsaacAPIClass(self, isaacAPIClass, serializationType)
40
40
  end
41
41
  return copyFunction(nil, isaacAPIClass, serializationType)
42
42
  end
43
+ --- Deserialization is a special case, so we make a dedicated function for this.
44
+ --
45
+ -- There is no need for a corresponding "serializeIsaacAPIClass" function because the
46
+ -- "copyIsaacAPIClass" function can handles all serialization types.
43
47
  function ____exports.deserializeIsaacAPIClass(self, serializedIsaacAPIClass)
44
48
  local objectType = type(serializedIsaacAPIClass)
45
49
  if objectType ~= "table" then
@@ -1,4 +1,5 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /// <reference types="isaac-typescript-definitions" />
2
3
  /**
3
4
  * Helper function to add all of the values in one set to another set. The first set passed will be
4
5
  * modified in place.
package/functions/set.lua CHANGED
@@ -9,12 +9,20 @@ local ____array = require("functions.array")
9
9
  local getRandomArrayElement = ____array.getRandomArrayElement
10
10
  local ____rng = require("functions.rng")
11
11
  local getRandomSeed = ____rng.getRandomSeed
12
+ --- Helper function to get a sorted array based on the contents of a set.
13
+ --
14
+ -- Normally, set values are returned in a random order, so use this function when the ordering of
15
+ -- the contents is important.
12
16
  function ____exports.getSortedSetValues(self, set)
13
17
  local values = set:values()
14
18
  local array = {__TS__Spread(values)}
15
19
  __TS__ArraySort(array)
16
20
  return array
17
21
  end
22
+ --- Helper function to add all of the values in one set to another set. The first set passed will be
23
+ -- modified in place.
24
+ --
25
+ -- This function is variadic, meaning that you can specify N sets to add to the first set.
18
26
  function ____exports.addSetsToSet(self, mainSet, ...)
19
27
  local setsToAdd = {...}
20
28
  for ____, set in ipairs(setsToAdd) do
@@ -23,6 +31,9 @@ function ____exports.addSetsToSet(self, mainSet, ...)
23
31
  end
24
32
  end
25
33
  end
34
+ --- Helper function to create a new set that is the composition of two or more sets.
35
+ --
36
+ -- This function is variadic, meaning that you can specify N sets.
26
37
  function ____exports.combineSets(self, ...)
27
38
  local sets = {...}
28
39
  local newSet = __TS__New(Set)
@@ -33,6 +44,7 @@ function ____exports.combineSets(self, ...)
33
44
  end
34
45
  return newSet
35
46
  end
47
+ --- Helper function to copy a set. (You can also use a Set constructor to accomplish this task.)
36
48
  function ____exports.copySet(self, oldSet)
37
49
  local newSet = __TS__New(Set)
38
50
  for ____, value in __TS__Iterator(oldSet:values()) do
@@ -40,6 +52,10 @@ function ____exports.copySet(self, oldSet)
40
52
  end
41
53
  return newSet
42
54
  end
55
+ --- Helper function to delete all of the values in one set from another set. The first set passed
56
+ -- will be modified in place.
57
+ --
58
+ -- This function is variadic, meaning that you can specify N sets to remove from the first set.
43
59
  function ____exports.deleteSetsFromSet(self, mainSet, ...)
44
60
  local setsToRemove = {...}
45
61
  for ____, set in ipairs(setsToRemove) do
@@ -48,6 +64,12 @@ function ____exports.deleteSetsFromSet(self, mainSet, ...)
48
64
  end
49
65
  end
50
66
  end
67
+ --- Helper function to get a random element from the provided set.
68
+ --
69
+ -- @param set The set to get an element from.
70
+ -- @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
71
+ -- `RNG.Next` method will be called. Default is `getRandomSeed()`.
72
+ -- @param exceptions Optional. An array of elements to skip over if selected.
51
73
  function ____exports.getRandomSetElement(self, set, seedOrRNG, exceptions)
52
74
  if seedOrRNG == nil then
53
75
  seedOrRNG = getRandomSeed(nil)
@@ -20,6 +20,20 @@ local anyPlayerIs = ____player.anyPlayerIs
20
20
  local ____rng = require("functions.rng")
21
21
  local getRandomSeed = ____rng.getRandomSeed
22
22
  local isRNG = ____rng.isRNG
23
+ --- Helper function to spawn a collectible. Use this instead of the `Game.Spawn` method because it
24
+ -- handles the cases of Tainted Keeper collectibles costing coins and preventing quest items from
25
+ -- being rotated by Tainted Isaac's rotation mechanic. (Rotation prevention will only occur in
26
+ -- upgraded mods.)
27
+ --
28
+ -- @param collectibleType The collectible type to spawn.
29
+ -- @param position The position to spawn the collectible at.
30
+ -- @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
31
+ -- `RNG.Next` method will be called. Default is `getRandomSeed()`.
32
+ -- @param options Optional. Set to true to make the collectible a "There's Options" style
33
+ -- collectible. Default is false.
34
+ -- @param forceFreeItem Optional. Set to true to disable the logic that gives the item a price for
35
+ -- Tainted Keeper. Default is false.
36
+ -- @param spawner Optional.
23
37
  function ____exports.spawnCollectible(self, collectibleType, position, seedOrRNG, options, forceFreeItem, spawner)
24
38
  if seedOrRNG == nil then
25
39
  seedOrRNG = getRandomSeed(nil)
@@ -52,6 +66,16 @@ function ____exports.spawnCollectible(self, collectibleType, position, seedOrRNG
52
66
  end
53
67
  return collectible
54
68
  end
69
+ --- Helper function to spawn an empty collectible. Doing this is tricky since spawning a collectible
70
+ -- with `CollectibleType.NULL` will result in spawning a collectible with a random type from the
71
+ -- current room's item pool.
72
+ --
73
+ -- Instead, this function arbitrarily spawns a collectible with `CollectibleType.SAD_ONION`, and
74
+ -- then converts it to an empty pedestal afterward.
75
+ --
76
+ -- @param position The position to spawn the empty collectible at.
77
+ -- @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
78
+ -- `RNG.Next` method will be called. Default is `getRandomSeed()`.
55
79
  function ____exports.spawnEmptyCollectible(self, position, seedOrRNG)
56
80
  if seedOrRNG == nil then
57
81
  seedOrRNG = getRandomSeed(nil)
@@ -1,4 +1,6 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /// <reference types="isaac-typescript-definitions" />
3
+ /// <reference types="isaac-typescript-definitions" />
2
4
  /**
3
5
  * Helper function to clear a specific layer from a sprite.
4
6
  *
@@ -6,11 +6,22 @@ local ____kColor = require("functions.kColor")
6
6
  local kColorEquals = ____kColor.kColorEquals
7
7
  local ____utils = require("functions.utils")
8
8
  local erange = ____utils.erange
9
+ --- Helper function to check if two texels on a sprite are equivalent to each other.
9
10
  function ____exports.texelEquals(self, sprite1, sprite2, position, layerID)
10
11
  local kColor1 = sprite1:GetTexel(position, VectorZero, 1, layerID)
11
12
  local kColor2 = sprite2:GetTexel(position, VectorZero, 1, layerID)
12
13
  return kColorEquals(nil, kColor1, kColor2)
13
14
  end
15
+ --- Helper function to clear a specific layer from a sprite.
16
+ --
17
+ -- This function is variadic, so pass as many layer IDs as you want to clear. If no specific layers
18
+ -- are passed, it will clear every layer.
19
+ --
20
+ -- Since there is no official API method to "clear" a sprite, we can work around it by setting the
21
+ -- spritesheet to a non-existent or completely transparent file. If the path to the spritesheet does
22
+ -- not exist, then this function might cause spurious errors to appear in the "log.txt file". To
23
+ -- silence these errors, create a transparent 1 pixel PNG file in your mod's resources folder at the
24
+ -- path corresponding to the "EMPTY_PNG_PATH" constant.
14
25
  function ____exports.clearSprite(self, sprite, ...)
15
26
  local layerIDs = {...}
16
27
  if #layerIDs == 0 then
@@ -22,6 +33,15 @@ function ____exports.clearSprite(self, sprite, ...)
22
33
  end
23
34
  sprite:LoadGraphics()
24
35
  end
36
+ --- Helper function that returns the number of the final frame in a particular animation for a
37
+ -- sprite. By default, it will use the currently playing animation, but you can also specify a
38
+ -- specific animation to check.
39
+ --
40
+ -- Note that this function is bugged with the Stop Watch or the Broken Watch, since using the
41
+ -- `Sprite.SetFrame` method will reset the internal accumulator used to slow down the playback speed
42
+ -- of the animation. (The `PlaybackSpeed` property of the sprite is not used.) Thus, it is only safe
43
+ -- to use this function on animations that are not slowed down by Stop Watch or Broken Watch, such
44
+ -- as player animations.
25
45
  function ____exports.getLastFrameOfAnimation(self, sprite, animation)
26
46
  local currentAnimation = sprite:GetAnimation()
27
47
  local currentFrame = sprite:GetFrame()
@@ -36,6 +56,11 @@ function ____exports.getLastFrameOfAnimation(self, sprite, animation)
36
56
  sprite:SetFrame(currentFrame)
37
57
  return finalFrame
38
58
  end
59
+ --- Helper function to check if two sprite layers have the same sprite sheet by using the
60
+ -- `Sprite.GetTexel` method.
61
+ --
62
+ -- Since checking every single texel in the entire sprite is very expensive, this function requires
63
+ -- that you provide a range of specific texels to check.
39
64
  function ____exports.spriteEquals(self, sprite1, sprite2, layerID, xStart, xFinish, xIncrement, yStart, yFinish, yIncrement)
40
65
  do
41
66
  local x = xStart
@@ -14,9 +14,16 @@ function ____exports.onRepentanceStage(self)
14
14
  local stageType = level:GetStageType()
15
15
  return ____exports.isRepentanceStage(nil, stageType)
16
16
  end
17
+ --- Helper function to convert a numerical `StageType` into the letter suffix supplied to the "stage"
18
+ -- console command. For example, `StageType.REPENTANCE` is the stage type for Downpour, and the
19
+ -- console command to go to Downpour is "stage 1c", so this function converts `StageType.REPENTANCE`
20
+ -- to "c".
17
21
  function ____exports.stageTypeToLetter(self, stageType)
18
22
  return STAGE_TYPE_TO_LETTER[stageType]
19
23
  end
24
+ --- Helper function to account for Repentance floors being offset by 1. For example, Downpour 2 is
25
+ -- the third level of the run, but the game considers it to have a stage of 2. This function will
26
+ -- consider Downpour 2 to have a stage of 3.
20
27
  function ____exports.getEffectiveStage(self)
21
28
  local level = game:GetLevel()
22
29
  local stage = level:GetStage()
@@ -25,14 +32,17 @@ function ____exports.getEffectiveStage(self)
25
32
  end
26
33
  return stage
27
34
  end
35
+ --- Alias for the `Level.GetStage` method.
28
36
  function ____exports.getStage(self)
29
37
  local level = game:GetLevel()
30
38
  return level:GetStage()
31
39
  end
40
+ --- Alias for the `Level.GetStageType` method.
32
41
  function ____exports.getStageType(self)
33
42
  local level = game:GetLevel()
34
43
  return level:GetStageType()
35
44
  end
45
+ --- Helper function to directly warp to a specific stage using the "stage" console command.
36
46
  function ____exports.goToStage(self, stage, stageType)
37
47
  local stageTypeLetterSuffix = ____exports.stageTypeToLetter(nil, stageType)
38
48
  local command = ("stage " .. tostring(stage)) .. stageTypeLetterSuffix
@@ -56,6 +66,12 @@ function ____exports.onDarkRoom(self)
56
66
  local stageType = level:GetStageType()
57
67
  return stage == LevelStage.DARK_ROOM_CHEST and stageType == StageType.ORIGINAL
58
68
  end
69
+ --- Returns whether or not the player is on the "final floor" of the particular run. The final floor
70
+ -- is defined as one that prevents the player from entering the I AM ERROR room on.
71
+ --
72
+ -- For example, when using Undefined on The Chest, it has a 50% chance of teleporting the player to
73
+ -- the Secret Room and a 50% chance of teleporting the player to the Super Secret Room, because the
74
+ -- I AM ERROR room is never entered into the list of possibilities.
59
75
  function ____exports.onFinalFloor(self)
60
76
  local level = game:GetLevel()
61
77
  local stage = level:GetStage()
@@ -13,6 +13,10 @@ end
13
13
  function ____exports.removeAllCharacters(self, ____string, character)
14
14
  return __TS__StringReplaceAll(____string, character, "")
15
15
  end
16
+ --- Helper function to remove one or more substrings from a string, if they exist. Returns the
17
+ -- modified string.
18
+ --
19
+ -- This function is variadic, meaning that you can pass as many substrings as you want to remove.
16
20
  function ____exports.removeSubstring(self, ____string, ...)
17
21
  local substrings = {...}
18
22
  for ____, substring in ipairs(substrings) do
@@ -20,12 +24,14 @@ function ____exports.removeSubstring(self, ____string, ...)
20
24
  end
21
25
  return ____string
22
26
  end
27
+ --- Helper function to trim a prefix from a string, if it exists. Returns the trimmed string.
23
28
  function ____exports.trimPrefix(self, ____string, prefix)
24
29
  if not __TS__StringStartsWith(____string, prefix) then
25
30
  return ____string
26
31
  end
27
32
  return __TS__StringSlice(____string, #prefix)
28
33
  end
34
+ --- Helper function to trim a suffix from a string, if it exists. Returns the trimmed string.
29
35
  function ____exports.trimSuffix(self, ____string, prefix)
30
36
  if not __TS__StringEndsWith(____string, prefix) then
31
37
  return ____string
@@ -27,6 +27,18 @@ export declare function getNumbersFromTable(table: LuaTable<string, unknown>, ob
27
27
  * This function is variadic, meaning that you can specify N arguments to get N values.
28
28
  */
29
29
  export declare function getStringsFromTable(table: LuaTable<string, unknown>, objectName: string, ...keys: string[]): string[];
30
+ /**
31
+ * Helper function to iterate over a table deterministically. This is useful because by default, the
32
+ * `pairs` function will return the keys of a Lua table in a random order.
33
+ *
34
+ * This function will sort the table entries based on the value of the key.
35
+ *
36
+ * @param table The table to iterate over.
37
+ * @param func The function to run for each iteration.
38
+ * @param deterministic Optional. Whether to iterate deterministically. True by default. You can
39
+ * dynamically set to false in situations where you need extra performance.
40
+ */
41
+ export declare function iterateTableDeterministically<K, V>(table: LuaTable<K, V>, func: (key: K, value: V) => void, deterministic?: boolean): void;
30
42
  /**
31
43
  * Helper function to check if a Lua table has all of the provided keys.
32
44
  *