isaacscript-common 1.2.205 → 1.2.208

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.
@@ -16,6 +16,8 @@ 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;
19
21
  /**
20
22
  * Helper function to get a random `Seed` value to be used in spawning entities and so on. Use this
21
23
  * instead of calling the `Random` function directly since that can return a value of 0 and crash
@@ -36,12 +38,15 @@ export declare function isSerializedRNG(object: unknown): object is SerializedRN
36
38
  */
37
39
  export declare function newRNG(seed?: Seed): RNG;
38
40
  /**
39
- * Helper function to get the next seed value.
40
- *
41
- * This function is useful if you are working with data structures that store seed values instead of
42
- * RNG objects.
41
+ * Helper function to iterate over the provided object and set the seed for all of the values that
42
+ * are RNG objects equal to a particular seed.
43
+ */
44
+ export declare function setAllRNGToSeed(object: unknown, seed: Seed): void;
45
+ /**
46
+ * Helper function to iterate over the provided object and set the seed for all of the values that
47
+ * are RNG objects equal to the start seed for the current run.
43
48
  */
44
- export declare function nextSeed(seed: Seed): Seed;
49
+ export declare function setAllRNGToStartSeed(object: unknown): void;
45
50
  /** Helper function to set a seed to an RNG object using Blade's recommended shift index. */
46
51
  export declare function setSeed(rng: RNG, seed: Seed): void;
47
52
  export {};
@@ -1,6 +1,9 @@
1
- --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
1
+ local ____lualib = require("lualib_bundle")
2
+ local __TS__ObjectValues = ____lualib.__TS__ObjectValues
2
3
  local ____exports = {}
3
4
  local RECOMMENDED_SHIFT_IDX, OBJECT_NAME
5
+ local ____cachedClasses = require("cachedClasses")
6
+ local game = ____cachedClasses.game
4
7
  local ____SerializationBrand = require("enums.private.SerializationBrand")
5
8
  local SerializationBrand = ____SerializationBrand.SerializationBrand
6
9
  local ____SerializationType = require("enums.SerializationType")
@@ -23,12 +26,15 @@ function ____exports.newRNG(self, seed)
23
26
  if seed == nil then
24
27
  seed = ____exports.getRandomSeed(nil)
25
28
  end
29
+ local rng = RNG()
30
+ ____exports.setSeed(nil, rng, seed)
31
+ return rng
32
+ end
33
+ function ____exports.setSeed(self, rng, seed)
26
34
  if seed == 0 then
27
- error("You cannot initialize an RNG object with a seed of 0, or the game will crash.")
35
+ error("You cannot set an RNG object to a seed of 0, or the game will crash.")
28
36
  end
29
- local rng = RNG()
30
37
  rng:SetSeed(seed, RECOMMENDED_SHIFT_IDX)
31
- return rng
32
38
  end
33
39
  RECOMMENDED_SHIFT_IDX = 35
34
40
  local KEYS = {"seed"}
@@ -86,6 +92,10 @@ function ____exports.copyRNG(self, rng, serializationType)
86
92
  end
87
93
  until true
88
94
  end
95
+ function ____exports.getNextSeed(self, rng)
96
+ rng:Next()
97
+ return rng:GetSeed()
98
+ end
89
99
  function ____exports.isSerializedRNG(self, object)
90
100
  local objectType = type(object)
91
101
  if objectType ~= "table" then
@@ -98,12 +108,21 @@ function ____exports.isSerializedRNG(self, object)
98
108
  table.unpack(KEYS)
99
109
  ) and ____table[SerializationBrand.RNG] ~= nil
100
110
  end
101
- function ____exports.nextSeed(self, seed)
102
- local rng = ____exports.newRNG(nil, seed)
103
- rng:Next()
104
- return rng:GetSeed()
111
+ function ____exports.setAllRNGToSeed(self, object, seed)
112
+ local objectType = type(object)
113
+ if objectType ~= "table" then
114
+ error("Failed to iterate over the object containing RNG objects since the type of the provided object was: " .. objectType)
115
+ end
116
+ local ____table = object
117
+ for ____, value in ipairs(__TS__ObjectValues(____table)) do
118
+ if ____exports.isRNG(nil, value) then
119
+ ____exports.setSeed(nil, value, seed)
120
+ end
121
+ end
105
122
  end
106
- function ____exports.setSeed(self, rng, seed)
107
- rng:SetSeed(seed, RECOMMENDED_SHIFT_IDX)
123
+ function ____exports.setAllRNGToStartSeed(self, object)
124
+ local seeds = game:GetSeeds()
125
+ local startSeed = seeds:GetStartSeed()
126
+ ____exports.setAllRNGToSeed(nil, object, startSeed)
108
127
  end
109
128
  return ____exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.205",
3
+ "version": "1.2.208",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",