isaacscript-common 1.2.205 → 1.2.206
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.
- package/dist/functions/rng.d.ts +10 -0
- package/dist/functions/rng.lua +26 -6
- package/package.json +1 -1
package/dist/functions/rng.d.ts
CHANGED
|
@@ -42,6 +42,16 @@ export declare function newRNG(seed?: Seed): RNG;
|
|
|
42
42
|
* RNG objects.
|
|
43
43
|
*/
|
|
44
44
|
export declare function nextSeed(seed: Seed): Seed;
|
|
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 a particular seed.
|
|
48
|
+
*/
|
|
49
|
+
export declare function setAllRNGToSeed(object: unknown, seed: Seed): void;
|
|
50
|
+
/**
|
|
51
|
+
* Helper function to iterate over the provided object and set the seed for all of the values that
|
|
52
|
+
* are RNG objects equal to the start seed for the current run.
|
|
53
|
+
*/
|
|
54
|
+
export declare function setAllRNGToStartSeed(object: unknown): void;
|
|
45
55
|
/** Helper function to set a seed to an RNG object using Blade's recommended shift index. */
|
|
46
56
|
export declare function setSeed(rng: RNG, seed: Seed): void;
|
|
47
57
|
export {};
|
package/dist/functions/rng.lua
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
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
|
|
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"}
|
|
@@ -103,7 +109,21 @@ function ____exports.nextSeed(self, seed)
|
|
|
103
109
|
rng:Next()
|
|
104
110
|
return rng:GetSeed()
|
|
105
111
|
end
|
|
106
|
-
function ____exports.
|
|
107
|
-
|
|
112
|
+
function ____exports.setAllRNGToSeed(self, object, seed)
|
|
113
|
+
local objectType = type(object)
|
|
114
|
+
if objectType ~= "table" then
|
|
115
|
+
error("Failed to iterate over the object containing RNG objects since the type of the provided object was: " .. objectType)
|
|
116
|
+
end
|
|
117
|
+
local ____table = object
|
|
118
|
+
for ____, value in ipairs(__TS__ObjectValues(____table)) do
|
|
119
|
+
if ____exports.isRNG(nil, value) then
|
|
120
|
+
____exports.setSeed(nil, value, seed)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
function ____exports.setAllRNGToStartSeed(self, object)
|
|
125
|
+
local seeds = game:GetSeeds()
|
|
126
|
+
local startSeed = seeds:GetStartSeed()
|
|
127
|
+
____exports.setAllRNGToSeed(nil, object, startSeed)
|
|
108
128
|
end
|
|
109
129
|
return ____exports
|