isaacscript-common 4.8.1 → 4.8.2

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.
@@ -706,7 +706,7 @@ export declare enum ModCallbackCustom {
706
706
  * what it was on the previous frame.
707
707
  *
708
708
  * When registering the callback, takes an optional second argument that will make the callback
709
- * only fire if the player matches the `CollectibleType` provided.
709
+ * only fire if the collectible matches the `CollectibleType` provided.
710
710
  *
711
711
  * ```ts
712
712
  * function postPlayerCollectibleAdded(
@@ -721,7 +721,7 @@ export declare enum ModCallbackCustom {
721
721
  * what it was on the previous frame.
722
722
  *
723
723
  * When registering the callback, takes an optional second argument that will make the callback
724
- * only fire if the player matches the `CollectibleType` provided.
724
+ * only fire if the collectible matches the `CollectibleType` provided.
725
725
  *
726
726
  * ```ts
727
727
  * function postPlayerCollectibleRemoved(
@@ -40,5 +40,8 @@ export declare function getRandomFloat(min: int, max: int, seedOrRNG?: Seed | RN
40
40
  * @param max The upper bound for the random number (inclusive).
41
41
  * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
42
42
  * `RNG.Next` method will be called. Default is `getRandomSeed()`.
43
+ * @param exceptions Optional. An array of elements that will be skipped over when getting the
44
+ * random integer. For example, a min of 1, a max of 4, and an exceptions array of
45
+ * `[2]` would cause the function to return either 1, 3, or 4.
43
46
  */
44
- export declare function getRandomInt(min: int, max: int, seedOrRNG?: Seed | RNG): int;
47
+ export declare function getRandomInt(min: int, max: int, seedOrRNG?: Seed | RNG, exceptions?: int[] | readonly int[]): int;
@@ -1,3 +1,6 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local Set = ____lualib.Set
3
+ local __TS__New = ____lualib.__TS__New
1
4
  local ____exports = {}
2
5
  local ____rng = require("functions.rng")
3
6
  local getRandomSeed = ____rng.getRandomSeed
@@ -54,10 +57,16 @@ end
54
57
  -- @param max The upper bound for the random number (inclusive).
55
58
  -- @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
56
59
  -- `RNG.Next` method will be called. Default is `getRandomSeed()`.
57
- function ____exports.getRandomInt(self, min, max, seedOrRNG)
60
+ -- @param exceptions Optional. An array of elements that will be skipped over when getting the
61
+ -- random integer. For example, a min of 1, a max of 4, and an exceptions array of
62
+ -- `[2]` would cause the function to return either 1, 3, or 4.
63
+ function ____exports.getRandomInt(self, min, max, seedOrRNG, exceptions)
58
64
  if seedOrRNG == nil then
59
65
  seedOrRNG = getRandomSeed(nil)
60
66
  end
67
+ if exceptions == nil then
68
+ exceptions = {}
69
+ end
61
70
  local rng = isRNG(nil, seedOrRNG) and seedOrRNG or newRNG(nil, seedOrRNG)
62
71
  if min > max then
63
72
  local oldMin = min
@@ -65,6 +74,13 @@ function ____exports.getRandomInt(self, min, max, seedOrRNG)
65
74
  min = oldMax
66
75
  max = oldMin
67
76
  end
68
- return rng:RandomInt(max - min + 1) + min
77
+ local exceptionsSet = __TS__New(Set, exceptions)
78
+ local randomInt
79
+ repeat
80
+ do
81
+ randomInt = rng:RandomInt(max - min + 1) + min
82
+ end
83
+ until exceptionsSet:has(randomInt)
84
+ return randomInt
69
85
  end
70
86
  return ____exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "4.8.1",
3
+ "version": "4.8.2",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -22,6 +22,6 @@
22
22
  "main": "index",
23
23
  "types": "index.d.ts",
24
24
  "dependencies": {
25
- "isaac-typescript-definitions": "^3.0.15"
25
+ "isaac-typescript-definitions": "^3.0.17"
26
26
  }
27
27
  }