isaacscript-common 31.2.4 → 31.3.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.
@@ -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,8 +4228,8 @@ 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
@@ -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.4
3
+ isaacscript-common 31.3.1
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)
@@ -16923,15 +16934,13 @@ function ____exports.getRandomArrayElement(self, array, seedOrRNG, exceptions)
16923
16934
  if #array == 0 then
16924
16935
  error("Failed to get a random array element since the provided array is empty.")
16925
16936
  end
16926
- if #exceptions > 0 then
16927
- array = ____exports.arrayRemove(
16928
- nil,
16929
- array,
16930
- table.unpack(exceptions)
16931
- )
16932
- end
16933
- local randomIndex = ____exports.getRandomArrayIndex(nil, array, seedOrRNG)
16934
- local randomElement = array[randomIndex + 1]
16937
+ local arrayToUse = #exceptions > 0 and ____exports.arrayRemove(
16938
+ nil,
16939
+ array,
16940
+ table.unpack(exceptions)
16941
+ ) or array
16942
+ local randomIndex = ____exports.getRandomArrayIndex(nil, arrayToUse, seedOrRNG)
16943
+ local randomElement = arrayToUse[randomIndex + 1]
16935
16944
  if randomElement == nil then
16936
16945
  error(("Failed to get a random array element since the random index of " .. tostring(randomIndex)) .. " was not valid.")
16937
16946
  end
@@ -17022,7 +17031,8 @@ end
17022
17031
  function ____exports.sumArray(self, array)
17023
17032
  return __TS__ArrayReduce(
17024
17033
  array,
17025
- function(____, accumulator, element) return accumulator + element end
17034
+ function(____, accumulator, element) return accumulator + element end,
17035
+ 0
17026
17036
  )
17027
17037
  end
17028
17038
  return ____exports
@@ -22365,10 +22375,10 @@ local ____isaac_2Dtypescript_2Ddefinitions = require("lua_modules.isaac-typescri
22365
22375
  local Direction = ____isaac_2Dtypescript_2Ddefinitions.Direction
22366
22376
  local ____direction = require("src.functions.direction")
22367
22377
  local directionToVector = ____direction.directionToVector
22368
- function ____exports.clamp(self, x, min, max)
22378
+ function ____exports.clamp(self, num, min, max)
22369
22379
  return math.max(
22370
22380
  min,
22371
- math.min(x, max)
22381
+ math.min(num, max)
22372
22382
  )
22373
22383
  end
22374
22384
  function ____exports.getAngleDifference(self, angle1, angle2)
@@ -42321,7 +42331,7 @@ function spawnFloorEntity(self, customStage, rng)
42321
42331
  sprite:Load(ISAACSCRIPT_CUSTOM_STAGE_GFX_PATH .. "/floor-backdrop.anm2", false)
42322
42332
  local numFloorLayers = getNumFloorLayers(nil, roomShape)
42323
42333
  if numFloorLayers ~= nil then
42324
- for ____, layerID in ipairs(eRange(nil, 0, numFloorLayers)) do
42334
+ for ____, layerID in ipairs(eRange(nil, numFloorLayers)) do
42325
42335
  local wallPNGPath = getBackdropPNGPath(nil, customStage, BackdropKind.WALL, rng)
42326
42336
  sprite:ReplaceSpritesheet(layerID, wallPNGPath)
42327
42337
  end
@@ -100,7 +100,7 @@ function spawnFloorEntity(self, customStage, rng)
100
100
  sprite:Load(ISAACSCRIPT_CUSTOM_STAGE_GFX_PATH .. "/floor-backdrop.anm2", false)
101
101
  local numFloorLayers = getNumFloorLayers(nil, roomShape)
102
102
  if numFloorLayers ~= nil then
103
- for ____, layerID in ipairs(eRange(nil, 0, numFloorLayers)) do
103
+ for ____, layerID in ipairs(eRange(nil, numFloorLayers)) do
104
104
  local wallPNGPath = getBackdropPNGPath(nil, customStage, BackdropKind.WALL, rng)
105
105
  sprite:ReplaceSpritesheet(layerID, wallPNGPath)
106
106
  end
@@ -98,8 +98,8 @@ 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
@@ -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;;;;;;;;;;;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@@ 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
@@ -388,15 +388,13 @@ function ____exports.getRandomArrayElement(self, array, seedOrRNG, exceptions)
388
388
  if #array == 0 then
389
389
  error("Failed to get a random array element since the provided array is empty.")
390
390
  end
391
- if #exceptions > 0 then
392
- array = ____exports.arrayRemove(
393
- nil,
394
- array,
395
- table.unpack(exceptions)
396
- )
397
- end
398
- local randomIndex = ____exports.getRandomArrayIndex(nil, array, seedOrRNG)
399
- local randomElement = array[randomIndex + 1]
391
+ local arrayToUse = #exceptions > 0 and ____exports.arrayRemove(
392
+ nil,
393
+ array,
394
+ table.unpack(exceptions)
395
+ ) or array
396
+ local randomIndex = ____exports.getRandomArrayIndex(nil, arrayToUse, seedOrRNG)
397
+ local randomElement = arrayToUse[randomIndex + 1]
400
398
  if randomElement == nil then
401
399
  error(("Failed to get a random array element since the random index of " .. tostring(randomIndex)) .. " was not valid.")
402
400
  end
@@ -516,7 +514,8 @@ end
516
514
  function ____exports.sumArray(self, array)
517
515
  return __TS__ArrayReduce(
518
516
  array,
519
- function(____, accumulator, element) return accumulator + element end
517
+ function(____, accumulator, element) return accumulator + element end,
518
+ 0
520
519
  )
521
520
  end
522
521
  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,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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AG,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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AgB,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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "31.2.4",
3
+ "version": "31.3.1",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -214,7 +214,7 @@ function spawnFloorEntity(customStage: CustomStage, rng: RNG) {
214
214
 
215
215
  const numFloorLayers = getNumFloorLayers(roomShape);
216
216
  if (numFloorLayers !== undefined) {
217
- for (const layerID of eRange(0, numFloorLayers)) {
217
+ for (const layerID of eRange(numFloorLayers)) {
218
218
  // The wall spritesheet is used for the "normal" floors.
219
219
  const wallPNGPath = getBackdropPNGPath(
220
220
  customStage,
@@ -237,8 +237,8 @@ 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
@@ -368,11 +368,10 @@ export function getRandomArrayElement<T>(
368
368
  );
369
369
  }
370
370
 
371
- if (exceptions.length > 0) {
372
- array = arrayRemove(array, ...exceptions);
373
- }
374
- const randomIndex = getRandomArrayIndex(array, seedOrRNG);
375
- const randomElement = array[randomIndex];
371
+ const arrayToUse =
372
+ exceptions.length > 0 ? arrayRemove(array, ...exceptions) : array;
373
+ const randomIndex = getRandomArrayIndex(arrayToUse, seedOrRNG);
374
+ const randomElement = arrayToUse[randomIndex];
376
375
  if (randomElement === undefined) {
377
376
  error(
378
377
  `Failed to get a random array element since the random index of ${randomIndex} was not valid.`,
@@ -560,7 +559,7 @@ export function shuffleArrayInPlace<T>(
560
559
 
561
560
  /** Helper function to sum every value in an array together. */
562
561
  export function sumArray(array: number[] | readonly number[]): number {
563
- return array.reduce((accumulator, element) => accumulator + element);
562
+ return array.reduce((accumulator, element) => accumulator + element, 0);
564
563
  }
565
564
 
566
565
  /**
@@ -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