isaacscript-common 71.2.0 → 72.0.0

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.
Files changed (83) hide show
  1. package/dist/index.rollup.d.ts +229 -96
  2. package/dist/isaacscript-common.lua +40 -154
  3. package/dist/src/classes/features/other/CustomItemPools.d.ts +7 -3
  4. package/dist/src/classes/features/other/CustomItemPools.d.ts.map +1 -1
  5. package/dist/src/classes/features/other/CustomItemPools.lua +1 -6
  6. package/dist/src/classes/features/other/DeployJSONRoom.d.ts +7 -3
  7. package/dist/src/classes/features/other/DeployJSONRoom.d.ts.map +1 -1
  8. package/dist/src/classes/features/other/DeployJSONRoom.lua +1 -5
  9. package/dist/src/classes/features/other/ModdedElementSets.d.ts +35 -15
  10. package/dist/src/classes/features/other/ModdedElementSets.d.ts.map +1 -1
  11. package/dist/src/classes/features/other/ModdedElementSets.lua +0 -17
  12. package/dist/src/classes/features/other/SpawnCollectible.d.ts +14 -6
  13. package/dist/src/classes/features/other/SpawnCollectible.d.ts.map +1 -1
  14. package/dist/src/classes/features/other/SpawnCollectible.lua +0 -8
  15. package/dist/src/classes/features/other/SpawnRockAltRewards.d.ts +8 -4
  16. package/dist/src/classes/features/other/SpawnRockAltRewards.d.ts.map +1 -1
  17. package/dist/src/classes/features/other/SpawnRockAltRewards.lua +0 -4
  18. package/dist/src/classes/features/other/customStages/utils.d.ts +2 -2
  19. package/dist/src/classes/features/other/customStages/utils.d.ts.map +1 -1
  20. package/dist/src/classes/features/other/customStages/utils.lua +0 -8
  21. package/dist/src/classes/features/other/extraConsoleCommands/commands.lua +2 -2
  22. package/dist/src/functions/array.d.ts +35 -15
  23. package/dist/src/functions/array.d.ts.map +1 -1
  24. package/dist/src/functions/array.lua +30 -26
  25. package/dist/src/functions/color.d.ts +8 -4
  26. package/dist/src/functions/color.d.ts.map +1 -1
  27. package/dist/src/functions/color.lua +7 -7
  28. package/dist/src/functions/enums.d.ts +6 -3
  29. package/dist/src/functions/enums.d.ts.map +1 -1
  30. package/dist/src/functions/enums.lua +5 -7
  31. package/dist/src/functions/itemPool.d.ts +8 -1
  32. package/dist/src/functions/itemPool.d.ts.map +1 -1
  33. package/dist/src/functions/itemPool.lua +9 -2
  34. package/dist/src/functions/jsonRoom.d.ts +13 -6
  35. package/dist/src/functions/jsonRoom.d.ts.map +1 -1
  36. package/dist/src/functions/jsonRoom.lua +11 -12
  37. package/dist/src/functions/kColor.d.ts +8 -4
  38. package/dist/src/functions/kColor.d.ts.map +1 -1
  39. package/dist/src/functions/kColor.lua +7 -7
  40. package/dist/src/functions/levelGrid.d.ts +12 -5
  41. package/dist/src/functions/levelGrid.d.ts.map +1 -1
  42. package/dist/src/functions/levelGrid.lua +10 -7
  43. package/dist/src/functions/nextStage.d.ts.map +1 -1
  44. package/dist/src/functions/nextStage.lua +4 -1
  45. package/dist/src/functions/random.d.ts +22 -13
  46. package/dist/src/functions/random.d.ts.map +1 -1
  47. package/dist/src/functions/random.lua +19 -20
  48. package/dist/src/functions/rng.d.ts +1 -1
  49. package/dist/src/functions/rng.lua +1 -1
  50. package/dist/src/functions/set.d.ts +7 -3
  51. package/dist/src/functions/set.d.ts.map +1 -1
  52. package/dist/src/functions/set.lua +6 -7
  53. package/dist/src/functions/spawnCollectible.d.ts +13 -5
  54. package/dist/src/functions/spawnCollectible.d.ts.map +1 -1
  55. package/dist/src/functions/spawnCollectible.lua +14 -9
  56. package/dist/src/functions/vector.d.ts +7 -3
  57. package/dist/src/functions/vector.d.ts.map +1 -1
  58. package/dist/src/functions/vector.lua +6 -6
  59. package/dist/src/functions/weighted.d.ts +18 -2
  60. package/dist/src/functions/weighted.d.ts.map +1 -1
  61. package/dist/src/functions/weighted.lua +16 -8
  62. package/package.json +1 -1
  63. package/src/classes/features/other/CustomItemPools.ts +7 -4
  64. package/src/classes/features/other/DeployJSONRoom.ts +9 -5
  65. package/src/classes/features/other/ModdedElementSets.ts +37 -16
  66. package/src/classes/features/other/SpawnCollectible.ts +14 -7
  67. package/src/classes/features/other/SpawnRockAltRewards.ts +9 -5
  68. package/src/classes/features/other/customStages/utils.ts +2 -3
  69. package/src/classes/features/other/extraConsoleCommands/commands.ts +2 -2
  70. package/src/functions/array.ts +36 -16
  71. package/src/functions/color.ts +9 -5
  72. package/src/functions/enums.ts +6 -4
  73. package/src/functions/itemPool.ts +11 -2
  74. package/src/functions/jsonRoom.ts +13 -7
  75. package/src/functions/kColor.ts +9 -5
  76. package/src/functions/levelGrid.ts +13 -6
  77. package/src/functions/nextStage.ts +6 -1
  78. package/src/functions/random.ts +23 -14
  79. package/src/functions/rng.ts +1 -1
  80. package/src/functions/set.ts +7 -4
  81. package/src/functions/spawnCollectible.ts +17 -5
  82. package/src/functions/vector.ts +8 -4
  83. package/src/functions/weighted.ts +18 -3
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  GameStateFlag,
3
3
  GridRoom,
4
+ LevelCurse,
4
5
  LevelStage,
5
6
  StageType,
6
7
  } from "isaac-typescript-definitions";
7
8
  import { game } from "../core/cachedClasses";
9
+ import { hasCurse } from "./curses";
8
10
  import { getRoomGridIndex } from "./roomData";
9
11
  import {
10
12
  calculateStageType,
@@ -56,7 +58,10 @@ export function getNextStage(): LevelStage {
56
58
  return asNumber(stage) + 1;
57
59
  }
58
60
 
59
- if (stage === LevelStage.DEPTHS_2) {
61
+ if (
62
+ stage === LevelStage.DEPTHS_2 ||
63
+ (stage === LevelStage.DEPTHS_1 && hasCurse(LevelCurse.LABYRINTH))
64
+ ) {
60
65
  // From Depths 2 to Mausoleum 2 through the strange door.
61
66
  return LevelStage.DEPTHS_2;
62
67
  }
@@ -1,14 +1,18 @@
1
1
  import { ReadonlySet } from "../types/ReadonlySet";
2
- import { getRandomSeed, isRNG, newRNG } from "./rng";
2
+ import { isRNG, newRNG } from "./rng";
3
3
 
4
4
  /**
5
5
  * Returns a random float between 0 and 1. It is inclusive on the low end, but exclusive on the high
6
6
  * end. (This is because the `RNG.RandomFloat` method will never return a value of exactly 1.)
7
7
  *
8
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
9
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
8
+ * If you want to generate an unseeded number, you must explicitly pass `undefined` to the
9
+ * `seedOrRNG` parameter.
10
+ *
11
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
12
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
13
+ * a random seed.
10
14
  */
11
- export function getRandom(seedOrRNG: Seed | RNG = getRandomSeed()): float {
15
+ export function getRandom(seedOrRNG: Seed | RNG | undefined): float {
12
16
  const rng = isRNG(seedOrRNG) ? seedOrRNG : newRNG(seedOrRNG);
13
17
  return rng.RandomFloat();
14
18
  }
@@ -19,18 +23,22 @@ export function getRandom(seedOrRNG: Seed | RNG = getRandomSeed()): float {
19
23
  * For example:
20
24
  *
21
25
  * ```ts
22
- * const realNumberBetweenOneAndThree = getRandomFloat(1, 3);
26
+ * const realNumberBetweenOneAndThree = getRandomFloat(1, 3, undefined);
23
27
  * ```
24
28
  *
29
+ * If you want to generate an unseeded number, you must explicitly pass `undefined` to the
30
+ * `seedOrRNG` parameter.
31
+ *
25
32
  * @param min The lower bound for the random number (inclusive).
26
33
  * @param max The upper bound for the random number (exclusive).
27
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
28
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
34
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
35
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
36
+ * a random seed.
29
37
  */
30
38
  export function getRandomFloat(
31
39
  min: int,
32
40
  max: int,
33
- seedOrRNG: Seed | RNG = getRandomSeed(),
41
+ seedOrRNG: Seed | RNG | undefined,
34
42
  ): float {
35
43
  if (min > max) {
36
44
  const oldMin = min;
@@ -46,19 +54,20 @@ export function getRandomFloat(
46
54
  /**
47
55
  * Returns a random integer between min and max. It is inclusive on both ends.
48
56
  *
49
- * Note that this function will run the `Next` method on the `RNG` object before returning the
50
- * random number.
51
- *
52
57
  * For example:
53
58
  *
54
59
  * ```ts
55
60
  * const oneTwoOrThree = getRandomInt(1, 3);
56
61
  * ```
57
62
  *
63
+ * If you want to generate an unseeded number, you must explicitly pass `undefined` to the
64
+ * `seedOrRNG` parameter.
65
+ *
58
66
  * @param min The lower bound for the random number (inclusive).
59
67
  * @param max The upper bound for the random number (inclusive).
60
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
61
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
68
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
69
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
70
+ * a random seed.
62
71
  * @param exceptions Optional. An array of elements that will be skipped over when getting the
63
72
  * random integer. For example, a min of 1, a max of 4, and an exceptions array of
64
73
  * `[2]` would cause the function to return either 1, 3, or 4. Default is an empty
@@ -67,7 +76,7 @@ export function getRandomFloat(
67
76
  export function getRandomInt(
68
77
  min: int,
69
78
  max: int,
70
- seedOrRNG: Seed | RNG = getRandomSeed(),
79
+ seedOrRNG: Seed | RNG | undefined,
71
80
  exceptions: int[] | readonly int[] = [],
72
81
  ): int {
73
82
  const rng = isRNG(seedOrRNG) ? seedOrRNG : newRNG(seedOrRNG);
@@ -86,7 +86,7 @@ export function isSerializedRNG(object: unknown): object is SerializedRNG {
86
86
  /**
87
87
  * Helper function to initialize a new RNG object using Blade's recommended shift index.
88
88
  *
89
- * @param seed The seed to initialize it with. Default is `getRandomSeed()`.
89
+ * @param seed Optional. The seed to initialize it with. Default is a random seed.
90
90
  */
91
91
  export function newRNG(seed = getRandomSeed()): RNG {
92
92
  const rng = RNG();
@@ -1,6 +1,5 @@
1
1
  import { ReadonlySet } from "../types/ReadonlySet";
2
2
  import { getArrayCombinations, getRandomArrayElement, sumArray } from "./array";
3
- import { getRandomSeed } from "./rng";
4
3
  import { isPrimitive } from "./types";
5
4
 
6
5
  /**
@@ -68,14 +67,18 @@ export function deleteSetsFromSet<T>(
68
67
  /**
69
68
  * Helper function to get a random element from the provided set.
70
69
  *
70
+ * If you want to get an unseeded element, you must explicitly pass `undefined` to the `seedOrRNG`
71
+ * parameter.
72
+ *
71
73
  * @param set The set to get an element from.
72
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
73
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
74
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
75
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
76
+ * a random seed.
74
77
  * @param exceptions Optional. An array of elements to skip over if selected.
75
78
  */
76
79
  export function getRandomSetElement<T>(
77
80
  set: Set<T> | ReadonlySet<T>,
78
- seedOrRNG: Seed | RNG = getRandomSeed(),
81
+ seedOrRNG: Seed | RNG | undefined,
79
82
  exceptions: T[] | readonly T[] = [],
80
83
  ): T {
81
84
  const array = getSortedSetValues(set);
@@ -20,10 +20,14 @@ import { getRandomSeed, isRNG } from "./rng";
20
20
  * Isaac's rotation mechanic. To handle that, use the `spawnCollectible` helper function instead
21
21
  * (which is provided by `ISCFeature.SPAWN_COLLECTIBLE`).
22
22
  *
23
+ * If you want to spawn an unseeded collectible, you must explicitly pass `undefined` to the
24
+ * `seedOrRNG` parameter.
25
+ *
23
26
  * @param collectibleType The collectible type to spawn.
24
27
  * @param positionOrGridIndex The position or grid index to spawn the collectible at.
25
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
26
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
28
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
29
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
30
+ * a random seed.
27
31
  * @param options Optional. Set to true to make the collectible a "There's Options" style
28
32
  * collectible. Default is false.
29
33
  * @param forceFreeItem Optional. Set to true to disable the logic that gives the item a price for
@@ -33,11 +37,15 @@ import { getRandomSeed, isRNG } from "./rng";
33
37
  export function spawnCollectibleUnsafe(
34
38
  collectibleType: CollectibleType,
35
39
  positionOrGridIndex: Vector | int,
36
- seedOrRNG: Seed | RNG = getRandomSeed(),
40
+ seedOrRNG: Seed | RNG | undefined,
37
41
  options = false,
38
42
  forceFreeItem = false,
39
43
  spawner?: Entity,
40
44
  ): EntityPickupCollectible {
45
+ if (seedOrRNG === undefined) {
46
+ seedOrRNG = getRandomSeed();
47
+ }
48
+
41
49
  const seed = isRNG(seedOrRNG) ? seedOrRNG.Next() : seedOrRNG;
42
50
  const collectible = spawnPickupWithSeed(
43
51
  PickupVariant.COLLECTIBLE,
@@ -82,13 +90,17 @@ export function spawnCollectibleUnsafe(
82
90
  * Onion because it is a quest collectible and quest collectibles will prevent Damocles from
83
91
  * duplicating the pedestal.)
84
92
  *
93
+ * If you want to spawn an unseeded collectible, you must explicitly pass `undefined` to the
94
+ * `seedOrRNG` parameter.
95
+ *
85
96
  * @param positionOrGridIndex The position or grid index to spawn the empty collectible at.
86
97
  * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
87
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
98
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
99
+ * a random seed.
88
100
  */
89
101
  export function spawnEmptyCollectible(
90
102
  positionOrGridIndex: Vector | int,
91
- seedOrRNG: Seed | RNG = getRandomSeed(),
103
+ seedOrRNG: Seed | RNG | undefined,
92
104
  ): EntityPickup {
93
105
  const collectible = spawnCollectibleUnsafe(
94
106
  CollectibleType.BROKEN_SHOVEL_1,
@@ -6,7 +6,7 @@ import { SerializationBrand } from "../enums/private/SerializationBrand";
6
6
  import { angleToDirection } from "./direction";
7
7
  import { isIsaacAPIClassOfType, isaacAPIClassEquals } from "./isaacAPIClass";
8
8
  import { getRandomFloat } from "./random";
9
- import { getRandomSeed, isRNG, newRNG } from "./rng";
9
+ import { isRNG, newRNG } from "./rng";
10
10
  import {
11
11
  copyUserdataValuesToTable,
12
12
  getNumbersFromTable,
@@ -109,11 +109,15 @@ export function getClosestVectorTo(
109
109
  *
110
110
  * Use this over the `RandomVector` function when you need the vector to be seeded.
111
111
  *
112
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
113
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
112
+ * If you want to generate an unseeded vector, you must explicitly pass `undefined` to the
113
+ * `seedOrRNG` parameter.
114
+ *
115
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
116
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
117
+ * a random seed.
114
118
  */
115
119
  export function getRandomVector(
116
- seedOrRNG: Seed | RNG = getRandomSeed(),
120
+ seedOrRNG: Seed | RNG | undefined,
117
121
  ): Readonly<Vector> {
118
122
  const rng = isRNG(seedOrRNG) ? seedOrRNG : newRNG(seedOrRNG);
119
123
 
@@ -1,17 +1,24 @@
1
1
  import type { WeightedArray } from "../types/WeightedArray";
2
2
  import { sumArray } from "./array";
3
3
  import { getRandomFloat } from "./random";
4
- import { getRandomSeed } from "./rng";
5
4
  import { assertDefined } from "./utils";
6
5
 
7
6
  /**
8
7
  * Get a random value from a `WeightedArray`. (A `WeightedArray` is an array of tuples, where the
9
8
  * first element in the tuple is a value, and the second element in the tuple is a float
10
9
  * corresponding to the value's weight.)
10
+ *
11
+ * If you want to get an unseeded element, you must explicitly pass `undefined` to the `seedOrRNG`
12
+ * parameter.
13
+ *
14
+ * @param weightedArray The array to pick from.
15
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
16
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
17
+ * a random seed.
11
18
  */
12
19
  export function getRandomFromWeightedArray<T>(
13
20
  weightedArray: WeightedArray<T>,
14
- seedOrRNG: Seed | RNG = getRandomSeed(),
21
+ seedOrRNG: Seed | RNG | undefined,
15
22
  ): T {
16
23
  const randomIndex = getRandomIndexFromWeightedArray(weightedArray, seedOrRNG);
17
24
 
@@ -28,10 +35,18 @@ export function getRandomFromWeightedArray<T>(
28
35
  * Get a random index from a `WeightedArray`. (A `WeightedArray` is an array of tuples, where the
29
36
  * first element in the tuple is a value, and the second element in the tuple is a float
30
37
  * corresponding to the value's weight.)
38
+ *
39
+ * If you want to get an unseeded index, you must explicitly pass `undefined` to the `seedOrRNG`
40
+ * parameter.
41
+ *
42
+ * @param weightedArray The array to pick from.
43
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
44
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
45
+ * a random seed.
31
46
  */
32
47
  export function getRandomIndexFromWeightedArray<T>(
33
48
  weightedArray: WeightedArray<T>,
34
- seedOrRNG: Seed | RNG = getRandomSeed(),
49
+ seedOrRNG: Seed | RNG | undefined,
35
50
  ): int {
36
51
  if (weightedArray.length === 0) {
37
52
  error(