isaacscript-common 71.2.1 → 72.0.1
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/index.rollup.d.ts +229 -96
- package/dist/isaacscript-common.lua +13 -128
- package/dist/src/classes/callbacks/PostHolyMantleRemoved.d.ts.map +1 -1
- package/dist/src/classes/callbacks/PostHolyMantleRemoved.lua +3 -1
- package/dist/src/classes/features/other/CustomItemPools.d.ts +7 -3
- package/dist/src/classes/features/other/CustomItemPools.d.ts.map +1 -1
- package/dist/src/classes/features/other/CustomItemPools.lua +1 -6
- package/dist/src/classes/features/other/DeployJSONRoom.d.ts +7 -3
- package/dist/src/classes/features/other/DeployJSONRoom.d.ts.map +1 -1
- package/dist/src/classes/features/other/DeployJSONRoom.lua +1 -5
- package/dist/src/classes/features/other/ModdedElementSets.d.ts +35 -15
- package/dist/src/classes/features/other/ModdedElementSets.d.ts.map +1 -1
- package/dist/src/classes/features/other/ModdedElementSets.lua +0 -17
- package/dist/src/classes/features/other/SpawnCollectible.d.ts +14 -6
- package/dist/src/classes/features/other/SpawnCollectible.d.ts.map +1 -1
- package/dist/src/classes/features/other/SpawnCollectible.lua +0 -8
- package/dist/src/classes/features/other/SpawnRockAltRewards.d.ts +8 -4
- package/dist/src/classes/features/other/SpawnRockAltRewards.d.ts.map +1 -1
- package/dist/src/classes/features/other/SpawnRockAltRewards.lua +0 -4
- package/dist/src/classes/features/other/customStages/utils.d.ts +2 -2
- package/dist/src/classes/features/other/customStages/utils.d.ts.map +1 -1
- package/dist/src/classes/features/other/customStages/utils.lua +0 -8
- package/dist/src/classes/features/other/extraConsoleCommands/commands.lua +2 -2
- package/dist/src/functions/array.d.ts +35 -15
- package/dist/src/functions/array.d.ts.map +1 -1
- package/dist/src/functions/array.lua +30 -26
- package/dist/src/functions/color.d.ts +8 -4
- package/dist/src/functions/color.d.ts.map +1 -1
- package/dist/src/functions/color.lua +7 -7
- package/dist/src/functions/enums.d.ts +6 -3
- package/dist/src/functions/enums.d.ts.map +1 -1
- package/dist/src/functions/enums.lua +5 -7
- package/dist/src/functions/itemPool.d.ts +8 -1
- package/dist/src/functions/itemPool.d.ts.map +1 -1
- package/dist/src/functions/itemPool.lua +9 -2
- package/dist/src/functions/jsonRoom.d.ts +13 -6
- package/dist/src/functions/jsonRoom.d.ts.map +1 -1
- package/dist/src/functions/jsonRoom.lua +11 -12
- package/dist/src/functions/kColor.d.ts +8 -4
- package/dist/src/functions/kColor.d.ts.map +1 -1
- package/dist/src/functions/kColor.lua +7 -7
- package/dist/src/functions/levelGrid.d.ts +12 -5
- package/dist/src/functions/levelGrid.d.ts.map +1 -1
- package/dist/src/functions/levelGrid.lua +10 -7
- package/dist/src/functions/random.d.ts +22 -13
- package/dist/src/functions/random.d.ts.map +1 -1
- package/dist/src/functions/random.lua +19 -20
- package/dist/src/functions/rng.d.ts +1 -1
- package/dist/src/functions/rng.lua +1 -1
- package/dist/src/functions/set.d.ts +7 -3
- package/dist/src/functions/set.d.ts.map +1 -1
- package/dist/src/functions/set.lua +6 -7
- package/dist/src/functions/spawnCollectible.d.ts +13 -5
- package/dist/src/functions/spawnCollectible.d.ts.map +1 -1
- package/dist/src/functions/spawnCollectible.lua +14 -9
- package/dist/src/functions/vector.d.ts +7 -3
- package/dist/src/functions/vector.d.ts.map +1 -1
- package/dist/src/functions/vector.lua +6 -6
- package/dist/src/functions/weighted.d.ts +18 -2
- package/dist/src/functions/weighted.d.ts.map +1 -1
- package/dist/src/functions/weighted.lua +16 -8
- package/package.json +1 -1
- package/src/classes/callbacks/PostHolyMantleRemoved.ts +6 -1
- package/src/classes/features/other/CustomItemPools.ts +7 -4
- package/src/classes/features/other/DeployJSONRoom.ts +9 -5
- package/src/classes/features/other/ModdedElementSets.ts +37 -16
- package/src/classes/features/other/SpawnCollectible.ts +14 -7
- package/src/classes/features/other/SpawnRockAltRewards.ts +9 -5
- package/src/classes/features/other/customStages/utils.ts +2 -3
- package/src/classes/features/other/extraConsoleCommands/commands.ts +2 -2
- package/src/functions/array.ts +36 -16
- package/src/functions/color.ts +9 -5
- package/src/functions/enums.ts +6 -4
- package/src/functions/itemPool.ts +11 -2
- package/src/functions/jsonRoom.ts +13 -7
- package/src/functions/kColor.ts +9 -5
- package/src/functions/levelGrid.ts +13 -6
- package/src/functions/random.ts +23 -14
- package/src/functions/rng.ts +1 -1
- package/src/functions/set.ts +7 -4
- package/src/functions/spawnCollectible.ts +17 -5
- package/src/functions/vector.ts +8 -4
- package/src/functions/weighted.ts +18 -3
|
@@ -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
|
|
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
|
|
49
|
+
seedOrRNG: Seed | RNG | undefined,
|
|
35
50
|
): int {
|
|
36
51
|
if (weightedArray.length === 0) {
|
|
37
52
|
error(
|