isaacscript-common 1.2.208 → 1.2.211

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.
@@ -234,6 +234,7 @@ function spawnNormalEntityForJSONRoom(self, entityType, variant, subType, x, y,
234
234
  local room = game:GetRoom()
235
235
  local roomType = room:GetType()
236
236
  local position = gridToPos(nil, x, y)
237
+ local seed = rng:Next()
237
238
  local entity
238
239
  if entityType == EntityType.ENTITY_PICKUP and variant == 100 then
239
240
  local options = roomType == RoomType.ROOM_ANGEL
@@ -241,12 +242,10 @@ function spawnNormalEntityForJSONRoom(self, entityType, variant, subType, x, y,
241
242
  nil,
242
243
  subType,
243
244
  position,
244
- rng,
245
+ seed,
245
246
  options
246
247
  )
247
248
  else
248
- rng:Next()
249
- local seed = rng:GetSeed()
250
249
  entity = game:Spawn(
251
250
  entityType,
252
251
  variant,
@@ -54,7 +54,7 @@ function ____exports.checkFamiliar(self, player, collectibleType, numTargetFamil
54
54
  nil,
55
55
  numFamiliarsToSpawn,
56
56
  function()
57
- collectibleRNG:Next()
57
+ local seed = collectibleRNG:Next()
58
58
  local familiar = game:Spawn(
59
59
  EntityType.ENTITY_FAMILIAR,
60
60
  familiarVariant,
@@ -62,7 +62,7 @@ function ____exports.checkFamiliar(self, player, collectibleType, numTargetFamil
62
62
  Vector.Zero,
63
63
  player,
64
64
  familiarSubTypeToUse,
65
- collectibleRNG:GetSeed()
65
+ seed
66
66
  ):ToFamiliar()
67
67
  if familiar ~= nil then
68
68
  familiar.Player = player
@@ -16,8 +16,6 @@ interface CopyRNGReturn {
16
16
  */
17
17
  export declare function copyRNG<R extends RNG | SerializedRNG, S extends SerializationType>(rng: R, serializationType: S): CopyRNGReturn[S];
18
18
  export declare function copyRNG<R extends RNG | SerializedRNG>(rng: R): CopyRNGReturn[SerializationType.NONE];
19
- /** Helper function to get the next seed value for the provided RNG object. */
20
- export declare function getNextSeed(rng: RNG): Seed;
21
19
  /**
22
20
  * Helper function to get a random `Seed` value to be used in spawning entities and so on. Use this
23
21
  * instead of calling the `Random` function directly since that can return a value of 0 and crash
@@ -92,10 +92,6 @@ function ____exports.copyRNG(self, rng, serializationType)
92
92
  end
93
93
  until true
94
94
  end
95
- function ____exports.getNextSeed(self, rng)
96
- rng:Next()
97
- return rng:GetSeed()
98
- end
99
95
  function ____exports.isSerializedRNG(self, object)
100
96
  local objectType = type(object)
101
97
  if objectType ~= "table" then
@@ -7,13 +7,14 @@
7
7
  *
8
8
  * @param collectibleType The collectible type to spawn.
9
9
  * @param position The position to spawn the collectible at.
10
- * @param rng Optional. Default is `newRNG()`.
10
+ * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
11
+ * `RNG.Next` method will be called. Default is `getRandomSeed()`.
11
12
  * @param options Optional. Set to true to make the collectible a "There's Options" style
12
13
  * collectible. Default is false.
13
14
  * @param forceFreeItem Optional. Set to true to disable the logic that gives the item a price for
14
15
  * Tainted Keeper. Default is false.
15
16
  */
16
- export declare function spawnCollectible(collectibleType: CollectibleType | int, position: Vector, rng?: RNG, options?: boolean, forceFreeItem?: boolean): EntityPickup;
17
+ export declare function spawnCollectible(collectibleType: CollectibleType | int, position: Vector, seedOrRNG?: Seed | RNG, options?: boolean, forceFreeItem?: boolean): EntityPickup;
17
18
  /**
18
19
  * Helper function to spawn an empty collectible. Doing this is tricky since spawning a collectible
19
20
  * with `CollectibleType.COLLECTIBLE_NULL` will result in spawning a collectible with a random type
@@ -21,5 +22,9 @@ export declare function spawnCollectible(collectibleType: CollectibleType | int,
21
22
  *
22
23
  * Instead, this function arbitrarily spawns a collectible with
23
24
  * `CollectibleType.COLLECTIBLE_SAD_ONION`, and then converts it to an empty pedestal afterward.
25
+ *
26
+ * @param position The position to spawn the empty collectible at.
27
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
28
+ * `RNG.Next` method will be called. Default is `getRandomSeed()`.
24
29
  */
25
- export declare function spawnEmptyCollectible(position: Vector, rng?: RNG): EntityPickup;
30
+ export declare function spawnEmptyCollectible(position: Vector, seedOrRNG?: Seed | RNG): EntityPickup;
@@ -12,10 +12,11 @@ local setCollectibleEmpty = ____collectibles.setCollectibleEmpty
12
12
  local ____player = require("functions.player")
13
13
  local anyPlayerIs = ____player.anyPlayerIs
14
14
  local ____rng = require("functions.rng")
15
- local newRNG = ____rng.newRNG
16
- function ____exports.spawnCollectible(self, collectibleType, position, rng, options, forceFreeItem)
17
- if rng == nil then
18
- rng = newRNG(nil)
15
+ local getRandomSeed = ____rng.getRandomSeed
16
+ local isRNG = ____rng.isRNG
17
+ function ____exports.spawnCollectible(self, collectibleType, position, seedOrRNG, options, forceFreeItem)
18
+ if seedOrRNG == nil then
19
+ seedOrRNG = getRandomSeed(nil)
19
20
  end
20
21
  if options == nil then
21
22
  options = false
@@ -23,8 +24,7 @@ function ____exports.spawnCollectible(self, collectibleType, position, rng, opti
23
24
  if forceFreeItem == nil then
24
25
  forceFreeItem = false
25
26
  end
26
- rng:Next()
27
- local seed = rng:GetSeed()
27
+ local seed = isRNG(nil, seedOrRNG) and seedOrRNG:Next() or seedOrRNG
28
28
  local collectible = game:Spawn(
29
29
  EntityType.ENTITY_PICKUP,
30
30
  100,
@@ -49,15 +49,15 @@ function ____exports.spawnCollectible(self, collectibleType, position, rng, opti
49
49
  end
50
50
  return collectible
51
51
  end
52
- function ____exports.spawnEmptyCollectible(self, position, rng)
53
- if rng == nil then
54
- rng = newRNG(nil)
52
+ function ____exports.spawnEmptyCollectible(self, position, seedOrRNG)
53
+ if seedOrRNG == nil then
54
+ seedOrRNG = getRandomSeed(nil)
55
55
  end
56
56
  local collectible = ____exports.spawnCollectible(
57
57
  nil,
58
58
  CollectibleType.COLLECTIBLE_SAD_ONION,
59
59
  position,
60
- rng,
60
+ seedOrRNG,
61
61
  false,
62
62
  true
63
63
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.208",
3
+ "version": "1.2.211",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",