isaacscript-common 1.2.77 → 1.2.80

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.
@@ -6,8 +6,8 @@ local ____exports = {}
6
6
  local hasSubscriptions, postUpdate, postNewRoom, checkNewEntity, v
7
7
  local ____exports = require("features.saveDataManager.exports")
8
8
  local saveDataManager = ____exports.saveDataManager
9
- local ____entity = require("functions.entity")
10
- local getSlots = ____entity.getSlots
9
+ local ____entitySpecific = require("functions.entitySpecific")
10
+ local getSlots = ____entitySpecific.getSlots
11
11
  local ____postSlotInit = require("callbacks.subscriptions.postSlotInit")
12
12
  local postSlotInitFire = ____postSlotInit.postSlotInitFire
13
13
  local postSlotInitHasSubscriptions = ____postSlotInit.postSlotInitHasSubscriptions
@@ -6,8 +6,8 @@ local ____exports = {}
6
6
  local hasSubscriptions, postRender, checkSlotBroken, BROKEN_ANIMATIONS, v
7
7
  local ____exports = require("features.saveDataManager.exports")
8
8
  local saveDataManager = ____exports.saveDataManager
9
- local ____entity = require("functions.entity")
10
- local getSlots = ____entity.getSlots
9
+ local ____entitySpecific = require("functions.entitySpecific")
10
+ local getSlots = ____entitySpecific.getSlots
11
11
  local ____postSlotDestroyed = require("callbacks.subscriptions.postSlotDestroyed")
12
12
  local postSlotDestroyedFire = ____postSlotDestroyed.postSlotDestroyedFire
13
13
  local postSlotDestroyedHasSubscriptions = ____postSlotDestroyed.postSlotDestroyedHasSubscriptions
@@ -24,6 +24,7 @@ export declare const CHARACTERS_WITH_NO_RED_HEARTS: ReadonlySet<PlayerType>;
24
24
  * includes The Lost and Tainted Lost.
25
25
  */
26
26
  export declare const CHARACTERS_WITH_NO_SOUL_HEARTS: ReadonlySet<PlayerType>;
27
+ export declare const CHEST_PICKUP_VARIANTS: ReadonlySet<PickupVariant>;
27
28
  /**
28
29
  * A collection of common colors that can be reused. Note that if you want to further modify these
29
30
  * colors, you should copy them first with the `copyColor` function.
@@ -38,6 +38,20 @@ ____exports.CHARACTERS_WITH_NO_SOUL_HEARTS = __TS__New(Set, {
38
38
  PlayerType.PLAYER_THELOST_B,
39
39
  PlayerType.PLAYER_KEEPER_B
40
40
  })
41
+ ____exports.CHEST_PICKUP_VARIANTS = __TS__New(Set, {
42
+ PickupVariant.PICKUP_CHEST,
43
+ PickupVariant.PICKUP_BOMBCHEST,
44
+ PickupVariant.PICKUP_SPIKEDCHEST,
45
+ PickupVariant.PICKUP_ETERNALCHEST,
46
+ PickupVariant.PICKUP_MIMICCHEST,
47
+ PickupVariant.PICKUP_OLDCHEST,
48
+ PickupVariant.PICKUP_WOODENCHEST,
49
+ PickupVariant.PICKUP_MEGACHEST,
50
+ PickupVariant.PICKUP_HAUNTEDCHEST,
51
+ PickupVariant.PICKUP_LOCKEDCHEST,
52
+ PickupVariant.PICKUP_REDCHEST,
53
+ PickupVariant.PICKUP_MOMSCHEST
54
+ })
41
55
  ____exports.COLORS = {
42
56
  Black = Color(1, 1, 1),
43
57
  Red = Color(1, 0, 0),
@@ -10,9 +10,10 @@ local postNewRoom, setDecorationsInvisible, respawnPersistentEntities, removeSpe
10
10
  local ____errors = require("errors")
11
11
  local getUpgradeErrorMsg = ____errors.getUpgradeErrorMsg
12
12
  local ____entity = require("functions.entity")
13
- local removeAllBombs = ____entity.removeAllBombs
14
13
  local removeAllMatchingEntities = ____entity.removeAllMatchingEntities
15
14
  local removeAllPickups = ____entity.removeAllPickups
15
+ local ____entitySpecific = require("functions.entitySpecific")
16
+ local removeAllBombs = ____entitySpecific.removeAllBombs
16
17
  local ____gridEntity = require("functions.gridEntity")
17
18
  local convertXMLGridEntityType = ____gridEntity.convertXMLGridEntityType
18
19
  local getGridEntities = ____gridEntity.getGridEntities
@@ -1,5 +1,10 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  /// <reference types="typescript-to-lua/language-extensions" />
3
+ /**
4
+ * Helper function for determining if two arrays contain the exact same elements. Note that this
5
+ * only performs a shallow comparison.
6
+ */
7
+ export declare function arrayEquals<T>(array1: T[] | readonly T[], array2: T[] | readonly T[]): boolean;
3
8
  /**
4
9
  * Helper function to combine two or more arrays. Returns a new array that is the composition of all
5
10
  * of the specified arrays. This function is variadic, meaning that you can specify N arguments to
@@ -15,11 +20,8 @@ export declare function combineArray<T>(...arrays: Array<T[] | readonly T[]>): T
15
20
  */
16
21
  export declare function copyArray<T>(oldArray: T[] | readonly T[], numElements?: int): T[];
17
22
  export declare function emptyArray<T>(array: T[]): void;
18
- /**
19
- * Helper function for determining if two arrays contain the exact same elements. Note that this
20
- * only performs a shallow comparison.
21
- */
22
- export declare function arrayEquals<T>(array1: T[] | readonly T[], array2: T[] | readonly T[]): boolean;
23
+ /** Helper function to return the last element of an array. */
24
+ export declare function getLastElement<T>(array: T[]): T;
23
25
  /**
24
26
  * Initializes an array with all elements containing the specified default value.
25
27
  *
@@ -1,8 +1,8 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____lualib = require("lualib_bundle")
3
+ local __TS__ArrayEvery = ____lualib.__TS__ArrayEvery
3
4
  local __TS__ArrayPush = ____lualib.__TS__ArrayPush
4
5
  local __TS__ArraySplice = ____lualib.__TS__ArraySplice
5
- local __TS__ArrayEvery = ____lualib.__TS__ArrayEvery
6
6
  local __TS__ArraySome = ____lualib.__TS__ArraySome
7
7
  local __TS__ArrayReduce = ____lualib.__TS__ArrayReduce
8
8
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
@@ -35,8 +35,19 @@ function ____exports.getRandomArrayIndex(self, array, seed)
35
35
  if #array == 0 then
36
36
  error("Failed to get a random array index since the provided array is empty.")
37
37
  end
38
- local randomIndex = getRandomInt(nil, 0, #array - 1, seed)
39
- return randomIndex
38
+ return getRandomInt(nil, 0, #array - 1, seed)
39
+ end
40
+ function ____exports.arrayEquals(self, array1, array2)
41
+ if #array1 ~= #array2 then
42
+ return false
43
+ end
44
+ return __TS__ArrayEvery(
45
+ array1,
46
+ function(____, array1Element, i)
47
+ local array2Element = array2[i + 1]
48
+ return array1Element == array2Element
49
+ end
50
+ )
40
51
  end
41
52
  function ____exports.combineArray(self, ...)
42
53
  local arrays = {...}
@@ -66,17 +77,8 @@ end
66
77
  function ____exports.emptyArray(self, array)
67
78
  __TS__ArraySplice(array, 0, #array)
68
79
  end
69
- function ____exports.arrayEquals(self, array1, array2)
70
- if #array1 ~= #array2 then
71
- return false
72
- end
73
- return __TS__ArrayEvery(
74
- array1,
75
- function(____, array1Element, i)
76
- local array2Element = array2[i + 1]
77
- return array1Element == array2Element
78
- end
79
- )
80
+ function ____exports.getLastElement(self, array)
81
+ return array[#array]
80
82
  end
81
83
  function ____exports.initArray(self, defaultValue, size)
82
84
  local array = {}
@@ -1,18 +1,6 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  import { AnyEntity } from "../types/AnyEntity";
3
3
  export declare function anyEntityCloserThan(entities: Entity[], position: Vector, distance: int): boolean;
4
- /**
5
- * Helper function to get all of the bombs in the room.
6
- *
7
- * Example:
8
- * ```
9
- * // Make all of the bombs in the room invisible
10
- * for (const bomb of getBombs()) {
11
- * bomb.Visible = false;
12
- * }
13
- * ```
14
- */
15
- export declare function getBombs(matchingVariant?: BombVariant | int, matchingSubType?: number): EntityBomb[];
16
4
  /**
17
5
  * Given an array of entities, this helper function returns the closest one to a provided reference
18
6
  * entity.
@@ -24,24 +12,12 @@ export declare function getBombs(matchingVariant?: BombVariant | int, matchingSu
24
12
  * const closestGaper = getClosestEntityTo(player, gapers);
25
13
  * ```
26
14
  */
27
- export declare function getClosestEntityTo(referenceEntity: Entity, entities: Entity[]): Entity;
15
+ export declare function getClosestEntityTo<T extends AnyEntity>(referenceEntity: Entity, entities: T[]): T;
28
16
  /**
29
17
  * Helper function to compare two different arrays of entities. Returns the entities that are in the
30
18
  * second array but not in the first array.
31
19
  */
32
20
  export declare function getFilteredNewEntities<T extends AnyEntity>(oldEntities: T[], newEntities: T[]): T[];
33
- /**
34
- * Helper function to get all of the effects in the room.
35
- *
36
- * Example:
37
- * ```
38
- * // Make all of the effects in the room invisible
39
- * for (const effect of getEffects()) {
40
- * effect.Visible = false;
41
- * }
42
- * ```
43
- */
44
- export declare function getEffects(matchingVariant?: EffectVariant | int, matchingSubType?: number): EntityEffect[];
45
21
  /**
46
22
  * Helper function to get all of the entities in the room or all of the entities that match a
47
23
  * specific entity type / variant / sub-type.
@@ -66,49 +42,6 @@ export declare function getEffects(matchingVariant?: EffectVariant | int, matchi
66
42
  * returned. False by default. Will only be taken into account if `matchingEntityType` is specified.
67
43
  */
68
44
  export declare function getEntities(matchingEntityType?: EntityType | int, matchingVariant?: number, matchingSubType?: number, ignoreFriendly?: boolean): Entity[];
69
- /**
70
- * Helper function to get a map containing the positions of every entity in the current room.
71
- *
72
- * This is useful for rewinding entity positions at a later time. Also see `setEntityPositions()`.
73
- *
74
- * @param entities Optional. If provided, will only get the positions of the provided entities. This
75
- * can be used to cache the entities to avoid invoking `Isaac.GetRoomEntities()` multiple times.
76
- */
77
- export declare function getEntityPositions(entities?: Entity[]): Map<PtrHash, Vector>;
78
- /**
79
- * Helper function to get a map containing the velocities of every entity in the current room.
80
- *
81
- * This is useful for rewinding entity velocities at a later time. Also see `setEntityVelocities()`.
82
- *
83
- * @param entities Optional. If provided, will only get the velocities of the provided entities.
84
- * This can be used to cache the entities to avoid invoking `Isaac.GetRoomEntities()` multiple
85
- * times.
86
- */
87
- export declare function getEntityVelocities(entities?: Entity[]): Map<PtrHash, Vector>;
88
- /**
89
- * Helper function to get all of the knives in the room.
90
- *
91
- * Example:
92
- * ```
93
- * // Make all of the knives in the room invisible
94
- * for (const knife of getKnives()) {
95
- * knife.Visible = false;
96
- * }
97
- * ```
98
- */
99
- export declare function getKnives(matchingVariant?: KnifeVariant | int, matchingSubType?: number): EntityKnife[];
100
- /**
101
- * Helper function to get all of the lasers in the room.
102
- *
103
- * Example:
104
- * ```
105
- * // Make all of the lasers in the room invisible
106
- * for (const laser of getLasers()) {
107
- * laser.Visible = false;
108
- * }
109
- * ```
110
- */
111
- export declare function getLasers(matchingVariant?: LaserVariant | int, matchingSubType?: number): EntityLaser[];
112
45
  /**
113
46
  * Helper function to get all of the pickups in the room.
114
47
  *
@@ -121,31 +54,6 @@ export declare function getLasers(matchingVariant?: LaserVariant | int, matching
121
54
  * ```
122
55
  */
123
56
  export declare function getPickups(matchingVariant?: PickupVariant | int, matchingSubType?: number): EntityPickup[];
124
- /**
125
- * Helper function to get all of the projectiles in the room.
126
- *
127
- * Example:
128
- * ```
129
- * // Make all of the projectiles in the room invisible
130
- * for (const projectile of getProjectiles()) {
131
- * projectile.Visible = false;
132
- * }
133
- * ```
134
- */
135
- export declare function getProjectiles(matchingVariant?: ProjectileVariant | int, matchingSubType?: number): EntityProjectile[];
136
- export declare function getSlots(matchingVariant?: SlotVariant | int, matchingSubType?: number): Entity[];
137
- /**
138
- * Helper function to get all of the tears in the room.
139
- *
140
- * Example:
141
- * ```
142
- * // Make all of the tears in the room invisible
143
- * for (const tear of getTears()) {
144
- * tear.Visible = false;
145
- * }
146
- * ```
147
- */
148
- export declare function getTears(matchingVariant?: TearVariant | int, matchingSubType?: number): EntityTear[];
149
57
  /**
150
58
  * Helper function to measure an entity's velocity to see if it is moving.
151
59
  *
@@ -167,42 +75,6 @@ export declare function isStoryBoss(entity: Entity): boolean;
167
75
  * @returns True if one or more entities was removed, false otherwise.
168
76
  */
169
77
  export declare function removeEntities(entities: Entity[], cap?: int): boolean;
170
- /**
171
- * Helper function to remove all of the bombs in the room.
172
- *
173
- * @param variant Optional. If specified, will only remove bombs that match this variant.
174
- * @param subType Optional. If specified, will only remove bombs that match this sub-type.
175
- * @param cap Optional. If specified, will only remove the given amount of bombs.
176
- * @returns True if one or more bombs was removed, false otherwise.
177
- */
178
- export declare function removeAllBombs(variant?: BombVariant | int, subType?: int, cap?: int): boolean;
179
- /**
180
- * Helper function to remove all of the effects in the room.
181
- *
182
- * @param variant Optional. If specified, will only remove effects that match this variant.
183
- * @param subType Optional. If specified, will only remove effects that match this sub-type.
184
- * @param cap Optional. If specified, will only remove the given amount of effects.
185
- * @returns True if one or more effects was removed, false otherwise.
186
- */
187
- export declare function removeAllEffects(variant?: EffectVariant | int, subType?: int, cap?: int): boolean;
188
- /**
189
- * Helper function to remove all of the knives in the room.
190
- *
191
- * @param variant Optional. If specified, will only remove knives that match this variant.
192
- * @param subType Optional. If specified, will only remove knives that match this sub-type.
193
- * @param cap Optional. If specified, will only remove the given amount of knives.
194
- * @returns True if one or more knives was removed, false otherwise.
195
- */
196
- export declare function removeAllKnives(variant?: KnifeVariant | int, subType?: int, cap?: int): boolean;
197
- /**
198
- * Helper function to remove all of the lasers in the room.
199
- *
200
- * @param variant Optional. If specified, will only remove lasers that match this variant.
201
- * @param subType Optional. If specified, will only remove lasers that match this sub-type.
202
- * @param cap Optional. If specified, will only remove the given amount of lasers.
203
- * @returns True if one or more lasers was removed, false otherwise.
204
- */
205
- export declare function removeAllLasers(variant?: LaserVariant | int, subType?: int, cap?: int): boolean;
206
78
  /**
207
79
  * Helper function to remove all of the matching entities in the room.
208
80
  *
@@ -225,57 +97,12 @@ export declare function removeAllMatchingEntities(entityType: int, entityVariant
225
97
  */
226
98
  export declare function removeAllPickups(variant?: PickupVariant | int, subType?: int, cap?: int): boolean;
227
99
  /**
228
- * Helper function to remove all of the projectiles in the room.
100
+ * Helper function to reroll an enemy. Use this instead of the vanilla "Game.RerollEnemy" function
101
+ * if you want the rerolled enemy to be returned.
229
102
  *
230
- * @param variant Optional. If specified, will only remove projectiles that match this variant.
231
- * @param subType Optional. If specified, will only remove projectiles that match this sub-type.
232
- * @param cap Optional. If specified, will only remove the given amount of projectiles.
233
- * @returns True if one or more projectiles was removed, false otherwise.
103
+ * @param entity The entity to reroll.
104
+ * @returns If the game failed to reroll the enemy, returns undefined. Otherwise, returns the
105
+ * rerolled entity.
234
106
  */
235
- export declare function removeAllProjectiles(variant?: ProjectileVariant | int, subType?: int, cap?: int): boolean;
236
- /**
237
- * Helper function to remove all of the tears in the room.
238
- *
239
- * @param variant Optional. If specified, will only remove tears that match this variant.
240
- * @param subType Optional. If specified, will only remove tears that match this sub-type.
241
- * @param cap Optional. If specified, will only remove the given amount of tears.
242
- * @returns True if one or more tears was removed, false otherwise.
243
- */
244
- export declare function removeAllTears(variant?: TearVariant | int, subType?: int, cap?: int): boolean;
245
- /**
246
- * Game().RerollEnemy rerolls a boolean of whether or not the enemy was rerolled. However, you
247
- * cannot use the same entity object after a reroll. This function calls game.RerollEnemy and
248
- * returns the new entity object.
249
- *
250
- * @param entity The entity to reroll
251
- * @returns If the entity was not rerolled, returns the original entity. otherwise, returns the resulting entity from the reroll
252
- */
253
- export declare function rerollEnemy(entity: Entity): Entity;
254
- /**
255
- * Helper function to set the position of every entity in the room based on a map of positions. If
256
- * an entity is found that does not have matching element in the provided map, then that entity will
257
- * be skipped.
258
- *
259
- * This function is useful for rewinding entity positions at a later time. Also see
260
- * `getEntityPositions()`.
261
- *
262
- * @param entityPositions The map providing the positions for every entity.
263
- * @param entities Optional. If provided, will only set the positions of the provided entities. This
264
- * can be used to cache the entities to avoid invoking `Isaac.GetRoomEntities()` multiple times.
265
- */
266
- export declare function setEntityPositions(entityPositions: Map<PtrHash, Vector>, entities?: Entity[]): void;
107
+ export declare function rerollEnemy(entity: Entity): Entity | undefined;
267
108
  export declare function setEntityRandomColor(entity: Entity): void;
268
- /**
269
- * Helper function to set the velocity of every entity in the room based on a map of velocities. If
270
- * an entity is found that does not have matching element in the provided map, then that entity will
271
- * be skipped.
272
- *
273
- * This function is useful for rewinding entity velocities at a later time. Also see
274
- * `getEntityVelocities()`.
275
- *
276
- * @param entityVelocities The map providing the velocities for every entity.
277
- * @param entities Optional. If provided, will only set the velocities of the provided entities.
278
- * This can be used to cache the entities to avoid invoking `Isaac.GetRoomEntities()` multiple
279
- * times.
280
- */
281
- export declare function setEntityVelocities(entityVelocities: Map<PtrHash, Vector>, entities?: Entity[]): void;
@@ -1,11 +1,10 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____lualib = require("lualib_bundle")
3
3
  local __TS__ArraySome = ____lualib.__TS__ArraySome
4
- local __TS__ArrayPush = ____lualib.__TS__ArrayPush
5
4
  local Set = ____lualib.Set
6
5
  local __TS__New = ____lualib.__TS__New
7
6
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
8
- local Map = ____lualib.Map
7
+ local __TS__ArrayPush = ____lualib.__TS__ArrayPush
9
8
  local ____exports = {}
10
9
  local ____constants = require("constants")
11
10
  local STORY_BOSSES = ____constants.STORY_BOSSES
@@ -14,44 +13,12 @@ local getRandom = ____random.getRandom
14
13
  local nextSeed = ____random.nextSeed
15
14
  local ____utils = require("functions.utils")
16
15
  local ____repeat = ____utils["repeat"]
17
- function ____exports.getEntities(self, matchingEntityType, matchingVariant, matchingSubType, ignoreFriendly)
18
- if matchingVariant == nil then
19
- matchingVariant = -1
20
- end
21
- if matchingSubType == nil then
22
- matchingSubType = -1
23
- end
24
- if ignoreFriendly == nil then
25
- ignoreFriendly = false
26
- end
27
- if matchingEntityType == nil then
28
- return Isaac.GetRoomEntities()
29
- end
30
- return Isaac.FindByType(matchingEntityType, matchingVariant, matchingSubType, ignoreFriendly)
31
- end
32
16
  function ____exports.anyEntityCloserThan(self, entities, position, distance)
33
17
  return __TS__ArraySome(
34
18
  entities,
35
19
  function(____, entity) return position:Distance(entity.Position) <= distance end
36
20
  )
37
21
  end
38
- function ____exports.getBombs(self, matchingVariant, matchingSubType)
39
- if matchingVariant == nil then
40
- matchingVariant = -1
41
- end
42
- if matchingSubType == nil then
43
- matchingSubType = -1
44
- end
45
- local entities = ____exports.getEntities(nil, EntityType.ENTITY_BOMB, matchingVariant, matchingSubType)
46
- local bombs = {}
47
- for ____, entity in ipairs(entities) do
48
- local bomb = entity:ToBomb()
49
- if bomb ~= nil then
50
- __TS__ArrayPush(bombs, bomb)
51
- end
52
- end
53
- return bombs
54
- end
55
22
  function ____exports.getClosestEntityTo(self, referenceEntity, entities)
56
23
  local closestEntity = nil
57
24
  local closestDistance = math.huge
@@ -81,78 +48,20 @@ function ____exports.getFilteredNewEntities(self, oldEntities, newEntities)
81
48
  end
82
49
  )
83
50
  end
84
- function ____exports.getEffects(self, matchingVariant, matchingSubType)
85
- if matchingVariant == nil then
86
- matchingVariant = -1
87
- end
88
- if matchingSubType == nil then
89
- matchingSubType = -1
90
- end
91
- local entities = ____exports.getEntities(nil, EntityType.ENTITY_EFFECT, matchingVariant, matchingSubType)
92
- local effects = {}
93
- for ____, entity in ipairs(entities) do
94
- local effect = entity:ToEffect()
95
- if effect ~= nil then
96
- __TS__ArrayPush(effects, effect)
97
- end
98
- end
99
- return effects
100
- end
101
- function ____exports.getEntityPositions(self, entities)
102
- if entities == nil then
103
- entities = ____exports.getEntities(nil)
104
- end
105
- local entityPositions = __TS__New(Map)
106
- for ____, entity in ipairs(entities) do
107
- local ptrHash = GetPtrHash(entity)
108
- entityPositions:set(ptrHash, entity.Position)
109
- end
110
- return entityPositions
111
- end
112
- function ____exports.getEntityVelocities(self, entities)
113
- if entities == nil then
114
- entities = ____exports.getEntities(nil)
115
- end
116
- local entityVelocities = __TS__New(Map)
117
- for ____, entity in ipairs(entities) do
118
- local ptrHash = GetPtrHash(entity)
119
- entityVelocities:set(ptrHash, entity.Velocity)
120
- end
121
- return entityVelocities
122
- end
123
- function ____exports.getKnives(self, matchingVariant, matchingSubType)
51
+ function ____exports.getEntities(self, matchingEntityType, matchingVariant, matchingSubType, ignoreFriendly)
124
52
  if matchingVariant == nil then
125
53
  matchingVariant = -1
126
54
  end
127
55
  if matchingSubType == nil then
128
56
  matchingSubType = -1
129
57
  end
130
- local entities = ____exports.getEntities(nil, EntityType.ENTITY_KNIFE, matchingVariant, matchingSubType)
131
- local knives = {}
132
- for ____, entity in ipairs(entities) do
133
- local knife = entity:ToKnife()
134
- if knife ~= nil then
135
- __TS__ArrayPush(knives, knife)
136
- end
137
- end
138
- return knives
139
- end
140
- function ____exports.getLasers(self, matchingVariant, matchingSubType)
141
- if matchingVariant == nil then
142
- matchingVariant = -1
143
- end
144
- if matchingSubType == nil then
145
- matchingSubType = -1
58
+ if ignoreFriendly == nil then
59
+ ignoreFriendly = false
146
60
  end
147
- local entities = ____exports.getEntities(nil, EntityType.ENTITY_LASER, matchingVariant, matchingSubType)
148
- local lasers = {}
149
- for ____, entity in ipairs(entities) do
150
- local laser = entity:ToLaser()
151
- if laser ~= nil then
152
- __TS__ArrayPush(lasers, laser)
153
- end
61
+ if matchingEntityType == nil then
62
+ return Isaac.GetRoomEntities()
154
63
  end
155
- return lasers
64
+ return Isaac.FindByType(matchingEntityType, matchingVariant, matchingSubType, ignoreFriendly)
156
65
  end
157
66
  function ____exports.getPickups(self, matchingVariant, matchingSubType)
158
67
  if matchingVariant == nil then
@@ -171,50 +80,6 @@ function ____exports.getPickups(self, matchingVariant, matchingSubType)
171
80
  end
172
81
  return pickups
173
82
  end
174
- function ____exports.getProjectiles(self, matchingVariant, matchingSubType)
175
- if matchingVariant == nil then
176
- matchingVariant = -1
177
- end
178
- if matchingSubType == nil then
179
- matchingSubType = -1
180
- end
181
- local entities = ____exports.getEntities(nil, EntityType.ENTITY_PROJECTILE, matchingVariant, matchingSubType)
182
- local projectiles = {}
183
- for ____, entity in ipairs(entities) do
184
- local projectile = entity:ToProjectile()
185
- if projectile ~= nil then
186
- __TS__ArrayPush(projectiles, projectile)
187
- end
188
- end
189
- return projectiles
190
- end
191
- function ____exports.getSlots(self, matchingVariant, matchingSubType)
192
- if matchingVariant == nil then
193
- matchingVariant = -1
194
- end
195
- if matchingSubType == nil then
196
- matchingSubType = -1
197
- end
198
- local slots = ____exports.getEntities(nil, EntityType.ENTITY_SLOT, matchingVariant, matchingSubType)
199
- return slots
200
- end
201
- function ____exports.getTears(self, matchingVariant, matchingSubType)
202
- if matchingVariant == nil then
203
- matchingVariant = -1
204
- end
205
- if matchingSubType == nil then
206
- matchingSubType = -1
207
- end
208
- local entities = ____exports.getEntities(nil, EntityType.ENTITY_TEAR, matchingVariant, matchingSubType)
209
- local tears = {}
210
- for ____, entity in ipairs(entities) do
211
- local tear = entity:ToTear()
212
- if tear ~= nil then
213
- __TS__ArrayPush(tears, tear)
214
- end
215
- end
216
- return tears
217
- end
218
83
  function ____exports.isEntityMoving(self, entity, threshold)
219
84
  if threshold == nil then
220
85
  threshold = 0.01
@@ -238,22 +103,6 @@ function ____exports.removeEntities(self, entities, cap)
238
103
  end
239
104
  return true
240
105
  end
241
- function ____exports.removeAllBombs(self, variant, subType, cap)
242
- local bombs = ____exports.getBombs(nil, variant, subType)
243
- return ____exports.removeEntities(nil, bombs, cap)
244
- end
245
- function ____exports.removeAllEffects(self, variant, subType, cap)
246
- local effects = ____exports.getEffects(nil, variant, subType)
247
- return ____exports.removeEntities(nil, effects, cap)
248
- end
249
- function ____exports.removeAllKnives(self, variant, subType, cap)
250
- local knives = ____exports.getKnives(nil, variant, subType)
251
- return ____exports.removeEntities(nil, knives, cap)
252
- end
253
- function ____exports.removeAllLasers(self, variant, subType, cap)
254
- local lasers = ____exports.getLasers(nil, variant, subType)
255
- return ____exports.removeEntities(nil, lasers, cap)
256
- end
257
106
  function ____exports.removeAllMatchingEntities(self, entityType, entityVariant, entitySubType, cap)
258
107
  if entityVariant == nil then
259
108
  entityVariant = -1
@@ -271,40 +120,20 @@ function ____exports.removeAllPickups(self, variant, subType, cap)
271
120
  local pickups = ____exports.getPickups(nil, variant, subType)
272
121
  return ____exports.removeEntities(nil, pickups, cap)
273
122
  end
274
- function ____exports.removeAllProjectiles(self, variant, subType, cap)
275
- local projectiles = ____exports.getProjectiles(nil, variant, subType)
276
- return ____exports.removeEntities(nil, projectiles, cap)
277
- end
278
- function ____exports.removeAllTears(self, variant, subType, cap)
279
- local tears = ____exports.getTears(nil, variant, subType)
280
- return ____exports.removeEntities(nil, tears, cap)
281
- end
282
123
  function ____exports.rerollEnemy(self, entity)
283
124
  local game = Game()
284
125
  local oldEntities = ____exports.getEntities(nil)
285
126
  local wasRerolled = game:RerollEnemy(entity)
286
127
  if not wasRerolled then
287
- return entity
128
+ return nil
288
129
  end
289
130
  local newEntities = ____exports.getEntities(nil)
290
131
  local filteredNewEntities = ____exports.getFilteredNewEntities(nil, oldEntities, newEntities)
291
- if #filteredNewEntities ~= 0 then
132
+ if #filteredNewEntities == 0 then
292
133
  error("Failed to find the new entity generated by the \"RerollEnemy\" method.")
293
134
  end
294
135
  return filteredNewEntities[1]
295
136
  end
296
- function ____exports.setEntityPositions(self, entityPositions, entities)
297
- if entities == nil then
298
- entities = ____exports.getEntities(nil)
299
- end
300
- for ____, entity in ipairs(entities) do
301
- local ptrHash = GetPtrHash(entity)
302
- local entityPosition = entityPositions:get(ptrHash)
303
- if entityPosition ~= nil then
304
- entity.Position = entityPosition
305
- end
306
- end
307
- end
308
137
  function ____exports.setEntityRandomColor(self, entity)
309
138
  local colorValues = {}
310
139
  local seed = entity.InitSeed
@@ -326,16 +155,4 @@ function ____exports.setEntityRandomColor(self, entity)
326
155
  false
327
156
  )
328
157
  end
329
- function ____exports.setEntityVelocities(self, entityVelocities, entities)
330
- if entities == nil then
331
- entities = ____exports.getEntities(nil)
332
- end
333
- for ____, entity in ipairs(entities) do
334
- local ptrHash = GetPtrHash(entity)
335
- local entityVelocity = entityVelocities:get(ptrHash)
336
- if entityVelocity ~= nil then
337
- entity.Velocity = entityVelocity
338
- end
339
- end
340
- end
341
158
  return ____exports
@@ -0,0 +1,148 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ /**
3
+ * Helper function to get all of the bombs in the room.
4
+ *
5
+ * Example:
6
+ * ```
7
+ * // Make all of the bombs in the room invisible
8
+ * for (const bomb of getBombs()) {
9
+ * bomb.Visible = false;
10
+ * }
11
+ * ```
12
+ */
13
+ export declare function getBombs(matchingVariant?: BombVariant | int, matchingSubType?: number): EntityBomb[];
14
+ /**
15
+ * Helper function to get all of the effects in the room.
16
+ *
17
+ * Example:
18
+ * ```
19
+ * // Make all of the effects in the room invisible
20
+ * for (const effect of getEffects()) {
21
+ * effect.Visible = false;
22
+ * }
23
+ * ```
24
+ */
25
+ export declare function getEffects(matchingVariant?: EffectVariant | int, matchingSubType?: number): EntityEffect[];
26
+ /**
27
+ * Helper function to get all of the knives in the room.
28
+ *
29
+ * Example:
30
+ * ```
31
+ * // Make all of the knives in the room invisible
32
+ * for (const knife of getKnives()) {
33
+ * knife.Visible = false;
34
+ * }
35
+ * ```
36
+ */
37
+ export declare function getKnives(matchingVariant?: KnifeVariant | int, matchingSubType?: number): EntityKnife[];
38
+ /**
39
+ * Helper function to get all of the lasers in the room.
40
+ *
41
+ * Example:
42
+ * ```
43
+ * // Make all of the lasers in the room invisible
44
+ * for (const laser of getLasers()) {
45
+ * laser.Visible = false;
46
+ * }
47
+ * ```
48
+ */
49
+ export declare function getLasers(matchingVariant?: LaserVariant | int, matchingSubType?: number): EntityLaser[];
50
+ /**
51
+ * Helper function to get all of the projectiles in the room.
52
+ *
53
+ * Example:
54
+ * ```
55
+ * // Make all of the projectiles in the room invisible
56
+ * for (const projectile of getProjectiles()) {
57
+ * projectile.Visible = false;
58
+ * }
59
+ * ```
60
+ */
61
+ export declare function getProjectiles(matchingVariant?: ProjectileVariant | int, matchingSubType?: number): EntityProjectile[];
62
+ /**
63
+ * Helper function to get all of the slots in the room.
64
+ *
65
+ * Example:
66
+ * ```
67
+ * // Make all of the slots in the room invisible
68
+ * for (const slot of getSlots()) {
69
+ * slot.Visible = false;
70
+ * }
71
+ * ```
72
+ */
73
+ export declare function getSlots(matchingVariant?: SlotVariant | int, matchingSubType?: number): Entity[];
74
+ /**
75
+ * Helper function to get all of the tears in the room.
76
+ *
77
+ * Example:
78
+ * ```
79
+ * // Make all of the tears in the room invisible
80
+ * for (const tear of getTears()) {
81
+ * tear.Visible = false;
82
+ * }
83
+ * ```
84
+ */
85
+ export declare function getTears(matchingVariant?: TearVariant | int, matchingSubType?: number): EntityTear[];
86
+ /**
87
+ * Helper function to remove all of the bombs in the room.
88
+ *
89
+ * @param variant Optional. If specified, will only remove bombs that match this variant.
90
+ * @param subType Optional. If specified, will only remove bombs that match this sub-type.
91
+ * @param cap Optional. If specified, will only remove the given amount of bombs.
92
+ * @returns True if one or more bombs was removed, false otherwise.
93
+ */
94
+ export declare function removeAllBombs(variant?: BombVariant | int, subType?: int, cap?: int): boolean;
95
+ /**
96
+ * Helper function to remove all of the effects in the room.
97
+ *
98
+ * @param variant Optional. If specified, will only remove effects that match this variant.
99
+ * @param subType Optional. If specified, will only remove effects that match this sub-type.
100
+ * @param cap Optional. If specified, will only remove the given amount of effects.
101
+ * @returns True if one or more effects was removed, false otherwise.
102
+ */
103
+ export declare function removeAllEffects(variant?: EffectVariant | int, subType?: int, cap?: int): boolean;
104
+ /**
105
+ * Helper function to remove all of the knives in the room.
106
+ *
107
+ * @param variant Optional. If specified, will only remove knives that match this variant.
108
+ * @param subType Optional. If specified, will only remove knives that match this sub-type.
109
+ * @param cap Optional. If specified, will only remove the given amount of knives.
110
+ * @returns True if one or more knives was removed, false otherwise.
111
+ */
112
+ export declare function removeAllKnives(variant?: KnifeVariant | int, subType?: int, cap?: int): boolean;
113
+ /**
114
+ * Helper function to remove all of the lasers in the room.
115
+ *
116
+ * @param variant Optional. If specified, will only remove lasers that match this variant.
117
+ * @param subType Optional. If specified, will only remove lasers that match this sub-type.
118
+ * @param cap Optional. If specified, will only remove the given amount of lasers.
119
+ * @returns True if one or more lasers was removed, false otherwise.
120
+ */
121
+ export declare function removeAllLasers(variant?: LaserVariant | int, subType?: int, cap?: int): boolean;
122
+ /**
123
+ * Helper function to remove all of the projectiles in the room.
124
+ *
125
+ * @param variant Optional. If specified, will only remove projectiles that match this variant.
126
+ * @param subType Optional. If specified, will only remove projectiles that match this sub-type.
127
+ * @param cap Optional. If specified, will only remove the given amount of projectiles.
128
+ * @returns True if one or more projectiles was removed, false otherwise.
129
+ */
130
+ export declare function removeAllProjectiles(variant?: ProjectileVariant | int, subType?: int, cap?: int): boolean;
131
+ /**
132
+ * Helper function to remove all of the slots in the room.
133
+ *
134
+ * @param variant Optional. If specified, will only remove slots that match this variant.
135
+ * @param subType Optional. If specified, will only remove slots that match this sub-type.
136
+ * @param cap Optional. If specified, will only remove the given amount of slots.
137
+ * @returns True if one or more slots was removed, false otherwise.
138
+ */
139
+ export declare function removeAllSlots(variant?: SlotVariant | int, subType?: int, cap?: int): boolean;
140
+ /**
141
+ * Helper function to remove all of the tears in the room.
142
+ *
143
+ * @param variant Optional. If specified, will only remove tears that match this variant.
144
+ * @param subType Optional. If specified, will only remove tears that match this sub-type.
145
+ * @param cap Optional. If specified, will only remove the given amount of tears.
146
+ * @returns True if one or more tears was removed, false otherwise.
147
+ */
148
+ export declare function removeAllTears(variant?: TearVariant | int, subType?: int, cap?: int): boolean;
@@ -0,0 +1,148 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____lualib = require("lualib_bundle")
3
+ local __TS__ArrayPush = ____lualib.__TS__ArrayPush
4
+ local ____exports = {}
5
+ local ____entity = require("functions.entity")
6
+ local getEntities = ____entity.getEntities
7
+ local removeEntities = ____entity.removeEntities
8
+ function ____exports.getBombs(self, matchingVariant, matchingSubType)
9
+ if matchingVariant == nil then
10
+ matchingVariant = -1
11
+ end
12
+ if matchingSubType == nil then
13
+ matchingSubType = -1
14
+ end
15
+ local entities = getEntities(nil, EntityType.ENTITY_BOMB, matchingVariant, matchingSubType)
16
+ local bombs = {}
17
+ for ____, entity in ipairs(entities) do
18
+ local bomb = entity:ToBomb()
19
+ if bomb ~= nil then
20
+ __TS__ArrayPush(bombs, bomb)
21
+ end
22
+ end
23
+ return bombs
24
+ end
25
+ function ____exports.getEffects(self, matchingVariant, matchingSubType)
26
+ if matchingVariant == nil then
27
+ matchingVariant = -1
28
+ end
29
+ if matchingSubType == nil then
30
+ matchingSubType = -1
31
+ end
32
+ local entities = getEntities(nil, EntityType.ENTITY_EFFECT, matchingVariant, matchingSubType)
33
+ local effects = {}
34
+ for ____, entity in ipairs(entities) do
35
+ local effect = entity:ToEffect()
36
+ if effect ~= nil then
37
+ __TS__ArrayPush(effects, effect)
38
+ end
39
+ end
40
+ return effects
41
+ end
42
+ function ____exports.getKnives(self, matchingVariant, matchingSubType)
43
+ if matchingVariant == nil then
44
+ matchingVariant = -1
45
+ end
46
+ if matchingSubType == nil then
47
+ matchingSubType = -1
48
+ end
49
+ local entities = getEntities(nil, EntityType.ENTITY_KNIFE, matchingVariant, matchingSubType)
50
+ local knives = {}
51
+ for ____, entity in ipairs(entities) do
52
+ local knife = entity:ToKnife()
53
+ if knife ~= nil then
54
+ __TS__ArrayPush(knives, knife)
55
+ end
56
+ end
57
+ return knives
58
+ end
59
+ function ____exports.getLasers(self, matchingVariant, matchingSubType)
60
+ if matchingVariant == nil then
61
+ matchingVariant = -1
62
+ end
63
+ if matchingSubType == nil then
64
+ matchingSubType = -1
65
+ end
66
+ local entities = getEntities(nil, EntityType.ENTITY_LASER, matchingVariant, matchingSubType)
67
+ local lasers = {}
68
+ for ____, entity in ipairs(entities) do
69
+ local laser = entity:ToLaser()
70
+ if laser ~= nil then
71
+ __TS__ArrayPush(lasers, laser)
72
+ end
73
+ end
74
+ return lasers
75
+ end
76
+ function ____exports.getProjectiles(self, matchingVariant, matchingSubType)
77
+ if matchingVariant == nil then
78
+ matchingVariant = -1
79
+ end
80
+ if matchingSubType == nil then
81
+ matchingSubType = -1
82
+ end
83
+ local entities = getEntities(nil, EntityType.ENTITY_PROJECTILE, matchingVariant, matchingSubType)
84
+ local projectiles = {}
85
+ for ____, entity in ipairs(entities) do
86
+ local projectile = entity:ToProjectile()
87
+ if projectile ~= nil then
88
+ __TS__ArrayPush(projectiles, projectile)
89
+ end
90
+ end
91
+ return projectiles
92
+ end
93
+ function ____exports.getSlots(self, matchingVariant, matchingSubType)
94
+ if matchingVariant == nil then
95
+ matchingVariant = -1
96
+ end
97
+ if matchingSubType == nil then
98
+ matchingSubType = -1
99
+ end
100
+ local slots = getEntities(nil, EntityType.ENTITY_SLOT, matchingVariant, matchingSubType)
101
+ return slots
102
+ end
103
+ function ____exports.getTears(self, matchingVariant, matchingSubType)
104
+ if matchingVariant == nil then
105
+ matchingVariant = -1
106
+ end
107
+ if matchingSubType == nil then
108
+ matchingSubType = -1
109
+ end
110
+ local entities = getEntities(nil, EntityType.ENTITY_TEAR, matchingVariant, matchingSubType)
111
+ local tears = {}
112
+ for ____, entity in ipairs(entities) do
113
+ local tear = entity:ToTear()
114
+ if tear ~= nil then
115
+ __TS__ArrayPush(tears, tear)
116
+ end
117
+ end
118
+ return tears
119
+ end
120
+ function ____exports.removeAllBombs(self, variant, subType, cap)
121
+ local bombs = ____exports.getBombs(nil, variant, subType)
122
+ return removeEntities(nil, bombs, cap)
123
+ end
124
+ function ____exports.removeAllEffects(self, variant, subType, cap)
125
+ local effects = ____exports.getEffects(nil, variant, subType)
126
+ return removeEntities(nil, effects, cap)
127
+ end
128
+ function ____exports.removeAllKnives(self, variant, subType, cap)
129
+ local knives = ____exports.getKnives(nil, variant, subType)
130
+ return removeEntities(nil, knives, cap)
131
+ end
132
+ function ____exports.removeAllLasers(self, variant, subType, cap)
133
+ local lasers = ____exports.getLasers(nil, variant, subType)
134
+ return removeEntities(nil, lasers, cap)
135
+ end
136
+ function ____exports.removeAllProjectiles(self, variant, subType, cap)
137
+ local projectiles = ____exports.getProjectiles(nil, variant, subType)
138
+ return removeEntities(nil, projectiles, cap)
139
+ end
140
+ function ____exports.removeAllSlots(self, variant, subType, cap)
141
+ local slots = ____exports.getSlots(nil, variant, subType)
142
+ return removeEntities(nil, slots, cap)
143
+ end
144
+ function ____exports.removeAllTears(self, variant, subType, cap)
145
+ local tears = ____exports.getTears(nil, variant, subType)
146
+ return removeEntities(nil, tears, cap)
147
+ end
148
+ return ____exports
@@ -11,8 +11,9 @@ local EGGY_STATE_FRAME_OF_FINAL_SPIDER = ____constants.EGGY_STATE_FRAME_OF_FINAL
11
11
  local ____entity = require("functions.entity")
12
12
  local getEntities = ____entity.getEntities
13
13
  local getFilteredNewEntities = ____entity.getFilteredNewEntities
14
- local getProjectiles = ____entity.getProjectiles
15
14
  local removeEntities = ____entity.removeEntities
15
+ local ____entitySpecific = require("functions.entitySpecific")
16
+ local getProjectiles = ____entitySpecific.getProjectiles
16
17
  function ____exports.getAliveNPCs(self)
17
18
  local npcs = ____exports.getNPCs(nil)
18
19
  return __TS__ArrayFilter(
@@ -1,8 +1,7 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
- local ____lualib = require("lualib_bundle")
3
- local Set = ____lualib.Set
4
- local __TS__New = ____lualib.__TS__New
5
2
  local ____exports = {}
3
+ local ____constants = require("constants")
4
+ local CHEST_PICKUP_VARIANTS = ____constants.CHEST_PICKUP_VARIANTS
6
5
  local ____array = require("functions.array")
7
6
  local getRandomArrayElement = ____array.getRandomArrayElement
8
7
  local ____utils = require("functions.utils")
@@ -17,20 +16,6 @@ function ____exports.getRandomHeartSubType(self, seed, exceptions)
17
16
  local heartSubTypes = getEnumValues(nil, HeartSubType)
18
17
  return getRandomArrayElement(nil, heartSubTypes, seed, exceptions)
19
18
  end
20
- local CHEST_PICKUP_VARIANTS = __TS__New(Set, {
21
- PickupVariant.PICKUP_CHEST,
22
- PickupVariant.PICKUP_BOMBCHEST,
23
- PickupVariant.PICKUP_SPIKEDCHEST,
24
- PickupVariant.PICKUP_ETERNALCHEST,
25
- PickupVariant.PICKUP_MIMICCHEST,
26
- PickupVariant.PICKUP_OLDCHEST,
27
- PickupVariant.PICKUP_WOODENCHEST,
28
- PickupVariant.PICKUP_MEGACHEST,
29
- PickupVariant.PICKUP_HAUNTEDCHEST,
30
- PickupVariant.PICKUP_LOCKEDCHEST,
31
- PickupVariant.PICKUP_REDCHEST,
32
- PickupVariant.PICKUP_MOMSCHEST
33
- })
34
19
  function ____exports.isChest(self, pickup)
35
20
  return CHEST_PICKUP_VARIANTS:has(pickup.Variant)
36
21
  end
@@ -22,6 +22,7 @@ local MAX_VANILLA_CHARACTER = ____constants.MAX_VANILLA_CHARACTER
22
22
  local ____HealthType = require("types.HealthType")
23
23
  local HealthType = ____HealthType.HealthType
24
24
  local ____array = require("functions.array")
25
+ local getLastElement = ____array.getLastElement
25
26
  local sumArray = ____array.sumArray
26
27
  local ____bitwise = require("functions.bitwise")
27
28
  local getKBitOfN = ____bitwise.getKBitOfN
@@ -336,7 +337,7 @@ function ____exports.getEffectsList(self, player)
336
337
  end
337
338
  function ____exports.getFinalPlayer(self)
338
339
  local players = ____exports.getPlayers(nil)
339
- return players[#players]
340
+ return getLastElement(nil, players)
340
341
  end
341
342
  function ____exports.getLastHeart(self, player)
342
343
  local hearts = player:GetHearts()
@@ -0,0 +1,59 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ /**
3
+ * Helper function to get a room position that is not overlapping with a grid entity, a heaven door,
4
+ * or a player. The `Room.FindFreePickupSpawnPosition()` function will return locations that overlap
5
+ * with heaven doors and partially overlap with players, if the thing being spawned is bigger than a
6
+ * tile (like a Blood Donation Machine). Use this function instead if you want to account for those
7
+ * specific situations.
8
+ *
9
+ * @param startingPosition The position to start searching from. If this position is not overlapping
10
+ * with anything, then it will be returned.
11
+ * @param avoidActiveEntities Optional. False by default.
12
+ */
13
+ export declare function findFreePosition(startingPosition: Vector, avoidActiveEntities?: boolean): Vector;
14
+ /**
15
+ * Helper function to get a map containing the positions of every entity in the current room.
16
+ *
17
+ * This is useful for rewinding entity positions at a later time. Also see `setEntityPositions()`.
18
+ *
19
+ * @param entities Optional. If provided, will only get the positions of the provided entities. This
20
+ * can be used to cache the entities to avoid invoking `Isaac.GetRoomEntities()` multiple times.
21
+ */
22
+ export declare function getEntityPositions(entities?: Entity[]): Map<PtrHash, Vector>;
23
+ /**
24
+ * Helper function to get a map containing the velocities of every entity in the current room.
25
+ *
26
+ * This is useful for rewinding entity velocities at a later time. Also see `setEntityVelocities()`.
27
+ *
28
+ * @param entities Optional. If provided, will only get the velocities of the provided entities.
29
+ * This can be used to cache the entities to avoid invoking `Isaac.GetRoomEntities()` multiple
30
+ * times.
31
+ */
32
+ export declare function getEntityVelocities(entities?: Entity[]): Map<PtrHash, Vector>;
33
+ /**
34
+ * Helper function to set the position of every entity in the room based on a map of positions. If
35
+ * an entity is found that does not have matching element in the provided map, then that entity will
36
+ * be skipped.
37
+ *
38
+ * This function is useful for rewinding entity positions at a later time. Also see
39
+ * `getEntityPositions()`.
40
+ *
41
+ * @param entityPositions The map providing the positions for every entity.
42
+ * @param entities Optional. If provided, will only set the positions of the provided entities. This
43
+ * can be used to cache the entities to avoid invoking `Isaac.GetRoomEntities()` multiple times.
44
+ */
45
+ export declare function setEntityPositions(entityPositions: Map<PtrHash, Vector>, entities?: Entity[]): void;
46
+ /**
47
+ * Helper function to set the velocity of every entity in the room based on a map of velocities. If
48
+ * an entity is found that does not have matching element in the provided map, then that entity will
49
+ * be skipped.
50
+ *
51
+ * This function is useful for rewinding entity velocities at a later time. Also see
52
+ * `getEntityVelocities()`.
53
+ *
54
+ * @param entityVelocities The map providing the velocities for every entity.
55
+ * @param entities Optional. If provided, will only set the velocities of the provided entities.
56
+ * This can be used to cache the entities to avoid invoking `Isaac.GetRoomEntities()` multiple
57
+ * times.
58
+ */
59
+ export declare function setEntityVelocities(entityVelocities: Map<PtrHash, Vector>, entities?: Entity[]): void;
@@ -0,0 +1,90 @@
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
+ local ____constants = require("constants")
7
+ local DISTANCE_OF_GRID_TILE = ____constants.DISTANCE_OF_GRID_TILE
8
+ local ____entity = require("functions.entity")
9
+ local anyEntityCloserThan = ____entity.anyEntityCloserThan
10
+ local getEntities = ____entity.getEntities
11
+ local ____entitySpecific = require("functions.entitySpecific")
12
+ local getEffects = ____entitySpecific.getEffects
13
+ local ____player = require("functions.player")
14
+ local getPlayerCloserThan = ____player.getPlayerCloserThan
15
+ local MAX_FIND_FREE_POSITION_ATTEMPTS = 100
16
+ function ____exports.findFreePosition(self, startingPosition, avoidActiveEntities)
17
+ if avoidActiveEntities == nil then
18
+ avoidActiveEntities = false
19
+ end
20
+ local game = Game()
21
+ local room = game:GetRoom()
22
+ local heavenDoors = getEffects(nil, EffectVariant.HEAVEN_LIGHT_DOOR, 0)
23
+ do
24
+ local i = 0
25
+ while i < MAX_FIND_FREE_POSITION_ATTEMPTS do
26
+ do
27
+ local position = room:FindFreePickupSpawnPosition(startingPosition, i, avoidActiveEntities)
28
+ local closePlayer = getPlayerCloserThan(nil, position, DISTANCE_OF_GRID_TILE)
29
+ if closePlayer ~= nil then
30
+ goto __continue3
31
+ end
32
+ local isCloseHeavenDoor = anyEntityCloserThan(nil, heavenDoors, position, DISTANCE_OF_GRID_TILE)
33
+ if isCloseHeavenDoor then
34
+ goto __continue3
35
+ end
36
+ return position
37
+ end
38
+ ::__continue3::
39
+ i = i + 1
40
+ end
41
+ end
42
+ return room:FindFreePickupSpawnPosition(startingPosition)
43
+ end
44
+ function ____exports.getEntityPositions(self, entities)
45
+ if entities == nil then
46
+ entities = getEntities(nil)
47
+ end
48
+ local entityPositions = __TS__New(Map)
49
+ for ____, entity in ipairs(entities) do
50
+ local ptrHash = GetPtrHash(entity)
51
+ entityPositions:set(ptrHash, entity.Position)
52
+ end
53
+ return entityPositions
54
+ end
55
+ function ____exports.getEntityVelocities(self, entities)
56
+ if entities == nil then
57
+ entities = getEntities(nil)
58
+ end
59
+ local entityVelocities = __TS__New(Map)
60
+ for ____, entity in ipairs(entities) do
61
+ local ptrHash = GetPtrHash(entity)
62
+ entityVelocities:set(ptrHash, entity.Velocity)
63
+ end
64
+ return entityVelocities
65
+ end
66
+ function ____exports.setEntityPositions(self, entityPositions, entities)
67
+ if entities == nil then
68
+ entities = getEntities(nil)
69
+ end
70
+ for ____, entity in ipairs(entities) do
71
+ local ptrHash = GetPtrHash(entity)
72
+ local entityPosition = entityPositions:get(ptrHash)
73
+ if entityPosition ~= nil then
74
+ entity.Position = entityPosition
75
+ end
76
+ end
77
+ end
78
+ function ____exports.setEntityVelocities(self, entityVelocities, entities)
79
+ if entities == nil then
80
+ entities = getEntities(nil)
81
+ end
82
+ for ____, entity in ipairs(entities) do
83
+ local ptrHash = GetPtrHash(entity)
84
+ local entityVelocity = entityVelocities:get(ptrHash)
85
+ if entityVelocity ~= nil then
86
+ entity.Velocity = entityVelocity
87
+ end
88
+ end
89
+ end
90
+ return ____exports
@@ -21,14 +21,15 @@ local isHiddenSecretRoomDoor = ____doors.isHiddenSecretRoomDoor
21
21
  local openDoorFast = ____doors.openDoorFast
22
22
  local ____entity = require("functions.entity")
23
23
  local getEntities = ____entity.getEntities
24
- local getEntityPositions = ____entity.getEntityPositions
25
- local getEntityVelocities = ____entity.getEntityVelocities
26
- local setEntityPositions = ____entity.setEntityPositions
27
- local setEntityVelocities = ____entity.setEntityVelocities
28
24
  local ____flag = require("functions.flag")
29
25
  local hasFlag = ____flag.hasFlag
30
26
  local ____math = require("functions.math")
31
27
  local range = ____math.range
28
+ local ____positionVelocity = require("functions.positionVelocity")
29
+ local getEntityPositions = ____positionVelocity.getEntityPositions
30
+ local getEntityVelocities = ____positionVelocity.getEntityVelocities
31
+ local setEntityPositions = ____positionVelocity.setEntityPositions
32
+ local setEntityVelocities = ____positionVelocity.setEntityVelocities
32
33
  function ____exports.getCurrentRoomDescriptorReadOnly(self)
33
34
  local game = Game()
34
35
  local level = game:GetLevel()
package/dist/index.d.ts CHANGED
@@ -22,6 +22,7 @@ export { deepCopy } from "./functions/deepCopy";
22
22
  export { deepCopyTests } from "./functions/deepCopyTests";
23
23
  export * from "./functions/doors";
24
24
  export * from "./functions/entity";
25
+ export * from "./functions/entitySpecific";
25
26
  export * from "./functions/familiars";
26
27
  export * from "./functions/flag";
27
28
  export * from "./functions/flying";
@@ -40,7 +41,7 @@ export * from "./functions/pills";
40
41
  export * from "./functions/player";
41
42
  export * from "./functions/playerHealth";
42
43
  export * from "./functions/pocketItems";
43
- export * from "./functions/position";
44
+ export * from "./functions/positionVelocity";
44
45
  export * from "./functions/random";
45
46
  export * from "./functions/revive";
46
47
  export * from "./functions/rooms";
package/dist/index.lua CHANGED
@@ -186,6 +186,14 @@ do
186
186
  end
187
187
  end
188
188
  end
189
+ do
190
+ local ____export = require("functions.entitySpecific")
191
+ for ____exportKey, ____exportValue in pairs(____export) do
192
+ if ____exportKey ~= "default" then
193
+ ____exports[____exportKey] = ____exportValue
194
+ end
195
+ end
196
+ end
189
197
  do
190
198
  local ____export = require("functions.familiars")
191
199
  for ____exportKey, ____exportValue in pairs(____export) do
@@ -331,7 +339,7 @@ do
331
339
  end
332
340
  end
333
341
  do
334
- local ____export = require("functions.position")
342
+ local ____export = require("functions.positionVelocity")
335
343
  for ____exportKey, ____exportValue in pairs(____export) do
336
344
  if ____exportKey ~= "default" then
337
345
  ____exports[____exportKey] = ____exportValue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.77",
3
+ "version": "1.2.80",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",