isaacscript-common 1.0.482 → 1.0.483

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.
@@ -201,6 +201,8 @@ function spawnAllEntities(self, jsonRoom, seed, verbose)
201
201
  log("Setting the room to be uncleared since there were one or more battle NPCs spawned.")
202
202
  end
203
203
  setRoomUncleared(nil)
204
+ elseif verbose then
205
+ log("Leaving the room cleared since there were no battle NPCs spawned.")
204
206
  end
205
207
  return seed
206
208
  end
@@ -60,6 +60,25 @@ export declare function getEffects(matchingVariant?: number, matchingSubType?: n
60
60
  * returned. False by default. Will only be taken into account if `matchingEntityType` is specified.
61
61
  */
62
62
  export declare function getEntities(matchingEntityType?: EntityType | int, matchingVariant?: number, matchingSubType?: number, ignoreFriendly?: boolean): Entity[];
63
+ /**
64
+ * Helper function to get a map containing the positions of every entity in the current room.
65
+ *
66
+ * This is useful for rewinding entity positions at a later time. Also see `setEntityPositions()`.
67
+ *
68
+ * @param entities Optional. If provided, will only get the positions of the provided entities. This
69
+ * can be used to cache the entities to avoid invoking `Isaac.GetRoomEntities()` multiple times.
70
+ */
71
+ export declare function getEntityPositions(entities?: Entity[]): Map<PtrHash, Vector>;
72
+ /**
73
+ * Helper function to get a map containing the velocities of every entity in the current room.
74
+ *
75
+ * This is useful for rewinding entity velocities at a later time. Also see `setEntityVelocities()`.
76
+ *
77
+ * @param entities Optional. If provided, will only get the velocities of the provided entities.
78
+ * This can be used to cache the entities to avoid invoking `Isaac.GetRoomEntities()` multiple
79
+ * times.
80
+ */
81
+ export declare function getEntityVelocities(entities?: Entity[]): Map<PtrHash, Vector>;
63
82
  /**
64
83
  * Helper function to get all of the familiars in the room.
65
84
  *
@@ -144,4 +163,31 @@ export declare function removeAllMatchingEntities(entityType: int, entityVariant
144
163
  export declare function removeAllPickups(): void;
145
164
  export declare function removeAllProjectiles(): void;
146
165
  export declare function removeAllTears(): void;
166
+ /**
167
+ * Helper function to set the position of every entity in the room based on a map of positions. If
168
+ * an entity is found that does not have matching element in the provided map, then that entity will
169
+ * be skipped.
170
+ *
171
+ * This function is useful for rewinding entity positions at a later time. Also see
172
+ * `getEntityPositions()`.
173
+ *
174
+ * @param entityPositions The map providing the positions for every entity.
175
+ * @param entities Optional. If provided, will only set the positions of the provided entities. This
176
+ * can be used to cache the entities to avoid invoking `Isaac.GetRoomEntities()` multiple times.
177
+ */
178
+ export declare function setEntityPositions(entityPositions: Map<PtrHash, Vector>, entities?: Entity[]): void;
147
179
  export declare function setEntityRandomColor(entity: Entity): void;
180
+ /**
181
+ * Helper function to set the velocity of every entity in the room based on a map of velocities. If
182
+ * an entity is found that does not have matching element in the provided map, then that entity will
183
+ * be skipped.
184
+ *
185
+ * This function is useful for rewinding entity velocities at a later time. Also see
186
+ * `getEntityVelocities()`.
187
+ *
188
+ * @param entityVelocities The map providing the velocities for every entity.
189
+ * @param entities Optional. If provided, will only set the velocities of the provided entities.
190
+ * This can be used to cache the entities to avoid invoking `Isaac.GetRoomEntities()` multiple
191
+ * times.
192
+ */
193
+ export declare function setEntityVelocities(entityVelocities: Map<PtrHash, Vector>, entities?: Entity[]): void;
@@ -76,6 +76,28 @@ function ____exports.getEntities(self, matchingEntityType, matchingVariant, matc
76
76
  end
77
77
  return Isaac.FindByType(matchingEntityType, matchingVariant, matchingSubType, ignoreFriendly)
78
78
  end
79
+ function ____exports.getEntityPositions(self, entities)
80
+ if entities == nil then
81
+ entities = ____exports.getEntities(nil)
82
+ end
83
+ local entityPositions = __TS__New(Map)
84
+ for ____, entity in ipairs(entities) do
85
+ local ptrHash = GetPtrHash(entity)
86
+ entityPositions:set(ptrHash, entity.Position)
87
+ end
88
+ return entityPositions
89
+ end
90
+ function ____exports.getEntityVelocities(self, entities)
91
+ if entities == nil then
92
+ entities = ____exports.getEntities(nil)
93
+ end
94
+ local entityVelocities = __TS__New(Map)
95
+ for ____, entity in ipairs(entities) do
96
+ local ptrHash = GetPtrHash(entity)
97
+ entityVelocities:set(ptrHash, entity.Velocity)
98
+ end
99
+ return entityVelocities
100
+ end
79
101
  function ____exports.getFamiliars(self, matchingVariant, matchingSubType)
80
102
  if matchingVariant == nil then
81
103
  matchingVariant = -1
@@ -251,6 +273,18 @@ function ____exports.removeAllTears(self)
251
273
  tear:Remove()
252
274
  end
253
275
  end
276
+ function ____exports.setEntityPositions(self, entityPositions, entities)
277
+ if entities == nil then
278
+ entities = ____exports.getEntities(nil)
279
+ end
280
+ for ____, entity in ipairs(entities) do
281
+ local ptrHash = GetPtrHash(entity)
282
+ local entityPosition = entityPositions:get(ptrHash)
283
+ if entityPosition ~= nil then
284
+ entity.Position = entityPosition
285
+ end
286
+ end
287
+ end
254
288
  function ____exports.setEntityRandomColor(self, entity)
255
289
  local colorValues = {}
256
290
  local seed = entity.InitSeed
@@ -266,4 +300,16 @@ function ____exports.setEntityRandomColor(self, entity)
266
300
  local color = Color(colorValues[1], colorValues[2], colorValues[3])
267
301
  entity:SetColor(color, 100000, 100000, false, false)
268
302
  end
303
+ function ____exports.setEntityVelocities(self, entityVelocities, entities)
304
+ if entities == nil then
305
+ entities = ____exports.getEntities(nil)
306
+ end
307
+ for ____, entity in ipairs(entities) do
308
+ local ptrHash = GetPtrHash(entity)
309
+ local entityVelocity = entityVelocities:get(ptrHash)
310
+ if entityVelocity ~= nil then
311
+ entity.Velocity = entityVelocity
312
+ end
313
+ end
314
+ end
269
315
  return ____exports
@@ -38,9 +38,30 @@ export declare function isAllPressurePlatesPushed(): boolean;
38
38
  * at the VarData of the entity.)
39
39
  */
40
40
  export declare function isPostBossVoidPortal(gridEntity: GridEntity): boolean;
41
+ /**
42
+ * Helper function to remove most grid entities in the room.
43
+ *
44
+ * Example:
45
+ * ```
46
+ * removeAllGridEntitiesExceptFor(
47
+ * GridEntityType.GRID_WALL,
48
+ * GridEntityType.GRID_DOOR,
49
+ * );
50
+ * ```
51
+ */
41
52
  export declare function removeAllGridEntitiesExceptFor(...gridEntityTypes: GridEntityType[]): void;
42
53
  export declare function removeAllMatchingGridEntities(gridEntityType: GridEntityType): void;
43
- export declare function removeGridEntity(gridEntity: GridEntity): void;
54
+ /**
55
+ * Helper function to remove a grid entity simply by providing the grid entity object.
56
+ *
57
+ * @param gridEntity The grid entity to remove.
58
+ * @param updateRoom Optional. Whether or not to update the room after the grid entity is removed.
59
+ * True by default. This is generally a good idea because if the room is not updated, you will be
60
+ * unable to spawn another grid entity on the same tile until a frame has passed. However, doing
61
+ * this is expensive, since it involves a call to `Isaac.GetRoomEntities()`, so set it to false if
62
+ * you need to invoke this function multiple times.
63
+ */
64
+ export declare function removeGridEntity(gridEntity: GridEntity, updateRoom?: boolean): void;
44
65
  /**
45
66
  * Helper function to make a grid entity invisible. This is accomplished by setting its sprite to
46
67
  * "gfx/none.png" (a non-existent PNG file).
@@ -3,12 +3,19 @@ require("lualib_bundle");
3
3
  local ____exports = {}
4
4
  local ____constants = require("constants")
5
5
  local GRID_ENTITY_XML_MAP = ____constants.GRID_ENTITY_XML_MAP
6
- function ____exports.removeGridEntity(self, gridEntity)
6
+ local ____rooms = require("functions.rooms")
7
+ local roomUpdateSafe = ____rooms.roomUpdateSafe
8
+ function ____exports.removeGridEntity(self, gridEntity, updateRoom)
9
+ if updateRoom == nil then
10
+ updateRoom = true
11
+ end
7
12
  local game = Game()
8
13
  local room = game:GetRoom()
9
14
  local gridIndex = gridEntity:GetGridIndex()
10
15
  room:RemoveGridEntity(gridIndex, 0, false)
11
- room:Update()
16
+ if updateRoom then
17
+ roomUpdateSafe(nil)
18
+ end
12
19
  end
13
20
  function ____exports.spawnGridEntityWithVariant(self, gridEntityType, variant, gridIndex)
14
21
  local game = Game()
@@ -113,15 +120,17 @@ function ____exports.removeAllGridEntitiesExceptFor(self, ...)
113
120
  for ____, gridEntity in ipairs(gridEntities) do
114
121
  local gridEntityType = gridEntity:GetType()
115
122
  if not gridEntityTypeExceptions:has(gridEntityType) then
116
- ____exports.removeGridEntity(nil, gridEntity)
123
+ ____exports.removeGridEntity(nil, gridEntity, false)
117
124
  end
118
125
  end
126
+ roomUpdateSafe(nil)
119
127
  end
120
128
  function ____exports.removeAllMatchingGridEntities(self, gridEntityType)
121
129
  local gridEntities = ____exports.getGridEntities(nil, gridEntityType)
122
130
  for ____, gridEntity in ipairs(gridEntities) do
123
- ____exports.removeGridEntity(nil, gridEntity)
131
+ ____exports.removeGridEntity(nil, gridEntity, false)
124
132
  end
133
+ roomUpdateSafe(nil)
125
134
  end
126
135
  function ____exports.setGridEntityInvisible(self, gridEntity)
127
136
  local sprite = gridEntity:GetSprite()
@@ -108,6 +108,13 @@ export declare function inDimension(dimension: Dimension): boolean;
108
108
  export declare function inLRoom(): boolean;
109
109
  export declare function inGenesisRoom(): boolean;
110
110
  export declare function inStartingRoom(): boolean;
111
+ /**
112
+ * If `Room.Update()` is called in a PostNewRoom callback, then some entities will slide around
113
+ * (such as the player). Since those entity velocities are already at zero, setting them to zero
114
+ * will have no effect. Thus, a generic solution is to record all of the entity positions/velocities
115
+ * before updating the room, and then restore those positions/velocities.
116
+ */
117
+ export declare function roomUpdateSafe(): void;
111
118
  /**
112
119
  * Helper function to convert an uncleared room to a cleared room in the PostNewRoom callback. This
113
120
  * is useful because if enemies are removed in this callback, a room drop will be awarded and the
@@ -11,6 +11,12 @@ local ____doors = require("functions.doors")
11
11
  local closeAllDoors = ____doors.closeAllDoors
12
12
  local getDoors = ____doors.getDoors
13
13
  local isHiddenSecretRoomDoor = ____doors.isHiddenSecretRoomDoor
14
+ local ____entity = require("functions.entity")
15
+ local getEntities = ____entity.getEntities
16
+ local getEntityPositions = ____entity.getEntityPositions
17
+ local getEntityVelocities = ____entity.getEntityVelocities
18
+ local setEntityPositions = ____entity.setEntityPositions
19
+ local setEntityVelocities = ____entity.setEntityVelocities
14
20
  local ____flag = require("functions.flag")
15
21
  local hasFlag = ____flag.hasFlag
16
22
  function ____exports.getRoomIndex(self)
@@ -196,6 +202,16 @@ function ____exports.inStartingRoom(self)
196
202
  local roomIndex = ____exports.getRoomIndex(nil)
197
203
  return roomIndex == startingRoomIndex
198
204
  end
205
+ function ____exports.roomUpdateSafe(self)
206
+ local game = Game()
207
+ local room = game:GetRoom()
208
+ local entities = getEntities(nil)
209
+ local entityPositions = getEntityPositions(nil, entities)
210
+ local entityVelocities = getEntityVelocities(nil, entities)
211
+ room:Update()
212
+ setEntityPositions(nil, entityPositions, entities)
213
+ setEntityVelocities(nil, entityVelocities, entities)
214
+ end
199
215
  function ____exports.setRoomCleared(self)
200
216
  local game = Game()
201
217
  local room = game:GetRoom()
@@ -210,14 +226,14 @@ function ____exports.setRoomCleared(self)
210
226
  ) do
211
227
  do
212
228
  if isHiddenSecretRoomDoor(nil, door) then
213
- goto __continue38
229
+ goto __continue39
214
230
  end
215
231
  door.State = DoorState.STATE_OPEN
216
232
  local sprite = door:GetSprite()
217
233
  sprite:Play("Opened", true)
218
234
  door.ExtraVisible = false
219
235
  end
220
- ::__continue38::
236
+ ::__continue39::
221
237
  end
222
238
  sfx:Stop(SoundEffect.SOUND_DOOR_HEAVY_OPEN)
223
239
  game:ShakeScreen(0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.0.482",
3
+ "version": "1.0.483",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",