isaacscript-common 1.2.204 → 1.2.207

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 getNewSeed(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
@@ -42,4 +44,16 @@ export declare function newRNG(seed?: Seed): RNG;
42
44
  * RNG objects.
43
45
  */
44
46
  export declare function nextSeed(seed: Seed): Seed;
47
+ /**
48
+ * Helper function to iterate over the provided object and set the seed for all of the values that
49
+ * are RNG objects equal to a particular seed.
50
+ */
51
+ export declare function setAllRNGToSeed(object: unknown, seed: Seed): void;
52
+ /**
53
+ * Helper function to iterate over the provided object and set the seed for all of the values that
54
+ * are RNG objects equal to the start seed for the current run.
55
+ */
56
+ export declare function setAllRNGToStartSeed(object: unknown): void;
57
+ /** Helper function to set a seed to an RNG object using Blade's recommended shift index. */
58
+ export declare function setSeed(rng: RNG, seed: Seed): void;
45
59
  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.getNewSeed(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
@@ -103,4 +113,21 @@ function ____exports.nextSeed(self, seed)
103
113
  rng:Next()
104
114
  return rng:GetSeed()
105
115
  end
116
+ function ____exports.setAllRNGToSeed(self, object, seed)
117
+ local objectType = type(object)
118
+ if objectType ~= "table" then
119
+ error("Failed to iterate over the object containing RNG objects since the type of the provided object was: " .. objectType)
120
+ end
121
+ local ____table = object
122
+ for ____, value in ipairs(__TS__ObjectValues(____table)) do
123
+ if ____exports.isRNG(nil, value) then
124
+ ____exports.setSeed(nil, value, seed)
125
+ end
126
+ end
127
+ end
128
+ function ____exports.setAllRNGToStartSeed(self, object)
129
+ local seeds = game:GetSeeds()
130
+ local startSeed = seeds:GetStartSeed()
131
+ ____exports.setAllRNGToSeed(nil, object, startSeed)
132
+ end
106
133
  return ____exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.204",
3
+ "version": "1.2.207",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",