isaacscript-common 1.2.203 → 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.
@@ -15,6 +15,7 @@ interface CopyColorReturn {
15
15
  * @param serializationType Default is `SerializationType.NONE`.
16
16
  */
17
17
  export declare function copyColor<C extends Color | SerializedColor, S extends SerializationType>(color: C, serializationType: S): CopyColorReturn[S];
18
+ export declare function copyColor<C extends Color | SerializedColor>(color: C): CopyColorReturn[SerializationType.NONE];
18
19
  export declare function copyKColor(kColor: KColor): KColor;
19
20
  export declare function getDefaultColor(): Color;
20
21
  export declare function getDefaultKColor(): KColor;
@@ -15,6 +15,7 @@ interface CopyRNGReturn {
15
15
  * @param serializationType Default is `SerializationType.NONE`.
16
16
  */
17
17
  export declare function copyRNG<R extends RNG | SerializedRNG, S extends SerializationType>(rng: R, serializationType: S): CopyRNGReturn[S];
18
+ export declare function copyRNG<R extends RNG | SerializedRNG>(rng: R): CopyRNGReturn[SerializationType.NONE];
18
19
  /**
19
20
  * Helper function to get a random `Seed` value to be used in spawning entities and so on. Use this
20
21
  * instead of calling the `Random` function directly since that can return a value of 0 and crash
@@ -41,4 +42,16 @@ export declare function newRNG(seed?: Seed): RNG;
41
42
  * RNG objects.
42
43
  */
43
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;
55
+ /** Helper function to set a seed to an RNG object using Blade's recommended shift index. */
56
+ export declare function setSeed(rng: RNG, seed: Seed): void;
44
57
  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"}
@@ -103,4 +109,21 @@ function ____exports.nextSeed(self, seed)
103
109
  rng:Next()
104
110
  return rng:GetSeed()
105
111
  end
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)
128
+ end
106
129
  return ____exports
@@ -15,6 +15,7 @@ interface CopyVectorReturn {
15
15
  * @param serializationType Default is `SerializationType.NONE`.
16
16
  */
17
17
  export declare function copyVector<V extends Vector | SerializedVector, S extends SerializationType>(vector: V, serializationType: S): CopyVectorReturn[S];
18
+ export declare function copyVector<V extends Vector | SerializedVector>(vector: V): CopyVectorReturn[SerializationType.NONE];
18
19
  export declare function directionToVector(direction: Direction): Vector;
19
20
  /**
20
21
  * Helper function to get a new vector of length 1. Using this is safer than using the `Vector.One`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.203",
3
+ "version": "1.2.206",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",