isaacscript-common 31.2.2 → 31.3.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.
@@ -1470,12 +1470,12 @@ export declare function checkFamiliar(player: EntityPlayer, collectibleType: Col
1470
1470
  export declare function checkFamiliarFromCollectibles(player: EntityPlayer, collectibleType: CollectibleType, familiarVariant: FamiliarVariant, familiarSubType?: int): void;
1471
1471
 
1472
1472
  /**
1473
- * Helper function to normalize an integer.
1473
+ * Helper function to normalize a number, ensuring that it is within a certain range.
1474
1474
  *
1475
- * - If `x` is less than `min`, then it will be clamped to `min`.
1476
- * - If `x` is greater than `max`, then it will be clamped to `max`.
1475
+ * - If `num` is less than `min`, then it will be clamped to `min`.
1476
+ * - If `num` is greater than `max`, then it will be clamped to `max`.
1477
1477
  */
1478
- export declare function clamp(x: int, min: int, max: int): int;
1478
+ export declare function clamp(num: int, min: int, max: int): int;
1479
1479
 
1480
1480
  export declare function clearCollectibleSprite(collectible: EntityPickup): void;
1481
1481
 
@@ -4053,10 +4053,19 @@ export declare type EntityID = string & {
4053
4053
 
4054
4054
  /**
4055
4055
  * Helper function to return an array of integers with the specified range, inclusive on the lower
4056
- * end and exclusive on the high end. (The "e" in the function name stands for exclusive.)
4056
+ * end and exclusive on the high end. (The "e" in the function name stands for exclusive.) Thus,
4057
+ * this function works in a similar way as the built-in `range` function from Python.
4057
4058
  *
4058
- * - For example, `eRange(1, 3)` will return `[1, 2]`.
4059
- * - For example, `eRange(2)` will return `[0, 1]`.
4059
+ * If the end is lower than the start, then the range will be reversed.
4060
+ *
4061
+ * For example:
4062
+ *
4063
+ * - `eRange(2)` returns `[0, 1]`.
4064
+ * - `eRange(3)` returns `[0, 1, 2]`.
4065
+ * - `eRange(-3)` returns `[0, -1, -2]`.
4066
+ * - `eRange(1, 3)` returns `[1, 2]`.
4067
+ * - `eRange(2, 5)` returns `[2, 3, 4]`.
4068
+ * - `eRange(5, 2)` returns `[5, 4, 3]`.
4060
4069
  *
4061
4070
  * @param start The integer to start at.
4062
4071
  * @param end Optional. The integer to end at. If not specified, then the start will be 0 and the
@@ -4219,13 +4228,13 @@ export declare function filter<T>(array: T[], func: (value: T, index: number, ar
4219
4228
  * function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
4220
4229
  * this function cannot be used in situations where `undefined` can be a valid array element.)
4221
4230
  *
4222
- * This function is useful because a map will always produce an array with the same amount of
4223
- * elements as the original array.
4231
+ * This function is useful because the `Array.map` method will always produce an array with the same
4232
+ * amount of elements as the original array.
4224
4233
  *
4225
4234
  * This is named `filterMap` after the Rust function:
4226
4235
  * https://doc.rust-lang.org/std/iter/struct.FilterMap.html
4227
4236
  */
4228
- export declare function filterMap<OldT, NewT>(array: OldT[], func: (element: OldT) => NewT | undefined): NewT[];
4237
+ export declare function filterMap<OldT, NewT>(array: OldT[] | readonly OldT[], func: (element: OldT) => NewT | undefined): NewT[];
4229
4238
 
4230
4239
  /**
4231
4240
  * Helper function for non-TypeScript users to find an element in an array.
@@ -7696,8 +7705,16 @@ export declare function inStartingRoom(): boolean;
7696
7705
  * Helper function to return an array of integers with the specified range, inclusive on both ends.
7697
7706
  * (The "i" in the function name stands for inclusive.)
7698
7707
  *
7699
- * - For example, `iRange(1, 3)` will return `[1, 2, 3]`.
7700
- * - For example, `iRange(2)` will return `[0, 1, 2]`.
7708
+ * If the end is lower than the start, then the range will be reversed.
7709
+ *
7710
+ * For example:
7711
+ *
7712
+ * - `iRange(2)` returns `[0, 1, 2]`.
7713
+ * - `iRange(3)` returns `[0, 1, 2, 3]`.
7714
+ * - `iRange(-3)` returns `[0, -1, -2, -3]`.
7715
+ * - `iRange(1, 3)` returns `[1, 2, 3]`.
7716
+ * - `iRange(2, 5)` returns `[2, 3, 4, 5]`.
7717
+ * - `iRange(5, 2)` returns `[5, 4, 3, 2]`.
7701
7718
  *
7702
7719
  * @param start The integer to start at.
7703
7720
  * @param end Optional. The integer to end at. If not specified, then the start will be 0 and the
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 31.2.2
3
+ isaacscript-common 31.3.0
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -16582,14 +16582,24 @@ function ____exports.eRange(self, start, ____end, increment)
16582
16582
  increment = 1
16583
16583
  end
16584
16584
  if ____end == nil then
16585
- return ____exports.eRange(nil, 0, start)
16585
+ return ____exports.eRange(nil, 0, start, increment)
16586
16586
  end
16587
16587
  local array = {}
16588
- do
16589
- local i = start
16590
- while i < ____end do
16591
- array[#array + 1] = i
16592
- i = i + increment
16588
+ if start < ____end then
16589
+ do
16590
+ local i = start
16591
+ while i < ____end do
16592
+ array[#array + 1] = i
16593
+ i = i + increment
16594
+ end
16595
+ end
16596
+ else
16597
+ do
16598
+ local i = start
16599
+ while i > ____end do
16600
+ array[#array + 1] = i
16601
+ i = i - increment
16602
+ end
16593
16603
  end
16594
16604
  end
16595
16605
  return array
@@ -16606,9 +16616,10 @@ function ____exports.iRange(self, start, ____end, increment)
16606
16616
  increment = 1
16607
16617
  end
16608
16618
  if ____end == nil then
16609
- return ____exports.iRange(nil, 0, start)
16619
+ return ____exports.iRange(nil, 0, start, increment)
16610
16620
  end
16611
- local exclusiveEnd = ____end + 1
16621
+ local rangeIncreasing = start <= ____end
16622
+ local exclusiveEnd = rangeIncreasing and ____end + 1 or ____end - 1
16612
16623
  return ____exports.eRange(nil, start, exclusiveEnd, increment)
16613
16624
  end
16614
16625
  function ____exports.inRange(self, num, start, ____end)
@@ -17022,7 +17033,8 @@ end
17022
17033
  function ____exports.sumArray(self, array)
17023
17034
  return __TS__ArrayReduce(
17024
17035
  array,
17025
- function(____, accumulator, element) return accumulator + element end
17036
+ function(____, accumulator, element) return accumulator + element end,
17037
+ 0
17026
17038
  )
17027
17039
  end
17028
17040
  return ____exports
@@ -22365,10 +22377,10 @@ local ____isaac_2Dtypescript_2Ddefinitions = require("lua_modules.isaac-typescri
22365
22377
  local Direction = ____isaac_2Dtypescript_2Ddefinitions.Direction
22366
22378
  local ____direction = require("src.functions.direction")
22367
22379
  local directionToVector = ____direction.directionToVector
22368
- function ____exports.clamp(self, x, min, max)
22380
+ function ____exports.clamp(self, num, min, max)
22369
22381
  return math.max(
22370
22382
  min,
22371
- math.min(x, max)
22383
+ math.min(num, max)
22372
22384
  )
22373
22385
  end
22374
22386
  function ____exports.getAngleDifference(self, angle1, angle2)
@@ -53866,10 +53878,23 @@ return ____exports
53866
53878
  end,
53867
53879
  ["src.types.TupleWithLengthBetween"] = function(...)
53868
53880
  local ____exports = {}
53881
+ local zeroOneTwo = {}
53882
+ local oneOneTwo = {"1"}
53883
+ local twoOneTwo = {"1", "2"}
53884
+ local threeOneTwo = {"1", "2", "3"}
53869
53885
  return ____exports
53870
53886
  end,
53871
53887
  ["src.types.TupleWithMaxLength"] = function(...)
53872
53888
  local ____exports = {}
53889
+ local zeroZero = {}
53890
+ local oneZero = {"1"}
53891
+ local zeroOne = {}
53892
+ local oneOne = {"1"}
53893
+ local twoOne = {"1", "2"}
53894
+ local zeroTwo = {}
53895
+ local oneTwo = {"1"}
53896
+ local twoTwo = {"1", "2"}
53897
+ local threeTwo = {"1", "2", "3"}
53873
53898
  return ____exports
53874
53899
  end,
53875
53900
  ["src.types.UnionToIntersection"] = function(...)
@@ -98,13 +98,13 @@ export declare function emptyArray<T>(array: T[]): void;
98
98
  * function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
99
99
  * this function cannot be used in situations where `undefined` can be a valid array element.)
100
100
  *
101
- * This function is useful because a map will always produce an array with the same amount of
102
- * elements as the original array.
101
+ * This function is useful because the `Array.map` method will always produce an array with the same
102
+ * amount of elements as the original array.
103
103
  *
104
104
  * This is named `filterMap` after the Rust function:
105
105
  * https://doc.rust-lang.org/std/iter/struct.FilterMap.html
106
106
  */
107
- export declare function filterMap<OldT, NewT>(array: OldT[], func: (element: OldT) => NewT | undefined): NewT[];
107
+ export declare function filterMap<OldT, NewT>(array: OldT[] | readonly OldT[], func: (element: OldT) => NewT | undefined): NewT[];
108
108
  /**
109
109
  * Helper function to get all possible combinations of the given array. This includes the
110
110
  * combination of an empty array.
@@ -1 +1 @@
1
- {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/functions/array.ts"],"names":[],"mappings":";;;AAMA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,MAAM,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,EAC1B,MAAM,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,GACzB,OAAO,CAST;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,aAAa,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,EACjC,GAAG,gBAAgB,EAAE,CAAC,EAAE,GACvB,CAAC,EAAE,CAIL;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,aAAa,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,EACjC,GAAG,gBAAgB,EAAE,CAAC,EAAE,GACvB,CAAC,EAAE,CAIL;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,KAAK,EAAE,CAAC,EAAE,EACV,GAAG,gBAAgB,EAAE,CAAC,EAAE,GACvB,OAAO,CAcT;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,KAAK,EAAE,CAAC,EAAE,EACV,GAAG,gBAAgB,EAAE,CAAC,EAAE,GACvB,OAAO,CAWT;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,aAAa,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,EACjC,GAAG,eAAe,EAAE,GAAG,EAAE,GACxB,CAAC,EAAE,CAWL;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EACvC,KAAK,EAAE,CAAC,EAAE,EACV,G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AE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,EAChC,WAAW,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,CAAC,GACrC,OAAO,CAET;AAED,4EAA4E;AAC5E,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAIjE;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,aAAa,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,EACjC,SAAS,GAAE,IAAI,GAAG,GAAqB,GACtC,CAAC,EAAE,CAKL;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,KAAK,EAAE,CAAC,EAAE,EACV,SAAS,GAAE,IAAI,GAAG,GAAqB,GACtC,IAAI,CAWN;AAED,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE,GAAG,MAAM,CAEpE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAM3E"}
@@ -294,8 +294,8 @@ end
294
294
  -- function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
295
295
  -- this function cannot be used in situations where `undefined` can be a valid array element.)
296
296
  --
297
- -- This function is useful because a map will always produce an array with the same amount of
298
- -- elements as the original array.
297
+ -- This function is useful because the `Array.map` method will always produce an array with the same
298
+ -- amount of elements as the original array.
299
299
  --
300
300
  -- This is named `filterMap` after the Rust function:
301
301
  -- https://doc.rust-lang.org/std/iter/struct.FilterMap.html
@@ -516,7 +516,8 @@ end
516
516
  function ____exports.sumArray(self, array)
517
517
  return __TS__ArrayReduce(
518
518
  array,
519
- function(____, accumulator, element) return accumulator + element end
519
+ function(____, accumulator, element) return accumulator + element end,
520
+ 0
520
521
  )
521
522
  end
522
523
  return ____exports
@@ -1,11 +1,11 @@
1
1
  import { Direction } from "isaac-typescript-definitions";
2
2
  /**
3
- * Helper function to normalize an integer.
3
+ * Helper function to normalize a number, ensuring that it is within a certain range.
4
4
  *
5
- * - If `x` is less than `min`, then it will be clamped to `min`.
6
- * - If `x` is greater than `max`, then it will be clamped to `max`.
5
+ * - If `num` is less than `min`, then it will be clamped to `min`.
6
+ * - If `num` is greater than `max`, then it will be clamped to `max`.
7
7
  */
8
- export declare function clamp(x: int, min: int, max: int): int;
8
+ export declare function clamp(num: int, min: int, max: int): int;
9
9
  export declare function getAngleDifference(angle1: float, angle2: float): float;
10
10
  /**
11
11
  * Helper function to get an array of equidistant points on the circumference around a circle.
@@ -1 +1 @@
1
- {"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../src/functions/math.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAGzD;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,CAErD;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,KAAK,CAGtE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,GAAG,EACd,WAAW,SAAI,EACf,WAAW,SAAI,EACf,gBAAgB,YAAe,GAC9B,MAAM,EAAE,CAaV;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAClB,OAAO,CAOT;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,KAAK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zB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAClB,OAAO,CAOT;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,KAAK,EACnB,gBAAgB,EAAE,MAAM,EACxB,oBAAoB,EAAE,MAAM,GAC3B,OAAO,CAgBT;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAGxC;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAGvC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,GAAG,MAAM,CAE7D;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,KAAK,GACb,MAAM,CAER;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,gBAAgB,SAAI,GAAG,KAAK,CAG7D;AAED,wEAAwE;AACxE,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAUnC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtC"}
@@ -3,14 +3,14 @@ local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitio
3
3
  local Direction = ____isaac_2Dtypescript_2Ddefinitions.Direction
4
4
  local ____direction = require("src.functions.direction")
5
5
  local directionToVector = ____direction.directionToVector
6
- --- Helper function to normalize an integer.
6
+ --- Helper function to normalize a number, ensuring that it is within a certain range.
7
7
  --
8
- -- - If `x` is less than `min`, then it will be clamped to `min`.
9
- -- - If `x` is greater than `max`, then it will be clamped to `max`.
10
- function ____exports.clamp(self, x, min, max)
8
+ -- - If `num` is less than `min`, then it will be clamped to `min`.
9
+ -- - If `num` is greater than `max`, then it will be clamped to `max`.
10
+ function ____exports.clamp(self, num, min, max)
11
11
  return math.max(
12
12
  min,
13
- math.min(x, max)
13
+ math.min(num, max)
14
14
  )
15
15
  end
16
16
  function ____exports.getAngleDifference(self, angle1, angle2)
@@ -1,10 +1,19 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  /**
3
3
  * Helper function to return an array of integers with the specified range, inclusive on the lower
4
- * end and exclusive on the high end. (The "e" in the function name stands for exclusive.)
4
+ * end and exclusive on the high end. (The "e" in the function name stands for exclusive.) Thus,
5
+ * this function works in a similar way as the built-in `range` function from Python.
5
6
  *
6
- * - For example, `eRange(1, 3)` will return `[1, 2]`.
7
- * - For example, `eRange(2)` will return `[0, 1]`.
7
+ * If the end is lower than the start, then the range will be reversed.
8
+ *
9
+ * For example:
10
+ *
11
+ * - `eRange(2)` returns `[0, 1]`.
12
+ * - `eRange(3)` returns `[0, 1, 2]`.
13
+ * - `eRange(-3)` returns `[0, -1, -2]`.
14
+ * - `eRange(1, 3)` returns `[1, 2]`.
15
+ * - `eRange(2, 5)` returns `[2, 3, 4]`.
16
+ * - `eRange(5, 2)` returns `[5, 4, 3]`.
8
17
  *
9
18
  * @param start The integer to start at.
10
19
  * @param end Optional. The integer to end at. If not specified, then the start will be 0 and the
@@ -21,8 +30,16 @@ export declare function getTraversalDescription(key: unknown, traversalDescripti
21
30
  * Helper function to return an array of integers with the specified range, inclusive on both ends.
22
31
  * (The "i" in the function name stands for inclusive.)
23
32
  *
24
- * - For example, `iRange(1, 3)` will return `[1, 2, 3]`.
25
- * - For example, `iRange(2)` will return `[0, 1, 2]`.
33
+ * If the end is lower than the start, then the range will be reversed.
34
+ *
35
+ * For example:
36
+ *
37
+ * - `iRange(2)` returns `[0, 1, 2]`.
38
+ * - `iRange(3)` returns `[0, 1, 2, 3]`.
39
+ * - `iRange(-3)` returns `[0, -1, -2, -3]`.
40
+ * - `iRange(1, 3)` returns `[1, 2, 3]`.
41
+ * - `iRange(2, 5)` returns `[2, 3, 4, 5]`.
42
+ * - `iRange(5, 2)` returns `[5, 4, 3, 2]`.
26
43
  *
27
44
  * @param start The integer to start at.
28
45
  * @param end Optional. The integer to end at. If not specified, then the start will be 0 and the
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/functions/utils.ts"],"names":[],"mappings":";AAMA;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,SAAS,SAAI,GAAG,GAAG,EAAE,CAWlE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,OAAO,EACZ,oBAAoB,EAAE,MAAM,GAC3B,MAAM,CAQR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,SAAS,SAAI,GAAG,GAAG,EAAE,CAOlE;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAE/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAMvC;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAI5C;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAetC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI,CAI3D;AAED;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAG"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/functions/utils.ts"],"names":[],"mappings":";AAMA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,SAAS,SAAI,GAAG,GAAG,EAAE,CAkBlE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,OAAO,EACZ,oBAAoB,EAAE,MAAM,GAC3B,MAAM,CAQR;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,SAAS,SAAI,GAAG,GAAG,EAAE,CAQlE;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAE/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAMvC;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAI5C;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAetC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI,CAI3D;AAED;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAG"}
@@ -13,10 +13,19 @@ local getAllPlayers = ____playerIndex.getAllPlayers
13
13
  local ____types = require("src.functions.types")
14
14
  local isFunction = ____types.isFunction
15
15
  --- Helper function to return an array of integers with the specified range, inclusive on the lower
16
- -- end and exclusive on the high end. (The "e" in the function name stands for exclusive.)
16
+ -- end and exclusive on the high end. (The "e" in the function name stands for exclusive.) Thus,
17
+ -- this function works in a similar way as the built-in `range` function from Python.
17
18
  --
18
- -- - For example, `eRange(1, 3)` will return `[1, 2]`.
19
- -- - For example, `eRange(2)` will return `[0, 1]`.
19
+ -- If the end is lower than the start, then the range will be reversed.
20
+ --
21
+ -- For example:
22
+ --
23
+ -- - `eRange(2)` returns `[0, 1]`.
24
+ -- - `eRange(3)` returns `[0, 1, 2]`.
25
+ -- - `eRange(-3)` returns `[0, -1, -2]`.
26
+ -- - `eRange(1, 3)` returns `[1, 2]`.
27
+ -- - `eRange(2, 5)` returns `[2, 3, 4]`.
28
+ -- - `eRange(5, 2)` returns `[5, 4, 3]`.
20
29
  --
21
30
  -- @param start The integer to start at.
22
31
  -- @param end Optional. The integer to end at. If not specified, then the start will be 0 and the
@@ -27,14 +36,24 @@ function ____exports.eRange(self, start, ____end, increment)
27
36
  increment = 1
28
37
  end
29
38
  if ____end == nil then
30
- return ____exports.eRange(nil, 0, start)
39
+ return ____exports.eRange(nil, 0, start, increment)
31
40
  end
32
41
  local array = {}
33
- do
34
- local i = start
35
- while i < ____end do
36
- array[#array + 1] = i
37
- i = i + increment
42
+ if start < ____end then
43
+ do
44
+ local i = start
45
+ while i < ____end do
46
+ array[#array + 1] = i
47
+ i = i + increment
48
+ end
49
+ end
50
+ else
51
+ do
52
+ local i = start
53
+ while i > ____end do
54
+ array[#array + 1] = i
55
+ i = i - increment
56
+ end
38
57
  end
39
58
  end
40
59
  return array
@@ -51,8 +70,16 @@ end
51
70
  --- Helper function to return an array of integers with the specified range, inclusive on both ends.
52
71
  -- (The "i" in the function name stands for inclusive.)
53
72
  --
54
- -- - For example, `iRange(1, 3)` will return `[1, 2, 3]`.
55
- -- - For example, `iRange(2)` will return `[0, 1, 2]`.
73
+ -- If the end is lower than the start, then the range will be reversed.
74
+ --
75
+ -- For example:
76
+ --
77
+ -- - `iRange(2)` returns `[0, 1, 2]`.
78
+ -- - `iRange(3)` returns `[0, 1, 2, 3]`.
79
+ -- - `iRange(-3)` returns `[0, -1, -2, -3]`.
80
+ -- - `iRange(1, 3)` returns `[1, 2, 3]`.
81
+ -- - `iRange(2, 5)` returns `[2, 3, 4, 5]`.
82
+ -- - `iRange(5, 2)` returns `[5, 4, 3, 2]`.
56
83
  --
57
84
  -- @param start The integer to start at.
58
85
  -- @param end Optional. The integer to end at. If not specified, then the start will be 0 and the
@@ -63,9 +90,10 @@ function ____exports.iRange(self, start, ____end, increment)
63
90
  increment = 1
64
91
  end
65
92
  if ____end == nil then
66
- return ____exports.iRange(nil, 0, start)
93
+ return ____exports.iRange(nil, 0, start, increment)
67
94
  end
68
- local exclusiveEnd = ____end + 1
95
+ local rangeIncreasing = start <= ____end
96
+ local exclusiveEnd = rangeIncreasing and ____end + 1 or ____end - 1
69
97
  return ____exports.eRange(nil, start, exclusiveEnd, increment)
70
98
  end
71
99
  --- Helper function to check if a variable is within a certain range, inclusive on both ends.
@@ -1,2 +1,6 @@
1
1
  local ____exports = {}
2
+ local zeroOneTwo = {}
3
+ local oneOneTwo = {"1"}
4
+ local twoOneTwo = {"1", "2"}
5
+ local threeOneTwo = {"1", "2", "3"}
2
6
  return ____exports
@@ -1,2 +1,11 @@
1
1
  local ____exports = {}
2
+ local zeroZero = {}
3
+ local oneZero = {"1"}
4
+ local zeroOne = {}
5
+ local oneOne = {"1"}
6
+ local twoOne = {"1", "2"}
7
+ local zeroTwo = {}
8
+ local oneTwo = {"1"}
9
+ local twoTwo = {"1", "2"}
10
+ local threeTwo = {"1", "2", "3"}
2
11
  return ____exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "31.2.2",
3
+ "version": "31.3.0",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -237,14 +237,14 @@ export function emptyArray<T>(array: T[]): void {
237
237
  * function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
238
238
  * this function cannot be used in situations where `undefined` can be a valid array element.)
239
239
  *
240
- * This function is useful because a map will always produce an array with the same amount of
241
- * elements as the original array.
240
+ * This function is useful because the `Array.map` method will always produce an array with the same
241
+ * amount of elements as the original array.
242
242
  *
243
243
  * This is named `filterMap` after the Rust function:
244
244
  * https://doc.rust-lang.org/std/iter/struct.FilterMap.html
245
245
  */
246
246
  export function filterMap<OldT, NewT>(
247
- array: OldT[],
247
+ array: OldT[] | readonly OldT[],
248
248
  func: (element: OldT) => NewT | undefined,
249
249
  ): NewT[] {
250
250
  const newArray: NewT[] = [];
@@ -560,7 +560,7 @@ export function shuffleArrayInPlace<T>(
560
560
 
561
561
  /** Helper function to sum every value in an array together. */
562
562
  export function sumArray(array: number[] | readonly number[]): number {
563
- return array.reduce((accumulator, element) => accumulator + element);
563
+ return array.reduce((accumulator, element) => accumulator + element, 0);
564
564
  }
565
565
 
566
566
  /**
@@ -2,13 +2,13 @@ import { Direction } from "isaac-typescript-definitions";
2
2
  import { directionToVector } from "./direction";
3
3
 
4
4
  /**
5
- * Helper function to normalize an integer.
5
+ * Helper function to normalize a number, ensuring that it is within a certain range.
6
6
  *
7
- * - If `x` is less than `min`, then it will be clamped to `min`.
8
- * - If `x` is greater than `max`, then it will be clamped to `max`.
7
+ * - If `num` is less than `min`, then it will be clamped to `min`.
8
+ * - If `num` is greater than `max`, then it will be clamped to `max`.
9
9
  */
10
- export function clamp(x: int, min: int, max: int): int {
11
- return Math.max(min, Math.min(x, max));
10
+ export function clamp(num: int, min: int, max: int): int {
11
+ return Math.max(min, Math.min(num, max));
12
12
  }
13
13
 
14
14
  export function getAngleDifference(angle1: float, angle2: float): float {
@@ -6,10 +6,19 @@ import { isFunction } from "./types";
6
6
 
7
7
  /**
8
8
  * Helper function to return an array of integers with the specified range, inclusive on the lower
9
- * end and exclusive on the high end. (The "e" in the function name stands for exclusive.)
9
+ * end and exclusive on the high end. (The "e" in the function name stands for exclusive.) Thus,
10
+ * this function works in a similar way as the built-in `range` function from Python.
10
11
  *
11
- * - For example, `eRange(1, 3)` will return `[1, 2]`.
12
- * - For example, `eRange(2)` will return `[0, 1]`.
12
+ * If the end is lower than the start, then the range will be reversed.
13
+ *
14
+ * For example:
15
+ *
16
+ * - `eRange(2)` returns `[0, 1]`.
17
+ * - `eRange(3)` returns `[0, 1, 2]`.
18
+ * - `eRange(-3)` returns `[0, -1, -2]`.
19
+ * - `eRange(1, 3)` returns `[1, 2]`.
20
+ * - `eRange(2, 5)` returns `[2, 3, 4]`.
21
+ * - `eRange(5, 2)` returns `[5, 4, 3]`.
13
22
  *
14
23
  * @param start The integer to start at.
15
24
  * @param end Optional. The integer to end at. If not specified, then the start will be 0 and the
@@ -18,12 +27,19 @@ import { isFunction } from "./types";
18
27
  */
19
28
  export function eRange(start: int, end?: int, increment = 1): int[] {
20
29
  if (end === undefined) {
21
- return eRange(0, start);
30
+ return eRange(0, start, increment);
22
31
  }
23
32
 
24
33
  const array: int[] = [];
25
- for (let i = start; i < end; i += increment) {
26
- array.push(i);
34
+
35
+ if (start < end) {
36
+ for (let i = start; i < end; i += increment) {
37
+ array.push(i);
38
+ }
39
+ } else {
40
+ for (let i = start; i > end; i -= increment) {
41
+ array.push(i);
42
+ }
27
43
  }
28
44
 
29
45
  return array;
@@ -50,8 +66,16 @@ export function getTraversalDescription(
50
66
  * Helper function to return an array of integers with the specified range, inclusive on both ends.
51
67
  * (The "i" in the function name stands for inclusive.)
52
68
  *
53
- * - For example, `iRange(1, 3)` will return `[1, 2, 3]`.
54
- * - For example, `iRange(2)` will return `[0, 1, 2]`.
69
+ * If the end is lower than the start, then the range will be reversed.
70
+ *
71
+ * For example:
72
+ *
73
+ * - `iRange(2)` returns `[0, 1, 2]`.
74
+ * - `iRange(3)` returns `[0, 1, 2, 3]`.
75
+ * - `iRange(-3)` returns `[0, -1, -2, -3]`.
76
+ * - `iRange(1, 3)` returns `[1, 2, 3]`.
77
+ * - `iRange(2, 5)` returns `[2, 3, 4, 5]`.
78
+ * - `iRange(5, 2)` returns `[5, 4, 3, 2]`.
55
79
  *
56
80
  * @param start The integer to start at.
57
81
  * @param end Optional. The integer to end at. If not specified, then the start will be 0 and the
@@ -60,10 +84,11 @@ export function getTraversalDescription(
60
84
  */
61
85
  export function iRange(start: int, end?: int, increment = 1): int[] {
62
86
  if (end === undefined) {
63
- return iRange(0, start);
87
+ return iRange(0, start, increment);
64
88
  }
65
89
 
66
- const exclusiveEnd = end + 1;
90
+ const rangeIncreasing = start <= end;
91
+ const exclusiveEnd = rangeIncreasing ? end + 1 : end - 1;
67
92
  return eRange(start, exclusiveEnd, increment);
68
93
  }
69
94
 
@@ -13,3 +13,31 @@ export type TupleWithLengthBetween<
13
13
  > = (T[] | readonly T[]) & {
14
14
  length: Range<MinLength, MaxLength>;
15
15
  };
16
+
17
+ // -----
18
+ // Tests
19
+ // -----
20
+
21
+ /* eslint-disable @typescript-eslint/no-unused-vars */
22
+ /* eslint-disable isaacscript/require-unannotated-const-assertions */
23
+
24
+ // @ts-expect-error Tuple of length 0 with min length 1 and max length 2.
25
+ const zeroOneTwo: TupleWithLengthBetween<string, 1, 2> = [] as const;
26
+
27
+ // Tuple of length 1 with min length 1 and max length 2.
28
+ const oneOneTwo: TupleWithLengthBetween<string, 1, 2> = ["1"] as const;
29
+
30
+ // Tuple of length 2 with min length 1 and max length 2.
31
+ const twoOneTwo: TupleWithLengthBetween<string, 1, 2> = ["1", "2"] as const;
32
+
33
+ // @ts-expect-error Tuple of length 3 with min length 1 and max length 2.
34
+ const threeOneTwo: TupleWithLengthBetween<string, 1, 2> = [
35
+ "1",
36
+ "2",
37
+ "3",
38
+ ] as const;
39
+
40
+ /* eslint-enable @typescript-eslint/no-unused-vars */
41
+ /* eslint-enable isaacscript/require-unannotated-const-assertions */
42
+
43
+ // See "TupleWithMaxLength.ts" for more tests.
@@ -11,3 +11,40 @@ export type TupleWithMaxLength<T, MaxLength extends number> = (
11
11
  ) & {
12
12
  length: Range<0, MaxLength>;
13
13
  };
14
+
15
+ // -----
16
+ // Tests
17
+ // -----
18
+
19
+ /* eslint-disable @typescript-eslint/no-unused-vars */
20
+ /* eslint-disable isaacscript/require-unannotated-const-assertions */
21
+
22
+ // Tuple of length 0 with max length 0.
23
+ const zeroZero: TupleWithMaxLength<string, 0> = [] as const;
24
+
25
+ // @ts-expect-error Tuple of length 1 with max length 0.
26
+ const oneZero: TupleWithMaxLength<string, 0> = ["1"] as const;
27
+
28
+ // Tuple of length 0 with max length 1.
29
+ const zeroOne: TupleWithMaxLength<string, 1> = [] as const;
30
+
31
+ // Tuple of length 1 with max length 1.
32
+ const oneOne: TupleWithMaxLength<string, 1> = ["1"] as const;
33
+
34
+ // @ts-expect-error Tuple of length 2 with max length 1.
35
+ const twoOne: TupleWithMaxLength<string, 1> = ["1", "2"] as const;
36
+
37
+ // Tuple of length 0 with max length 2.
38
+ const zeroTwo: TupleWithMaxLength<string, 2> = [] as const;
39
+
40
+ // Tuple of length 1 with max length 2.
41
+ const oneTwo: TupleWithMaxLength<string, 2> = ["1"] as const;
42
+
43
+ // Tuple of length 2 with max length 2.
44
+ const twoTwo: TupleWithMaxLength<string, 2> = ["1", "2"] as const;
45
+
46
+ // @ts-expect-error Tuple of length 3 with max length 2.
47
+ const threeTwo: TupleWithMaxLength<string, 2> = ["1", "2", "3"] as const;
48
+
49
+ /* eslint-enable @typescript-eslint/no-unused-vars */
50
+ /* eslint-enable isaacscript/require-unannotated-const-assertions */