isaacscript-common 1.2.29 → 1.2.32

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.
@@ -5,8 +5,8 @@ local ____exports = require("features.saveDataManager.exports")
5
5
  local saveDataManager = ____exports.saveDataManager
6
6
  local ____collectibles = require("functions.collectibles")
7
7
  local removeCollectibleFromItemTracker = ____collectibles.removeCollectibleFromItemTracker
8
- local ____entity = require("functions.entity")
9
- local removeAllFamiliars = ____entity.removeAllFamiliars
8
+ local ____familiars = require("functions.familiars")
9
+ local removeAllFamiliars = ____familiars.removeAllFamiliars
10
10
  local ____player = require("functions.player")
11
11
  local getPlayerIndex = ____player.getPlayerIndex
12
12
  local ____ModCallbacksCustom = require("types.ModCallbacksCustom")
@@ -29,6 +29,9 @@ function checkRoomChanged(self)
29
29
  local topLeftWall = room:GetGridEntity(topLeftWallGridIndex)
30
30
  if topLeftWall == nil then
31
31
  topLeftWall = spawnGridEntity(nil, GridEntityType.GRID_WALL, topLeftWallGridIndex)
32
+ if topLeftWall == nil then
33
+ return
34
+ end
32
35
  end
33
36
  local topLeftWallPtrHash = GetPtrHash(topLeftWall)
34
37
  if topLeftWallPtrHash ~= currentRoomTopLeftWallPtrHash then
@@ -6,7 +6,7 @@ local Map = ____lualib.Map
6
6
  local __TS__ArrayPush = ____lualib.__TS__ArrayPush
7
7
  local __TS__Iterator = ____lualib.__TS__Iterator
8
8
  local ____exports = {}
9
- local postNewRoom, setDecorationsInvisible, respawnPersistentEntities, removeSpecificNPCs, fillRoomWithDecorations, spawnAllEntities, spawnGridEntity, spawnNormalEntity, storePersistentEntity, fixPitGraphics, getPitMap, getPitFrame, FEATURE_NAME, NPC_TYPES_TO_NOT_REMOVE, PERSISTENT_ENTITY_TYPES, initialized, v
9
+ local postNewRoom, setDecorationsInvisible, respawnPersistentEntities, removeSpecificNPCs, fillRoomWithDecorations, spawnAllEntities, spawnGridEntityForJSONRoom, spawnNormalEntityForJSONRoom, storePersistentEntity, fixPitGraphics, getPitMap, getPitFrame, FEATURE_NAME, NPC_TYPES_TO_NOT_REMOVE, PERSISTENT_ENTITY_TYPES, initialized, v
10
10
  local ____errors = require("errors")
11
11
  local getUpgradeErrorMsg = ____errors.getUpgradeErrorMsg
12
12
  local ____entity = require("functions.entity")
@@ -18,6 +18,7 @@ local convertXMLGridEntityType = ____gridEntity.convertXMLGridEntityType
18
18
  local getGridEntities = ____gridEntity.getGridEntities
19
19
  local removeAllGridEntitiesExceptFor = ____gridEntity.removeAllGridEntitiesExceptFor
20
20
  local setGridEntityInvisible = ____gridEntity.setGridEntityInvisible
21
+ local spawnGridEntityWithVariant = ____gridEntity.spawnGridEntityWithVariant
21
22
  local ____jsonRoom = require("functions.jsonRoom")
22
23
  local getRandomJSONRoom = ____jsonRoom.getRandomJSONRoom
23
24
  local ____log = require("functions.log")
@@ -138,7 +139,9 @@ function fillRoomWithDecorations(self)
138
139
  end
139
140
  local position = room:GetGridPosition(gridIndex)
140
141
  local decoration = Isaac.GridSpawn(GridEntityType.GRID_DECORATION, 0, position, true)
141
- setGridEntityInvisible(nil, decoration)
142
+ if decoration ~= nil then
143
+ setGridEntityInvisible(nil, decoration)
144
+ end
142
145
  __TS__ArrayPush(decorationGridIndexes, gridIndex)
143
146
  end
144
147
  ::__continue34::
@@ -185,7 +188,7 @@ function spawnAllEntities(self, jsonRoom, seed, verbose)
185
188
  if verbose then
186
189
  log(((((((("Spawning grid entity " .. tostring(entityType)) .. ".") .. tostring(variant)) .. " at: (") .. tostring(x)) .. ", ") .. tostring(y)) .. ")")
187
190
  end
188
- spawnGridEntity(
191
+ spawnGridEntityForJSONRoom(
189
192
  nil,
190
193
  entityType,
191
194
  variant,
@@ -197,7 +200,7 @@ function spawnAllEntities(self, jsonRoom, seed, verbose)
197
200
  if verbose then
198
201
  log(((((((((("Spawning normal entity " .. tostring(entityType)) .. ".") .. tostring(variant)) .. ".") .. tostring(subType)) .. " at: (") .. tostring(x)) .. ", ") .. tostring(y)) .. ")")
199
202
  end
200
- local entity = spawnNormalEntity(
203
+ local entity = spawnNormalEntityForJSONRoom(
201
204
  nil,
202
205
  entityType,
203
206
  variant,
@@ -222,28 +225,28 @@ function spawnAllEntities(self, jsonRoom, seed, verbose)
222
225
  end
223
226
  return seed
224
227
  end
225
- function spawnGridEntity(self, xmlEntityType, xmlEntityVariant, x, y)
226
- local gridEntityArray = convertXMLGridEntityType(nil, xmlEntityType, xmlEntityVariant)
227
- if gridEntityArray == nil then
228
+ function spawnGridEntityForJSONRoom(self, xmlEntityType, xmlEntityVariant, x, y)
229
+ local game = Game()
230
+ local room = game:GetRoom()
231
+ local gridEntityTuple = convertXMLGridEntityType(nil, xmlEntityType, xmlEntityVariant)
232
+ if gridEntityTuple == nil then
228
233
  return nil
229
234
  end
230
- local entityType, variant = table.unpack(gridEntityArray)
235
+ local gridEntityType, variant = table.unpack(gridEntityTuple)
231
236
  local position = gridToPos(nil, x, y)
232
- local gridEntity = Isaac.GridSpawn(entityType, variant, position, true)
233
- if entityType == GridEntityType.GRID_PIT then
234
- local pit = gridEntity:ToPit()
235
- if pit ~= nil then
236
- pit:UpdateCollision()
237
- end
237
+ local gridIndex = room:GetGridIndex(position)
238
+ local gridEntity = spawnGridEntityWithVariant(nil, gridEntityType, variant, gridIndex)
239
+ if gridEntity == nil then
240
+ return gridEntity
238
241
  end
239
- if entityType == GridEntityType.GRID_POOP then
242
+ if gridEntityType == GridEntityType.GRID_POOP then
240
243
  local sprite = gridEntity:GetSprite()
241
244
  sprite:Play("State1", true)
242
245
  sprite:SetLastFrame()
243
246
  end
244
247
  return gridEntity
245
248
  end
246
- function spawnNormalEntity(self, entityType, variant, subType, x, y, seed)
249
+ function spawnNormalEntityForJSONRoom(self, entityType, variant, subType, x, y, seed)
247
250
  local game = Game()
248
251
  local room = game:GetRoom()
249
252
  local roomType = room:GetType()
@@ -85,18 +85,6 @@ export declare function getEntityPositions(entities?: Entity[]): Map<PtrHash, Ve
85
85
  * times.
86
86
  */
87
87
  export declare function getEntityVelocities(entities?: Entity[]): Map<PtrHash, Vector>;
88
- /**
89
- * Helper function to get all of the familiars in the room.
90
- *
91
- * Example:
92
- * ```
93
- * // Make all of the familiars in the room invisible
94
- * for (const familiar of getFamiliars()) {
95
- * familiar.Visible = false;
96
- * }
97
- * ```
98
- */
99
- export declare function getFamiliars(matchingVariant?: FamiliarVariant | int, matchingSubType?: number): EntityFamiliar[];
100
88
  /**
101
89
  * Helper function to get all of the knives in the room.
102
90
  *
@@ -197,15 +185,6 @@ export declare function removeAllBombs(variant?: BombVariant | int, subType?: in
197
185
  * @returns True if one or more effects was removed, false otherwise.
198
186
  */
199
187
  export declare function removeAllEffects(variant?: EffectVariant | int, subType?: int, cap?: int): boolean;
200
- /**
201
- * Helper function to remove all of the familiars in the room.
202
- *
203
- * @param variant Optional. If specified, will only remove familiars that match this variant.
204
- * @param subType Optional. If specified, will only remove familiars that match this sub-type.
205
- * @param cap Optional. If specified, will only remove the given amount of familiars.
206
- * @returns True if one or more familiars was removed, false otherwise.
207
- */
208
- export declare function removeAllFamiliars(variant?: FamiliarVariant | int, subType?: int, cap?: int): boolean;
209
188
  /**
210
189
  * Helper function to remove all of the knives in the room.
211
190
  *
@@ -118,23 +118,6 @@ function ____exports.getEntityVelocities(self, entities)
118
118
  end
119
119
  return entityVelocities
120
120
  end
121
- function ____exports.getFamiliars(self, matchingVariant, matchingSubType)
122
- if matchingVariant == nil then
123
- matchingVariant = -1
124
- end
125
- if matchingSubType == nil then
126
- matchingSubType = -1
127
- end
128
- local entities = ____exports.getEntities(nil, EntityType.ENTITY_FAMILIAR, matchingVariant, matchingSubType)
129
- local familiars = {}
130
- for ____, entity in ipairs(entities) do
131
- local familiar = entity:ToFamiliar()
132
- if familiar ~= nil then
133
- __TS__ArrayPush(familiars, familiar)
134
- end
135
- end
136
- return familiars
137
- end
138
121
  function ____exports.getKnives(self, matchingVariant, matchingSubType)
139
122
  if matchingVariant == nil then
140
123
  matchingVariant = -1
@@ -266,10 +249,6 @@ function ____exports.removeAllEffects(self, variant, subType, cap)
266
249
  local effects = ____exports.getEffects(nil, variant, subType)
267
250
  return ____exports.removeEntities(nil, effects, cap)
268
251
  end
269
- function ____exports.removeAllFamiliars(self, variant, subType, cap)
270
- local familiars = ____exports.getFamiliars(nil, variant, subType)
271
- return ____exports.removeEntities(nil, familiars, cap)
272
- end
273
252
  function ____exports.removeAllKnives(self, variant, subType, cap)
274
253
  local knives = ____exports.getKnives(nil, variant, subType)
275
254
  return ____exports.removeEntities(nil, knives, cap)
@@ -1,2 +1,40 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /**
3
+ * Helper function to add and remove familiars based on the amount of associated collectibles that a
4
+ * player has. Use this instead of the `EntityPlayer.CheckFamiliar` method so that the InitSeed of
5
+ * the spawned familiar will be set properly.
6
+ *
7
+ * This function is meant to be called in the EvaluateCache callback (when the cache flag is equal
8
+ * to `CacheFlag.CACHE_FAMILIARS`).
9
+ *
10
+ * @param player The player that has the collectibles for this familiar.
11
+ * @param collectibleType The collectible type of the collectible associated with this familiar.
12
+ * @param familiarVariant The variant of the familiar to spawn or remove.
13
+ * @param familiarSubType The sub-type of the familiar to spawn
14
+ * @returns The amount of familiars that were added or removed. For example, the player has 0
15
+ * collectibles and there were 2 familiars, this function would remove the 2 familiars and return
16
+ * -2.
17
+ */
18
+ export declare function checkFamiliar(player: EntityPlayer, collectibleType: int, familiarVariant: int, familiarSubType?: int): int;
19
+ /**
20
+ * Helper function to get all of the familiars in the room.
21
+ *
22
+ * Example:
23
+ * ```
24
+ * // Make all of the familiars in the room invisible
25
+ * for (const familiar of getFamiliars()) {
26
+ * familiar.Visible = false;
27
+ * }
28
+ * ```
29
+ */
30
+ export declare function getFamiliars(matchingVariant?: FamiliarVariant | int, matchingSubType?: number): EntityFamiliar[];
2
31
  export declare function isFamiliarThatShootsPlayerTears(familiar: EntityFamiliar): boolean;
32
+ /**
33
+ * Helper function to remove all of the familiars in the room.
34
+ *
35
+ * @param variant Optional. If specified, will only remove familiars that match this variant.
36
+ * @param subType Optional. If specified, will only remove familiars that match this sub-type.
37
+ * @param cap Optional. If specified, will only remove the given amount of familiars.
38
+ * @returns True if one or more familiars was removed, false otherwise.
39
+ */
40
+ export declare function removeAllFamiliars(variant?: FamiliarVariant | int, subType?: int, cap?: int): boolean;
@@ -1,10 +1,85 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____lualib = require("lualib_bundle")
3
3
  local Set = ____lualib.Set
4
+ local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
5
+ local __TS__ArrayPush = ____lualib.__TS__ArrayPush
4
6
  local ____exports = {}
5
7
  local ____constants = require("constants")
6
8
  local FAMILIARS_THAT_SHOOT_PLAYER_TEARS = ____constants.FAMILIARS_THAT_SHOOT_PLAYER_TEARS
9
+ local ____entity = require("functions.entity")
10
+ local getEntities = ____entity.getEntities
11
+ local removeEntities = ____entity.removeEntities
12
+ function ____exports.getFamiliars(self, matchingVariant, matchingSubType)
13
+ if matchingVariant == nil then
14
+ matchingVariant = -1
15
+ end
16
+ if matchingSubType == nil then
17
+ matchingSubType = -1
18
+ end
19
+ local entities = getEntities(nil, EntityType.ENTITY_FAMILIAR, matchingVariant, matchingSubType)
20
+ local familiars = {}
21
+ for ____, entity in ipairs(entities) do
22
+ local familiar = entity:ToFamiliar()
23
+ if familiar ~= nil then
24
+ __TS__ArrayPush(familiars, familiar)
25
+ end
26
+ end
27
+ return familiars
28
+ end
29
+ function ____exports.checkFamiliar(self, player, collectibleType, familiarVariant, familiarSubType)
30
+ local game = Game()
31
+ local familiarSubTypeToSearchFor = familiarSubType == nil and -1 or familiarSubType
32
+ local playerPtrHash = GetPtrHash(player)
33
+ local familiars = ____exports.getFamiliars(nil, familiarVariant, familiarSubTypeToSearchFor)
34
+ local familiarsForThisPlayer = __TS__ArrayFilter(
35
+ familiars,
36
+ function(____, familiar) return GetPtrHash(familiar.Player) == playerPtrHash end
37
+ )
38
+ local numCollectibles = player:GetCollectibleNum(collectibleType)
39
+ if #familiarsForThisPlayer == numCollectibles then
40
+ return 0
41
+ end
42
+ if #familiarsForThisPlayer > numCollectibles then
43
+ local numFamiliarsToRemove = #familiarsForThisPlayer - numCollectibles
44
+ do
45
+ local i = 0
46
+ while i < numFamiliarsToRemove do
47
+ local familiar = familiarsForThisPlayer[i + 1]
48
+ familiar:Remove()
49
+ i = i + 1
50
+ end
51
+ end
52
+ return numFamiliarsToRemove * -1
53
+ end
54
+ local numFamiliarsToSpawn = numCollectibles - #familiarsForThisPlayer
55
+ local collectibleRNG = player:GetCollectibleRNG(collectibleType)
56
+ local familiarSubTypeToUse = familiarSubType == nil and 0 or familiarSubType
57
+ do
58
+ local i = 0
59
+ while i < numFamiliarsToSpawn do
60
+ collectibleRNG:Next()
61
+ local familiar = game:Spawn(
62
+ EntityType.ENTITY_FAMILIAR,
63
+ familiarVariant,
64
+ player.Position,
65
+ Vector.Zero,
66
+ nil,
67
+ familiarSubTypeToUse,
68
+ collectibleRNG:GetSeed()
69
+ ):ToFamiliar()
70
+ if familiar ~= nil then
71
+ familiar.Player = player
72
+ end
73
+ i = i + 1
74
+ end
75
+ end
76
+ return numFamiliarsToSpawn
77
+ end
7
78
  function ____exports.isFamiliarThatShootsPlayerTears(self, familiar)
8
79
  return FAMILIARS_THAT_SHOOT_PLAYER_TEARS:has(familiar.Type)
9
80
  end
81
+ function ____exports.removeAllFamiliars(self, variant, subType, cap)
82
+ local familiars = ____exports.getFamiliars(nil, variant, subType)
83
+ return removeEntities(nil, familiars, cap)
84
+ end
10
85
  return ____exports
@@ -106,7 +106,7 @@ export declare function spawnGiantPoop(topLeftGridIndex: int): void;
106
106
  * - removes existing grid entities on the same tile, if any
107
107
  * - allows you to specify the grid index instead of the position
108
108
  */
109
- export declare function spawnGridEntity(gridEntityType: GridEntityType, gridIndex: int): GridEntity;
109
+ export declare function spawnGridEntity(gridEntityType: GridEntityType, gridIndex: int): GridEntity | undefined;
110
110
  /**
111
111
  * Helper function to spawn a grid entity with a specific variant. Use this instead of the
112
112
  * `Isaac.GridSpawn()` method since it:
@@ -114,9 +114,9 @@ export declare function spawnGridEntity(gridEntityType: GridEntityType, gridInde
114
114
  * - removes existing grid entities on the same tile, if any
115
115
  * - allows you to specify the grid index instead of the position
116
116
  */
117
- export declare function spawnGridEntityWithVariant(gridEntityType: GridEntityType, variant: int, gridIndex: int): GridEntity;
117
+ export declare function spawnGridEntityWithVariant(gridEntityType: GridEntityType, variant: int, gridIndex: int): GridEntity | undefined;
118
118
  /**
119
119
  * Helper function to spawn a Void Portal. This is more complicated than simply spawning a trapdoor
120
120
  * with the appropriate variant, as the game does not give it the correct sprite automatically.
121
121
  */
122
- export declare function spawnVoidPortal(gridIndex: int): void;
122
+ export declare function spawnVoidPortal(gridIndex: int): GridEntity | undefined;
@@ -48,6 +48,9 @@ function ____exports.spawnGridEntityWithVariant(self, gridEntityType, variant, g
48
48
  end
49
49
  local position = room:GetGridPosition(gridIndex)
50
50
  local gridEntity = Isaac.GridSpawn(gridEntityType, variant, position, true)
51
+ if gridEntity == nil then
52
+ return gridEntity
53
+ end
51
54
  if gridEntityType == GridEntityType.GRID_PIT then
52
55
  local pit = gridEntity:ToPit()
53
56
  if pit ~= nil then
@@ -221,8 +224,12 @@ function ____exports.spawnGridEntity(self, gridEntityType, gridIndex)
221
224
  end
222
225
  function ____exports.spawnVoidPortal(self, gridIndex)
223
226
  local voidPortal = ____exports.spawnGridEntityWithVariant(nil, GridEntityType.GRID_TRAPDOOR, 1, gridIndex)
227
+ if voidPortal == nil then
228
+ return voidPortal
229
+ end
224
230
  voidPortal.VarData = 1
225
231
  local sprite = voidPortal:GetSprite()
226
232
  sprite:Load("gfx/grid/voidtrapdoor.anm2", true)
233
+ return voidPortal
227
234
  end
228
235
  return ____exports
@@ -81,7 +81,10 @@ NON_ALIVE_NPCS_TYPE_VARIANT = __TS__New(
81
81
  )
82
82
  NON_ALIVE_NPCS_TYPE_VARIANT_SUBTYPE = __TS__New(
83
83
  Set,
84
- {(((tostring(EntityType.ENTITY_CHARGER) .. ".") .. 0) .. ".") .. 1}
84
+ {
85
+ (((tostring(EntityType.ENTITY_CHARGER) .. ".") .. 0) .. ".") .. 1,
86
+ (((tostring(EntityType.ENTITY_MOTHER) .. ".") .. 0) .. ".") .. 1
87
+ }
85
88
  )
86
89
  function ____exports.fireProjectiles(self, npc, position, velocity, projectilesMode, projectileParams)
87
90
  if projectilesMode == nil then
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.29",
3
+ "version": "1.2.32",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -26,10 +26,10 @@
26
26
  ],
27
27
  "devDependencies": {
28
28
  "@zamiell/typescript-to-lua": "^1.4.0",
29
- "isaac-typescript-definitions": "^1.0.339",
29
+ "isaac-typescript-definitions": "^1.0.347",
30
30
  "isaacscript-lint": "^1.0.79",
31
31
  "isaacscript-tsconfig": "^1.1.8",
32
- "typedoc": "^0.22.11",
32
+ "typedoc": "^0.22.12",
33
33
  "typescript": "^4.5.5"
34
34
  }
35
35
  }