isaacscript-common 2.0.10 → 2.0.11

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.
@@ -40,8 +40,6 @@ local ____jsonRoom = require("functions.jsonRoom")
40
40
  local getRandomJSONRoom = ____jsonRoom.getRandomJSONRoom
41
41
  local ____log = require("functions.log")
42
42
  local log = ____log.log
43
- local ____math = require("functions.math")
44
- local erange = ____math.erange
45
43
  local ____rng = require("functions.rng")
46
44
  local getRandomSeed = ____rng.getRandomSeed
47
45
  local isRNG = ____rng.isRNG
@@ -55,6 +53,8 @@ local setRoomCleared = ____rooms.setRoomCleared
55
53
  local setRoomUncleared = ____rooms.setRoomUncleared
56
54
  local ____spawnCollectible = require("functions.spawnCollectible")
57
55
  local spawnCollectible = ____spawnCollectible.spawnCollectible
56
+ local ____utils = require("functions.utils")
57
+ local erange = ____utils.erange
58
58
  local ____exports = require("features.saveDataManager.exports")
59
59
  local saveDataManager = ____exports.saveDataManager
60
60
  function postNewRoom(self)
@@ -11,8 +11,6 @@ local __TS__ArrayMap = ____lualib.__TS__ArrayMap
11
11
  local __TS__ArraySome = ____lualib.__TS__ArraySome
12
12
  local __TS__ArrayReduce = ____lualib.__TS__ArrayReduce
13
13
  local ____exports = {}
14
- local ____math = require("functions.math")
15
- local erange = ____math.erange
16
14
  local ____random = require("functions.random")
17
15
  local getRandomInt = ____random.getRandomInt
18
16
  local ____rng = require("functions.rng")
@@ -20,6 +18,7 @@ local getRandomSeed = ____rng.getRandomSeed
20
18
  local isRNG = ____rng.isRNG
21
19
  local newRNG = ____rng.newRNG
22
20
  local ____utils = require("functions.utils")
21
+ local erange = ____utils.erange
23
22
  local ____repeat = ____utils["repeat"]
24
23
  function ____exports.getRandomArrayIndex(self, array, seedOrRNG)
25
24
  if seedOrRNG == nil then
@@ -23,13 +23,13 @@ local CARD_TYPES = ____cardTypes.CARD_TYPES
23
23
  local DEFAULT_CARD_TYPE = ____cardTypes.DEFAULT_CARD_TYPE
24
24
  local ____enums = require("functions.enums")
25
25
  local getEnumValues = ____enums.getEnumValues
26
- local ____math = require("functions.math")
27
- local irange = ____math.irange
28
26
  local ____rng = require("functions.rng")
29
27
  local getRandomSeed = ____rng.getRandomSeed
30
28
  local ____set = require("functions.set")
31
29
  local addSetsToSet = ____set.addSetsToSet
32
30
  local getRandomSetElement = ____set.getRandomSetElement
31
+ local ____utils = require("functions.utils")
32
+ local irange = ____utils.irange
33
33
  function initCardObjects(self)
34
34
  for ____, cardType in ipairs(getEnumValues(nil, ItemConfigCardType)) do
35
35
  CARD_TYPE_TO_CARDS_MAP:set(
@@ -11,12 +11,11 @@ local ____collectibles = require("functions.collectibles")
11
11
  local collectibleHasCacheFlag = ____collectibles.collectibleHasCacheFlag
12
12
  local ____enums = require("functions.enums")
13
13
  local getEnumValues = ____enums.getEnumValues
14
- local ____math = require("functions.math")
15
- local irange = ____math.irange
16
14
  local ____set = require("functions.set")
17
15
  local copySet = ____set.copySet
18
16
  local getSortedSetValues = ____set.getSortedSetValues
19
17
  local ____utils = require("functions.utils")
18
+ local irange = ____utils.irange
20
19
  local ____repeat = ____utils["repeat"]
21
20
  local CACHE_FLAG_TO_COLLECTIBLES_MAP = __TS__New(Map)
22
21
  local function initCacheFlagMap(self)
@@ -6,10 +6,10 @@ local ____cachedClasses = require("cachedClasses")
6
6
  local itemConfig = ____cachedClasses.itemConfig
7
7
  local ____constantsMax = require("constantsMax")
8
8
  local MAX_COLLECTIBLE_TYPE = ____constantsMax.MAX_COLLECTIBLE_TYPE
9
- local ____math = require("functions.math")
10
- local irange = ____math.irange
11
9
  local ____set = require("functions.set")
12
10
  local copySet = ____set.copySet
11
+ local ____utils = require("functions.utils")
12
+ local irange = ____utils.irange
13
13
  local COLLECTIBLE_SET = __TS__New(Set)
14
14
  local function initCollectibleSet(self)
15
15
  for ____, collectibleType in ipairs(irange(nil, 1, MAX_COLLECTIBLE_TYPE)) do
@@ -14,12 +14,12 @@ local ____enums = require("functions.enums")
14
14
  local getEnumValues = ____enums.getEnumValues
15
15
  local ____flag = require("functions.flag")
16
16
  local getFlagName = ____flag.getFlagName
17
- local ____math = require("functions.math")
18
- local irange = ____math.irange
19
17
  local ____player = require("functions.player")
20
18
  local getPlayerCollectibleCount = ____player.getPlayerCollectibleCount
21
19
  local ____set = require("functions.set")
22
20
  local copySet = ____set.copySet
21
+ local ____utils = require("functions.utils")
22
+ local irange = ____utils.irange
23
23
  function ____exports.collectibleHasTag(self, collectibleType, tag)
24
24
  local itemConfigItem = itemConfig:GetCollectible(collectibleType)
25
25
  if itemConfigItem == nil then
@@ -160,8 +160,8 @@ export declare function setCollectibleEmpty(collectible: EntityPickup): void;
160
160
  */
161
161
  export declare function setCollectibleSprite(collectible: EntityPickup, pngPath: string | undefined): void;
162
162
  /**
163
- * Helper function to change the collectible on a pedestal. Simply updating the SubType property is
164
- * not sufficient because the sprite will not change.
163
+ * Helper function to change the collectible on a pedestal. Simply updating the `SubType` property
164
+ * is not sufficient because the sprite will not change.
165
165
  */
166
166
  export declare function setCollectibleSubType(collectible: EntityPickup, newCollectibleType: CollectibleType | int): void;
167
167
  /**
@@ -54,6 +54,15 @@ export declare function getEnumLength<T>(transpiledEnum: T): int;
54
54
  */
55
55
  export declare function getEnumValues<T>(transpiledEnum: T): Array<T[keyof T]>;
56
56
  export declare function getLastEnumValue<T>(transpiledEnum: T): T[keyof T];
57
+ /**
58
+ * Helper function to get a random element from the provided enum.
59
+ *
60
+ * @param transpiledEnum The enum to get an element from.
61
+ * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
62
+ * `RNG.Next` method will be called. Default is `getRandomSeed()`.
63
+ * @param exceptions Optional. An array of elements to skip over if selected.
64
+ */
65
+ export declare function getRandomEnumElement<T>(transpiledEnum: T, seedOrRNG?: Seed | RNG, exceptions?: Array<T[keyof T]> | ReadonlyArray<T[keyof T]>): T[keyof T];
57
66
  /**
58
67
  * Helper function to check every value of a custom enum for -1. This is helpful as a run-time check
59
68
  * because many methods of the Isaac class return -1 if they fail.
@@ -2,6 +2,10 @@ local ____lualib = require("lualib_bundle")
2
2
  local __TS__ArraySort = ____lualib.__TS__ArraySort
3
3
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
4
4
  local ____exports = {}
5
+ local ____array = require("functions.array")
6
+ local getRandomArrayElement = ____array.getRandomArrayElement
7
+ local ____rng = require("functions.rng")
8
+ local getRandomSeed = ____rng.getRandomSeed
5
9
  function ____exports.getEnumEntries(self, transpiledEnum)
6
10
  local enumEntries = {}
7
11
  for key, value in pairs(transpiledEnum) do
@@ -59,6 +63,16 @@ function ____exports.getLastEnumValue(self, transpiledEnum)
59
63
  end
60
64
  return lastElement
61
65
  end
66
+ function ____exports.getRandomEnumElement(self, transpiledEnum, seedOrRNG, exceptions)
67
+ if seedOrRNG == nil then
68
+ seedOrRNG = getRandomSeed(nil)
69
+ end
70
+ if exceptions == nil then
71
+ exceptions = {}
72
+ end
73
+ local enumValues = ____exports.getEnumValues(nil, transpiledEnum)
74
+ return getRandomArrayElement(nil, enumValues, seedOrRNG, exceptions)
75
+ end
62
76
  function ____exports.validateCustomEnum(self, transpiledEnumName, transpiledEnum)
63
77
  for ____, ____value in ipairs(____exports.getEnumEntries(nil, transpiledEnum)) do
64
78
  local key = ____value[1]
@@ -26,12 +26,13 @@ local ____roomShapeToTopLeftWallGridIndexMap = require("maps.roomShapeToTopLeftW
26
26
  local DEFAULT_TOP_LEFT_WALL_GRID_INDEX = ____roomShapeToTopLeftWallGridIndexMap.DEFAULT_TOP_LEFT_WALL_GRID_INDEX
27
27
  local ROOM_SHAPE_TO_TOP_LEFT_WALL_GRID_INDEX_MAP = ____roomShapeToTopLeftWallGridIndexMap.ROOM_SHAPE_TO_TOP_LEFT_WALL_GRID_INDEX_MAP
28
28
  local ____math = require("functions.math")
29
- local erange = ____math.erange
30
29
  local isCircleIntersectingRectangle = ____math.isCircleIntersectingRectangle
31
30
  local ____rooms = require("functions.rooms")
32
31
  local roomUpdateSafe = ____rooms.roomUpdateSafe
33
32
  local ____sprite = require("functions.sprite")
34
33
  local clearSprite = ____sprite.clearSprite
34
+ local ____utils = require("functions.utils")
35
+ local erange = ____utils.erange
35
36
  local ____vector = require("functions.vector")
36
37
  local isVector = ____vector.isVector
37
38
  function getAllGridEntities(self)
@@ -10,12 +10,12 @@ local ControllerIndex = ____isaac_2Dtypescript_2Ddefinitions.ControllerIndex
10
10
  local Keyboard = ____isaac_2Dtypescript_2Ddefinitions.Keyboard
11
11
  local ____constants = require("constants")
12
12
  local MAX_NUM_INPUTS = ____constants.MAX_NUM_INPUTS
13
- local ____math = require("functions.math")
14
- local erange = ____math.erange
15
13
  local ____set = require("functions.set")
16
14
  local copySet = ____set.copySet
17
15
  local ____string = require("functions.string")
18
16
  local trimPrefix = ____string.trimPrefix
17
+ local ____utils = require("functions.utils")
18
+ local erange = ____utils.erange
19
19
  local MODIFIER_KEYS = {
20
20
  Keyboard.LEFT_SHIFT,
21
21
  Keyboard.LEFT_CONTROL,
@@ -1,13 +1,4 @@
1
1
  import { Direction } from "isaac-typescript-definitions";
2
- /**
3
- * Helper function to return an array with the elements from start to end. It is inclusive at the
4
- * start and exclusive at the end. (The "e" stands for exclusive.)
5
- *
6
- * For example, `erange(1, 3)` will return `[1, 2]`.
7
- *
8
- * If only one argument is specified, then it will assume that the start is 0.
9
- */
10
- export declare function erange(start: int, end?: int): int[];
11
2
  export declare function getAngleDifference(angle1: float, angle2: float): float;
12
3
  /**
13
4
  * Helper function to get an array of equidistant points on the circumference around a circle.
@@ -29,15 +20,6 @@ export declare function getCircleDiscretizedPoints(centerPos: Vector, radius: fl
29
20
  * the rectangle.
30
21
  */
31
22
  export declare function inRectangle(position: Vector, topLeft: Vector, bottomRight: Vector): boolean;
32
- /**
33
- * Helper function to return an array with the elements from start to end, inclusive. (The "i"
34
- * stands for inclusive.)
35
- *
36
- * For example, `irange(1, 3)` will return `[1, 2, 3]`.
37
- *
38
- * If only one argument is specified, then it will assume that the start is 0.
39
- */
40
- export declare function irange(start: int, end?: int): int[];
41
23
  /**
42
24
  * From: https://www.geeksforgeeks.org/check-if-any-point-overlaps-the-given-circle-and-rectangle/
43
25
  */
@@ -3,21 +3,6 @@ local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitio
3
3
  local Direction = ____isaac_2Dtypescript_2Ddefinitions.Direction
4
4
  local ____direction = require("functions.direction")
5
5
  local directionToVector = ____direction.directionToVector
6
- function ____exports.erange(self, start, ____end)
7
- if ____end == nil then
8
- ____end = start
9
- start = 0
10
- end
11
- local array = {}
12
- do
13
- local i = start
14
- while i < ____end do
15
- array[#array + 1] = i
16
- i = i + 1
17
- end
18
- end
19
- return array
20
- end
21
6
  function ____exports.getAngleDifference(self, angle1, angle2)
22
7
  local subtractedAngle = angle1 - angle2
23
8
  return (subtractedAngle + 180) % 360 - 180
@@ -51,21 +36,6 @@ end
51
36
  function ____exports.inRectangle(self, position, topLeft, bottomRight)
52
37
  return position.X >= topLeft.X and position.X <= bottomRight.X and position.Y >= topLeft.Y and position.Y <= bottomRight.Y
53
38
  end
54
- function ____exports.irange(self, start, ____end)
55
- if ____end == nil then
56
- ____end = start
57
- start = 0
58
- end
59
- local array = {}
60
- do
61
- local i = start
62
- while i <= ____end do
63
- array[#array + 1] = i
64
- i = i + 1
65
- end
66
- end
67
- return array
68
- end
69
39
  function ____exports.isCircleIntersectingRectangle(self, circleCenter, circleRadius, rectangleTopLeft, rectangleBottomRight)
70
40
  local nearestX = math.max(
71
41
  rectangleTopLeft.X,
@@ -39,8 +39,6 @@ local ____entity = require("functions.entity")
39
39
  local getEntities = ____entity.getEntities
40
40
  local ____flag = require("functions.flag")
41
41
  local hasFlag = ____flag.hasFlag
42
- local ____math = require("functions.math")
43
- local erange = ____math.erange
44
42
  local ____positionVelocity = require("functions.positionVelocity")
45
43
  local getEntityPositions = ____positionVelocity.getEntityPositions
46
44
  local getEntityVelocities = ____positionVelocity.getEntityVelocities
@@ -58,6 +56,8 @@ local getRoomStageID = ____roomData.getRoomStageID
58
56
  local getRoomSubType = ____roomData.getRoomSubType
59
57
  local ____roomShape = require("functions.roomShape")
60
58
  local getGridIndexDelta = ____roomShape.getGridIndexDelta
59
+ local ____utils = require("functions.utils")
60
+ local erange = ____utils.erange
61
61
  function ____exports.getRooms(self, includeExtraDimensionalRooms)
62
62
  if includeExtraDimensionalRooms == nil then
63
63
  includeExtraDimensionalRooms = false
@@ -4,8 +4,8 @@ local EMPTY_PNG_PATH = ____constants.EMPTY_PNG_PATH
4
4
  local VectorZero = ____constants.VectorZero
5
5
  local ____kColor = require("functions.kColor")
6
6
  local kColorEquals = ____kColor.kColorEquals
7
- local ____math = require("functions.math")
8
- local erange = ____math.erange
7
+ local ____utils = require("functions.utils")
8
+ local erange = ____utils.erange
9
9
  function ____exports.texelEquals(self, sprite1, sprite2, position, layerID)
10
10
  local kColor1 = sprite1:GetTexel(position, VectorZero, 1, layerID)
11
11
  local kColor2 = sprite2:GetTexel(position, VectorZero, 1, layerID)
@@ -11,12 +11,12 @@ local ____constantsMax = require("constantsMax")
11
11
  local MAX_TRINKET_TYPE = ____constantsMax.MAX_TRINKET_TYPE
12
12
  local ____enums = require("functions.enums")
13
13
  local getEnumValues = ____enums.getEnumValues
14
- local ____math = require("functions.math")
15
- local irange = ____math.irange
16
14
  local ____set = require("functions.set")
17
15
  local copySet = ____set.copySet
18
16
  local ____trinkets = require("functions.trinkets")
19
17
  local trinketHasCacheFlag = ____trinkets.trinketHasCacheFlag
18
+ local ____utils = require("functions.utils")
19
+ local irange = ____utils.irange
20
20
  function initCacheFlagMap(self)
21
21
  for ____, cacheFlag in ipairs(getEnumValues(nil, CacheFlag)) do
22
22
  local trinketsSet = __TS__New(Set)
@@ -6,10 +6,10 @@ local ____cachedClasses = require("cachedClasses")
6
6
  local itemConfig = ____cachedClasses.itemConfig
7
7
  local ____constantsMax = require("constantsMax")
8
8
  local MAX_TRINKET_TYPE = ____constantsMax.MAX_TRINKET_TYPE
9
- local ____math = require("functions.math")
10
- local irange = ____math.irange
11
9
  local ____set = require("functions.set")
12
10
  local copySet = ____set.copySet
11
+ local ____utils = require("functions.utils")
12
+ local irange = ____utils.irange
13
13
  local TRINKET_SET = __TS__New(Set)
14
14
  local function initTrinketSet(self)
15
15
  for ____, trinketType in ipairs(irange(nil, 1, MAX_TRINKET_TYPE)) do
@@ -35,6 +35,15 @@
35
35
  * ```
36
36
  */
37
37
  export declare const ensureAllCases: (obj: never) => never;
38
+ /**
39
+ * Helper function to return an array with the elements from start to end. It is inclusive at the
40
+ * start and exclusive at the end. (The "e" stands for exclusive.)
41
+ *
42
+ * For example, `erange(1, 3)` will return `[1, 2]`.
43
+ *
44
+ * If only one argument is specified, then it will assume that the start is 0.
45
+ */
46
+ export declare function erange(start: int, end?: int): int[];
38
47
  /**
39
48
  * Helper function to log what is happening in functions that recursively move through nested data
40
49
  * structures.
@@ -46,6 +55,15 @@ export declare function getTraversalDescription(key: unknown, traversalDescripti
46
55
  * @param hexString A hex string like "#ffffff" or "ffffff". (The "#" character is optional.)
47
56
  */
48
57
  export declare function hexToKColor(hexString: string, alpha: float): KColor;
58
+ /**
59
+ * Helper function to return an array with the elements from start to end, inclusive. (The "i"
60
+ * stands for inclusive.)
61
+ *
62
+ * For example, `irange(1, 3)` will return `[1, 2, 3]`.
63
+ *
64
+ * If only one argument is specified, then it will assume that the start is 0.
65
+ */
66
+ export declare function irange(start: int, end?: int): int[];
49
67
  /**
50
68
  * Since this is a UI element, we do not want to draw it in water reflections. `renderOffset` will
51
69
  * be a non-zero value in reflections.
@@ -8,6 +8,21 @@ local ____cachedClasses = require("cachedClasses")
8
8
  local game = ____cachedClasses.game
9
9
  local HEX_STRING_LENGTH = 6
10
10
  ____exports.ensureAllCases = function(____, obj) return obj end
11
+ function ____exports.erange(self, start, ____end)
12
+ if ____end == nil then
13
+ ____end = start
14
+ start = 0
15
+ end
16
+ local array = {}
17
+ do
18
+ local i = start
19
+ while i < ____end do
20
+ array[#array + 1] = i
21
+ i = i + 1
22
+ end
23
+ end
24
+ return array
25
+ end
11
26
  function ____exports.getTraversalDescription(self, key, traversalDescription)
12
27
  if traversalDescription ~= "" then
13
28
  traversalDescription = traversalDescription .. " --> "
@@ -38,6 +53,21 @@ function ____exports.hexToKColor(self, hexString, alpha)
38
53
  local base = 255
39
54
  return KColor(R / base, G / base, B / base, alpha)
40
55
  end
56
+ function ____exports.irange(self, start, ____end)
57
+ if ____end == nil then
58
+ ____end = start
59
+ start = 0
60
+ end
61
+ local array = {}
62
+ do
63
+ local i = start
64
+ while i <= ____end do
65
+ array[#array + 1] = i
66
+ i = i + 1
67
+ end
68
+ end
69
+ return array
70
+ end
41
71
  function ____exports.isReflectionRender(self)
42
72
  local room = game:GetRoom()
43
73
  local renderMode = room:GetRenderMode()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "2.0.10",
3
+ "version": "2.0.11",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -25,10 +25,10 @@
25
25
  "dist/**/*.d.ts"
26
26
  ],
27
27
  "dependencies": {
28
- "isaac-typescript-definitions": "^2.0.13"
28
+ "isaac-typescript-definitions": "^2.0.14"
29
29
  },
30
30
  "devDependencies": {
31
- "isaacscript-lint": "^1.0.142",
31
+ "isaacscript-lint": "^1.0.145",
32
32
  "isaacscript-spell": "^1.0.3",
33
33
  "isaacscript-tsconfig": "^1.1.16",
34
34
  "ts-node": "^10.7.0",