isaacscript-common 31.2.4 → 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.
- package/dist/index.rollup.d.ts +28 -11
- package/dist/isaacscript-common.lua +24 -12
- package/dist/src/functions/array.d.ts +2 -2
- package/dist/src/functions/array.lua +4 -3
- package/dist/src/functions/math.d.ts +4 -4
- package/dist/src/functions/math.d.ts.map +1 -1
- package/dist/src/functions/math.lua +5 -5
- package/dist/src/functions/utils.d.ts +22 -5
- package/dist/src/functions/utils.d.ts.map +1 -1
- package/dist/src/functions/utils.lua +41 -13
- package/package.json +1 -1
- package/src/functions/array.ts +3 -3
- package/src/functions/math.ts +5 -5
- package/src/functions/utils.ts +35 -10
package/dist/index.rollup.d.ts
CHANGED
|
@@ -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
|
|
1473
|
+
* Helper function to normalize a number, ensuring that it is within a certain range.
|
|
1474
1474
|
*
|
|
1475
|
-
* - If `
|
|
1476
|
-
* - If `
|
|
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(
|
|
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
|
-
*
|
|
4059
|
-
*
|
|
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
|
|
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
|
-
*
|
|
7700
|
-
*
|
|
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.
|
|
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
|
-
|
|
16589
|
-
|
|
16590
|
-
|
|
16591
|
-
|
|
16592
|
-
|
|
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
|
|
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,
|
|
22380
|
+
function ____exports.clamp(self, num, min, max)
|
|
22369
22381
|
return math.max(
|
|
22370
22382
|
min,
|
|
22371
|
-
math.min(
|
|
22383
|
+
math.min(num, max)
|
|
22372
22384
|
)
|
|
22373
22385
|
end
|
|
22374
22386
|
function ____exports.getAngleDifference(self, angle1, angle2)
|
|
@@ -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
|
|
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
|
|
@@ -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
|
|
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
|
|
3
|
+
* Helper function to normalize a number, ensuring that it is within a certain range.
|
|
4
4
|
*
|
|
5
|
-
* - If `
|
|
6
|
-
* - If `
|
|
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(
|
|
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,
|
|
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,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,CAEvD;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,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
|
|
6
|
+
--- Helper function to normalize a number, ensuring that it is within a certain range.
|
|
7
7
|
--
|
|
8
|
-
-- - If `
|
|
9
|
-
-- - If `
|
|
10
|
-
function ____exports.clamp(self,
|
|
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(
|
|
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
|
-
*
|
|
7
|
-
*
|
|
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
|
-
*
|
|
25
|
-
*
|
|
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
|
|
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
|
-
--
|
|
19
|
-
--
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
--
|
|
55
|
-
--
|
|
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
|
|
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
package/src/functions/array.ts
CHANGED
|
@@ -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
|
|
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
|
|
@@ -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
|
/**
|
package/src/functions/math.ts
CHANGED
|
@@ -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
|
|
5
|
+
* Helper function to normalize a number, ensuring that it is within a certain range.
|
|
6
6
|
*
|
|
7
|
-
* - If `
|
|
8
|
-
* - If `
|
|
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(
|
|
11
|
-
return Math.max(min, Math.min(
|
|
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 {
|
package/src/functions/utils.ts
CHANGED
|
@@ -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
|
-
*
|
|
12
|
-
*
|
|
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
|
-
|
|
26
|
-
|
|
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
|
-
*
|
|
54
|
-
*
|
|
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
|
|
90
|
+
const rangeIncreasing = start <= end;
|
|
91
|
+
const exclusiveEnd = rangeIncreasing ? end + 1 : end - 1;
|
|
67
92
|
return eRange(start, exclusiveEnd, increment);
|
|
68
93
|
}
|
|
69
94
|
|