isaacscript-common 4.5.2 → 4.7.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.
Files changed (68) hide show
  1. package/constants.d.ts +0 -3
  2. package/constantsFirstLast.d.ts +0 -3
  3. package/features/characterHealthConversion.d.ts +6 -0
  4. package/features/characterStats.d.ts +5 -0
  5. package/features/deployJSONRoom.lua +2 -4
  6. package/features/disableAllSound.d.ts +0 -3
  7. package/features/runInNFrames.d.ts +38 -4
  8. package/features/runInNFrames.lua +90 -19
  9. package/functions/array.d.ts +30 -1
  10. package/functions/array.lua +84 -5
  11. package/functions/bitwise.d.ts +17 -0
  12. package/functions/bitwise.lua +41 -0
  13. package/functions/color.d.ts +1 -1
  14. package/functions/doors.d.ts +6 -0
  15. package/functions/doors.lua +23 -2
  16. package/functions/gridEntity.d.ts +12 -0
  17. package/functions/gridEntity.lua +15 -2
  18. package/functions/kColor.d.ts +1 -1
  19. package/functions/log.d.ts +2 -2
  20. package/functions/rng.d.ts +1 -1
  21. package/functions/rng.lua +5 -0
  22. package/functions/roomShape.d.ts +2 -2
  23. package/functions/rooms.d.ts +1 -0
  24. package/functions/rooms.lua +1 -0
  25. package/functions/set.d.ts +17 -0
  26. package/functions/set.lua +24 -0
  27. package/functions/stage.d.ts +6 -1
  28. package/functions/stage.lua +7 -0
  29. package/functions/vector.d.ts +1 -1
  30. package/index.d.ts +0 -1
  31. package/index.lua +0 -8
  32. package/initFeatures.lua +0 -3
  33. package/maps/roomTypeMap.lua +0 -1
  34. package/objects/doorSlotToDoorSlotFlag.d.ts +4 -0
  35. package/objects/doorSlotToDoorSlotFlag.lua +17 -0
  36. package/objects/roomShapeBounds.d.ts +1 -1
  37. package/objects/roomShapeBounds.lua +8 -8
  38. package/objects/roomShapeLayoutSizes.d.ts +1 -1
  39. package/objects/roomShapeLayoutSizes.lua +4 -4
  40. package/objects/roomTypeGotoPrefixes.d.ts +4 -0
  41. package/objects/roomTypeGotoPrefixes.lua +35 -0
  42. package/objects/roomTypeNames.lua +0 -1
  43. package/package.json +2 -2
  44. package/types/CollectibleIndex.d.ts +1 -1
  45. package/types/PickingUpItem.d.ts +3 -3
  46. package/types/PickingUpItem.lua +3 -3
  47. package/types/PlayerIndex.d.ts +1 -1
  48. package/types/private/IsaacAPIClass.d.ts +1 -1
  49. package/types/private/SerializedIsaacAPIClass.d.ts +1 -1
  50. package/types/private/TSTLClass.d.ts +1 -1
  51. package/enums/StageTravelEntityState.d.ts +0 -4
  52. package/enums/StageTravelEntityState.lua +0 -7
  53. package/enums/StageTravelState.d.ts +0 -6
  54. package/enums/StageTravelState.lua +0 -11
  55. package/features/customTrapdoor/constants.d.ts +0 -5
  56. package/features/customTrapdoor/constants.lua +0 -7
  57. package/features/customTrapdoor/exports.d.ts +0 -37
  58. package/features/customTrapdoor/exports.lua +0 -124
  59. package/features/customTrapdoor/init.d.ts +0 -1
  60. package/features/customTrapdoor/init.lua +0 -11
  61. package/features/customTrapdoor/stageTravel.d.ts +0 -0
  62. package/features/customTrapdoor/stageTravel.lua +0 -0
  63. package/features/customTrapdoor/trapdoor.d.ts +0 -0
  64. package/features/customTrapdoor/trapdoor.lua +0 -0
  65. package/features/customTrapdoor/v.d.ts +0 -14
  66. package/features/customTrapdoor/v.lua +0 -16
  67. package/interfaces/StageTravelEntityDescription.d.ts +0 -5
  68. package/interfaces/StageTravelEntityDescription.lua +0 -2
package/constants.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- /**
2
- * @module core/Constants
3
- */
4
1
  import { CollectibleType, ItemPoolType, LevelStage, RoomType } from "isaac-typescript-definitions";
5
2
  /**
6
3
  * The distance of the laser when Azazel does not have any range up items yet. For more info, see
@@ -1,6 +1,3 @@
1
- /**
2
- * @module Constants (First and Last)
3
- */
4
1
  import { Card, CollectibleType, PillColor, PillEffect, PlayerType, TrinketType } from "isaac-typescript-definitions";
5
2
  /** Equal to `CollectibleType.SAD_ONION`. */
6
3
  export declare const FIRST_COLLECTIBLE_TYPE = CollectibleType.SAD_ONION;
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Easily create custom characters that have the same health mechanic as Blue Baby (red heart
3
+ * containers --> soul hearts) or Black Judas (red heart containers --> black hearts).
4
+ *
5
+ * @module
6
+ */
1
7
  import { HeartSubType, PlayerType } from "isaac-typescript-definitions";
2
8
  export declare type ConversionHeartSubType = HeartSubType.SOUL | HeartSubType.BLACK;
3
9
  /**
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Easily create custom characters that have base stats different from that of Isaac.
3
+ *
4
+ * @module
5
+ */
1
6
  import { CacheFlag, PlayerType } from "isaac-typescript-definitions";
2
7
  /**
3
8
  * Helper function to manage the stats for a vanilla or custom character. Call this function once at
@@ -37,6 +37,7 @@ local removeAllBombs = ____entitySpecific.removeAllBombs
37
37
  local removeAllPickups = ____entitySpecific.removeAllPickups
38
38
  local ____gridEntity = require("functions.gridEntity")
39
39
  local convertXMLGridEntityType = ____gridEntity.convertXMLGridEntityType
40
+ local getAllGridIndexes = ____gridEntity.getAllGridIndexes
40
41
  local getGridEntities = ____gridEntity.getGridEntities
41
42
  local removeAllGridExcept = ____gridEntity.removeAllGridExcept
42
43
  local removeGrid = ____gridEntity.removeGrid
@@ -59,8 +60,6 @@ local setRoomCleared = ____rooms.setRoomCleared
59
60
  local setRoomUncleared = ____rooms.setRoomUncleared
60
61
  local ____spawnCollectible = require("functions.spawnCollectible")
61
62
  local spawnCollectible = ____spawnCollectible.spawnCollectible
62
- local ____utils = require("functions.utils")
63
- local erange = ____utils.erange
64
63
  local ____runInNFrames = require("features.runInNFrames")
65
64
  local runNextGameFrame = ____runInNFrames.runNextGameFrame
66
65
  local ____exports = require("features.saveDataManager.exports")
@@ -182,10 +181,9 @@ function removeSpecificNPCs(self)
182
181
  end
183
182
  function fillRoomWithDecorations(self)
184
183
  local room = game:GetRoom()
185
- local gridSize = room:GetGridSize()
186
184
  local roomListIndex = getRoomListIndex(nil)
187
185
  local decorationGridIndexes = v.level.roomToDecorationGridIndexesMap:getAndSetDefault(roomListIndex)
188
- for ____, gridIndex in ipairs(erange(nil, gridSize)) do
186
+ for ____, gridIndex in ipairs(getAllGridIndexes(nil)) do
189
187
  do
190
188
  local existingGridEntity = room:GetGridEntity(gridIndex)
191
189
  if existingGridEntity ~= nil then
@@ -1,6 +1,3 @@
1
- /**
2
- * @module Disable All Sound
3
- */
4
1
  /**
5
2
  * Helper function to stop muting all sound effects and music.
6
3
  *
@@ -1,6 +1,6 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  /**
3
- * Supply a function to run N game frames from now in the PostUpdate callback.
3
+ * Supply a function to run N game frames from now in the `POST_UPDATE` callback.
4
4
  *
5
5
  * For a usage example, see the documentation for the `runNextGameFrame`, which is used in a similar
6
6
  * way.
@@ -11,7 +11,7 @@
11
11
  */
12
12
  export declare function runInNGameFrames(func: () => void, gameFrames: int): void;
13
13
  /**
14
- * Supply a function to run N render frames from now in the PostRender callback.
14
+ * Supply a function to run N render frames from now in the `POST_RENDER` callback.
15
15
  *
16
16
  * For a usage example, see the documentation for the `runNextGameFrame`, which is used in a similar
17
17
  * way.
@@ -22,7 +22,7 @@ export declare function runInNGameFrames(func: () => void, gameFrames: int): voi
22
22
  */
23
23
  export declare function runInNRenderFrames(func: () => void, renderFrames: int): void;
24
24
  /**
25
- * Supply a function to run on the next PostUpdate callback.
25
+ * Supply a function to run on the next `POST_UPDATE` callback.
26
26
  *
27
27
  * For example:
28
28
  *
@@ -51,7 +51,7 @@ export declare function runInNRenderFrames(func: () => void, renderFrames: int):
51
51
  */
52
52
  export declare function runNextGameFrame(func: () => void): void;
53
53
  /**
54
- * Supply a function to run on the next PostRender callback.
54
+ * Supply a function to run on the next `POST_RENDER` callback.
55
55
  *
56
56
  * For a usage example, see the documentation for the `runNextGameFrame`, which is used in a similar
57
57
  * way.
@@ -59,3 +59,37 @@ export declare function runNextGameFrame(func: () => void): void;
59
59
  * Note that this function will not handle saving and quitting.
60
60
  */
61
61
  export declare function runNextRenderFrame(func: () => void): void;
62
+ /**
63
+ * Supply a function to be repeatedly run on an interval of N game frames in the `POST_UPDATE`
64
+ * callback. The function will continue to be fired until `false` is returned from the function.
65
+ *
66
+ * This is similar to the `setInterval` vanilla JavaScript function, except there is no
67
+ * corresponding `clearInterval` function. (Instead, the return value from the supplied function is
68
+ * used to stop the interval.)
69
+ *
70
+ * Note that this function will not handle saving and quitting. You must manually restart any
71
+ * intervals if the player saves and quits in the middle of a run.
72
+ *
73
+ * @param func The function to repeatedly run on an interval.
74
+ * @param gameFrames The amount of game frames to wait between each run.
75
+ * @param runImmediately Whether or not to execute the function right now before waiting for the
76
+ * interval.
77
+ */
78
+ export declare function setIntervalGameFrames(func: () => boolean, gameFrames: int, runImmediately: boolean): void;
79
+ /**
80
+ * Supply a function to be repeatedly run on an interval of N render frames in the `POST_RENDER`
81
+ * callback. The function will continue to be fired until `false` is returned from the function.
82
+ *
83
+ * This is similar to the `setInterval` vanilla JavaScript function, except there is no
84
+ * corresponding `clearInterval` function. (Instead, the return value from the supplied function is
85
+ * used to stop the interval.)
86
+ *
87
+ * Note that this function will not handle saving and quitting. You must manually restart any
88
+ * intervals if the player saves and quits in the middle of a run.
89
+ *
90
+ * @param func The function to repeatedly run on an interval.
91
+ * @param renderFrames The amount of game frames to wait between each run.
92
+ * @param runImmediately Whether or not to execute the function right now before waiting for the
93
+ * interval.
94
+ */
95
+ export declare function setIntervalRenderFrames(func: () => boolean, renderFrames: int, runImmediately: boolean): void;
@@ -1,46 +1,67 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__ArrayForEach = ____lualib.__TS__ArrayForEach
3
- local __TS__ArraySplice = ____lualib.__TS__ArraySplice
4
3
  local ____exports = {}
5
- local postUpdate, postRender, checkExecuteQueuedFunctions, v
4
+ local postUpdate, postRender, checkExecuteQueuedFunctions, checkExecuteIntervalFunctions, getFunctionsThatShouldFireOnThisFrame, v
6
5
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
7
6
  local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
8
7
  local ____cachedClasses = require("cachedClasses")
9
8
  local game = ____cachedClasses.game
10
9
  local ____featuresInitialized = require("featuresInitialized")
11
10
  local errorIfFeaturesNotInitialized = ____featuresInitialized.errorIfFeaturesNotInitialized
11
+ local ____array = require("functions.array")
12
+ local arrayRemoveIndexInPlace = ____array.arrayRemoveIndexInPlace
12
13
  local ____exports = require("features.saveDataManager.exports")
13
14
  local saveDataManager = ____exports.saveDataManager
14
15
  function postUpdate(self)
15
16
  local gameFrameCount = game:GetFrameCount()
16
17
  checkExecuteQueuedFunctions(nil, gameFrameCount, v.run.queuedGameFunctionTuples)
18
+ checkExecuteIntervalFunctions(nil, gameFrameCount, v.run.intervalGameFunctionTuples)
17
19
  end
18
20
  function postRender(self)
19
21
  local renderFrameCount = Isaac.GetFrameCount()
20
22
  checkExecuteQueuedFunctions(nil, renderFrameCount, v.run.queuedRenderFunctionTuples)
23
+ checkExecuteIntervalFunctions(nil, renderFrameCount, v.run.intervalRenderFunctionTuples)
21
24
  end
22
25
  function checkExecuteQueuedFunctions(self, frameCount, functionTuples)
23
- local functionsToFire = {}
24
- local indexesToRemove = {}
26
+ local firingFunctions = getFunctionsThatShouldFireOnThisFrame(nil, frameCount, functionTuples)
27
+ for ____, ____value in ipairs(firingFunctions) do
28
+ local i = ____value[1]
29
+ local func = ____value[2]
30
+ func(nil)
31
+ arrayRemoveIndexInPlace(nil, functionTuples, i)
32
+ end
33
+ end
34
+ function checkExecuteIntervalFunctions(self, frameCount, functionTuples)
35
+ local firingFunctions = getFunctionsThatShouldFireOnThisFrame(nil, frameCount, functionTuples)
36
+ for ____, ____value in ipairs(firingFunctions) do
37
+ local i = ____value[1]
38
+ local func = ____value[2]
39
+ local numIntervalFrames = ____value[3]
40
+ local returnValue = func(nil)
41
+ arrayRemoveIndexInPlace(nil, functionTuples, i)
42
+ if numIntervalFrames ~= nil and returnValue == false then
43
+ local nextFireFrame = frameCount + numIntervalFrames
44
+ local tuple = {nextFireFrame, func, numIntervalFrames}
45
+ functionTuples[#functionTuples + 1] = tuple
46
+ end
47
+ end
48
+ end
49
+ function getFunctionsThatShouldFireOnThisFrame(self, frameCount, functionTuples)
50
+ local firingFunctionTuples = {}
25
51
  __TS__ArrayForEach(
26
52
  functionTuples,
27
53
  function(____, functionTuple, i)
28
- local frame, func = table.unpack(functionTuple)
29
- if frameCount >= frame then
30
- functionsToFire[#functionsToFire + 1] = func
31
- indexesToRemove[#indexesToRemove + 1] = i
54
+ local frameCountToFire, func, numIntervalFrames = table.unpack(functionTuple)
55
+ if frameCount >= frameCountToFire then
56
+ local firingFunctionTuple = {i, func, numIntervalFrames}
57
+ firingFunctionTuples[#firingFunctionTuples + 1] = firingFunctionTuple
32
58
  end
33
59
  end
34
60
  )
35
- for ____, indexToRemove in ipairs(indexesToRemove) do
36
- __TS__ArraySplice(functionTuples, indexToRemove, 1)
37
- end
38
- for ____, func in ipairs(functionsToFire) do
39
- func(nil)
40
- end
61
+ return firingFunctionTuples
41
62
  end
42
63
  local FEATURE_NAME = "runInNFrames"
43
- v = {run = {queuedGameFunctionTuples = {}, queuedRenderFunctionTuples = {}}}
64
+ v = {run = {queuedGameFunctionTuples = {}, queuedRenderFunctionTuples = {}, intervalGameFunctionTuples = {}, intervalRenderFunctionTuples = {}}}
44
65
  ---
45
66
  -- @internal
46
67
  function ____exports.runInNFramesInit(self, mod)
@@ -53,7 +74,7 @@ function ____exports.runInNFramesInit(self, mod)
53
74
  mod:AddCallback(ModCallback.POST_UPDATE, postUpdate)
54
75
  mod:AddCallback(ModCallback.POST_RENDER, postRender)
55
76
  end
56
- --- Supply a function to run N game frames from now in the PostUpdate callback.
77
+ --- Supply a function to run N game frames from now in the `POST_UPDATE` callback.
57
78
  --
58
79
  -- For a usage example, see the documentation for the `runNextGameFrame`, which is used in a similar
59
80
  -- way.
@@ -69,7 +90,7 @@ function ____exports.runInNGameFrames(self, func, gameFrames)
69
90
  local ____v_run_queuedGameFunctionTuples_0 = v.run.queuedGameFunctionTuples
70
91
  ____v_run_queuedGameFunctionTuples_0[#____v_run_queuedGameFunctionTuples_0 + 1] = tuple
71
92
  end
72
- --- Supply a function to run N render frames from now in the PostRender callback.
93
+ --- Supply a function to run N render frames from now in the `POST_RENDER` callback.
73
94
  --
74
95
  -- For a usage example, see the documentation for the `runNextGameFrame`, which is used in a similar
75
96
  -- way.
@@ -85,7 +106,7 @@ function ____exports.runInNRenderFrames(self, func, renderFrames)
85
106
  local ____v_run_queuedRenderFunctionTuples_1 = v.run.queuedRenderFunctionTuples
86
107
  ____v_run_queuedRenderFunctionTuples_1[#____v_run_queuedRenderFunctionTuples_1 + 1] = tuple
87
108
  end
88
- --- Supply a function to run on the next PostUpdate callback.
109
+ --- Supply a function to run on the next `POST_UPDATE` callback.
89
110
  --
90
111
  -- For example:
91
112
  --
@@ -115,7 +136,7 @@ function ____exports.runNextGameFrame(self, func)
115
136
  errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
116
137
  ____exports.runInNGameFrames(nil, func, 1)
117
138
  end
118
- --- Supply a function to run on the next PostRender callback.
139
+ --- Supply a function to run on the next `POST_RENDER` callback.
119
140
  --
120
141
  -- For a usage example, see the documentation for the `runNextGameFrame`, which is used in a similar
121
142
  -- way.
@@ -125,4 +146,54 @@ function ____exports.runNextRenderFrame(self, func)
125
146
  errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
126
147
  ____exports.runInNRenderFrames(nil, func, 1)
127
148
  end
149
+ --- Supply a function to be repeatedly run on an interval of N game frames in the `POST_UPDATE`
150
+ -- callback. The function will continue to be fired until `false` is returned from the function.
151
+ --
152
+ -- This is similar to the `setInterval` vanilla JavaScript function, except there is no
153
+ -- corresponding `clearInterval` function. (Instead, the return value from the supplied function is
154
+ -- used to stop the interval.)
155
+ --
156
+ -- Note that this function will not handle saving and quitting. You must manually restart any
157
+ -- intervals if the player saves and quits in the middle of a run.
158
+ --
159
+ -- @param func The function to repeatedly run on an interval.
160
+ -- @param gameFrames The amount of game frames to wait between each run.
161
+ -- @param runImmediately Whether or not to execute the function right now before waiting for the
162
+ -- interval.
163
+ function ____exports.setIntervalGameFrames(self, func, gameFrames, runImmediately)
164
+ errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
165
+ local gameFrameCount = game:GetFrameCount()
166
+ local functionFireFrame = gameFrameCount + gameFrames
167
+ local tuple = {functionFireFrame, func, gameFrames}
168
+ local ____v_run_intervalGameFunctionTuples_2 = v.run.intervalGameFunctionTuples
169
+ ____v_run_intervalGameFunctionTuples_2[#____v_run_intervalGameFunctionTuples_2 + 1] = tuple
170
+ if runImmediately then
171
+ func(nil)
172
+ end
173
+ end
174
+ --- Supply a function to be repeatedly run on an interval of N render frames in the `POST_RENDER`
175
+ -- callback. The function will continue to be fired until `false` is returned from the function.
176
+ --
177
+ -- This is similar to the `setInterval` vanilla JavaScript function, except there is no
178
+ -- corresponding `clearInterval` function. (Instead, the return value from the supplied function is
179
+ -- used to stop the interval.)
180
+ --
181
+ -- Note that this function will not handle saving and quitting. You must manually restart any
182
+ -- intervals if the player saves and quits in the middle of a run.
183
+ --
184
+ -- @param func The function to repeatedly run on an interval.
185
+ -- @param renderFrames The amount of game frames to wait between each run.
186
+ -- @param runImmediately Whether or not to execute the function right now before waiting for the
187
+ -- interval.
188
+ function ____exports.setIntervalRenderFrames(self, func, renderFrames, runImmediately)
189
+ errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
190
+ local renderFrameCount = Isaac.GetFrameCount()
191
+ local functionFireFrame = renderFrameCount + renderFrames
192
+ local tuple = {functionFireFrame, func, renderFrames}
193
+ local ____v_run_intervalGameFunctionTuples_3 = v.run.intervalGameFunctionTuples
194
+ ____v_run_intervalGameFunctionTuples_3[#____v_run_intervalGameFunctionTuples_3 + 1] = tuple
195
+ if runImmediately then
196
+ func(nil)
197
+ end
198
+ end
128
199
  return ____exports
@@ -37,7 +37,7 @@ export declare function arrayRemoveIndex<T>(originalArray: T[] | readonly T[], .
37
37
  * This function is variadic, meaning that you can specify N arguments to remove N elements.
38
38
  */
39
39
  export declare function arrayRemoveIndexInPlace<T>(array: T[], ...indexesToRemove: int[]): boolean;
40
- export declare function arrayToString<T>(array: T[]): string;
40
+ export declare function arrayToString<T>(array: T[] | readonly T[]): string;
41
41
  /**
42
42
  * Helper function to combine two or more arrays. Returns a new array that is the composition of all
43
43
  * of the specified arrays.
@@ -56,6 +56,30 @@ export declare function combineArrays<T>(...arrays: Array<T[] | readonly T[]>):
56
56
  export declare function copyArray<T>(oldArray: T[] | readonly T[], numElements?: int): T[];
57
57
  /** Helper function to remove all of the elements in an array in-place. */
58
58
  export declare function emptyArray<T>(array: T[]): void;
59
+ /**
60
+ * Helper function to get all possible combinations of the given array. This includes the
61
+ * combination of an empty array.
62
+ *
63
+ * For example, if this function is provided an array containing 1, 2, and 3, then it will return an
64
+ * array containing the following arrays:
65
+ *
66
+ * - []
67
+ * - [1]
68
+ * - [2]
69
+ * - [3]
70
+ * - [1, 2]
71
+ * - [1, 3]
72
+ * - [2, 3]
73
+ * - [1, 2, 3]
74
+ *
75
+ * From: https://github.com/firstandthird/combinations/blob/master/index.js
76
+ *
77
+ * @param array The array to get the combinations of.
78
+ * @param min Optional. The minimum number of elements to include in each combination. Default is 1.
79
+ * @param max Optional. The maximum number of elements to include in each combination. Default is
80
+ * the length of the array.
81
+ */
82
+ export declare function getArrayCombinations<T>(array: T[] | readonly T[], min?: int, max?: int): ReadonlyArray<readonly T[]>;
59
83
  /**
60
84
  * Helper function to get an array containing the indexes of an array.
61
85
  *
@@ -141,4 +165,9 @@ export declare function shuffleArray<T>(originalArray: T[] | readonly T[], seedO
141
165
  * `RNG.Next` method will be called. Default is `getRandomSeed()`.
142
166
  */
143
167
  export declare function shuffleArrayInPlace<T>(array: T[], seedOrRNG?: Seed | RNG): void;
168
+ /** Helper function to sum every value in an array together. */
144
169
  export declare function sumArray(array: number[] | readonly number[]): number;
170
+ /**
171
+ * Helper function to swap two different array elements. (The elements will be swapped in-place.)
172
+ */
173
+ export declare function swapArrayElements<T>(array: T[], i: number, j: number): void;
@@ -8,6 +8,9 @@ local __TS__ArrayForEach = ____lualib.__TS__ArrayForEach
8
8
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
9
9
  local __TS__ArraySort = ____lualib.__TS__ArraySort
10
10
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
11
+ local __TS__ArraySlice = ____lualib.__TS__ArraySlice
12
+ local __TS__ArrayConcat = ____lualib.__TS__ArrayConcat
13
+ local __TS__ArrayUnshift = ____lualib.__TS__ArrayUnshift
11
14
  local __TS__ObjectKeys = ____lualib.__TS__ObjectKeys
12
15
  local __TS__ArraySome = ____lualib.__TS__ArraySome
13
16
  local __TS__ArrayReduce = ____lualib.__TS__ArrayReduce
@@ -50,16 +53,20 @@ function ____exports.shuffleArrayInPlace(self, array, seedOrRNG)
50
53
  seedOrRNG = getRandomSeed(nil)
51
54
  end
52
55
  local currentIndex = #array
53
- local randomIndex
54
56
  local rng = isRNG(nil, seedOrRNG) and seedOrRNG or newRNG(nil, seedOrRNG)
55
57
  while currentIndex > 0 do
56
58
  currentIndex = currentIndex - 1
57
- randomIndex = ____exports.getRandomArrayIndex(nil, array, rng)
58
- local ____temp_0 = {array[randomIndex + 1], array[currentIndex + 1]}
59
- array[currentIndex + 1] = ____temp_0[1]
60
- array[randomIndex + 1] = ____temp_0[2]
59
+ local randomIndex = ____exports.getRandomArrayIndex(nil, array, rng)
60
+ ____exports.swapArrayElements(nil, array, currentIndex, randomIndex)
61
61
  end
62
62
  end
63
+ --- Helper function to swap two different array elements. (The elements will be swapped in-place.)
64
+ function ____exports.swapArrayElements(self, array, i, j)
65
+ local value1 = array[i + 1]
66
+ local value2 = array[j + 1]
67
+ array[i + 1] = value2
68
+ array[j + 1] = value1
69
+ end
63
70
  --- Helper function for determining if two arrays contain the exact same elements. Note that this
64
71
  -- only performs a shallow comparison.
65
72
  function ____exports.arrayEquals(self, array1, array2)
@@ -201,6 +208,77 @@ end
201
208
  function ____exports.emptyArray(self, array)
202
209
  __TS__ArraySplice(array, 0, #array)
203
210
  end
211
+ --- Helper function to get all possible combinations of the given array. This includes the
212
+ -- combination of an empty array.
213
+ --
214
+ -- For example, if this function is provided an array containing 1, 2, and 3, then it will return an
215
+ -- array containing the following arrays:
216
+ --
217
+ -- - []
218
+ -- - [1]
219
+ -- - [2]
220
+ -- - [3]
221
+ -- - [1, 2]
222
+ -- - [1, 3]
223
+ -- - [2, 3]
224
+ -- - [1, 2, 3]
225
+ --
226
+ -- From: https://github.com/firstandthird/combinations/blob/master/index.js
227
+ --
228
+ -- @param array The array to get the combinations of.
229
+ -- @param min Optional. The minimum number of elements to include in each combination. Default is 1.
230
+ -- @param max Optional. The maximum number of elements to include in each combination. Default is
231
+ -- the length of the array.
232
+ function ____exports.getArrayCombinations(self, array, min, max)
233
+ if min == nil or min <= 0 then
234
+ min = 1
235
+ end
236
+ if max == nil or max <= 0 then
237
+ max = #array
238
+ end
239
+ local addCombinations
240
+ addCombinations = function(____, n, src, got, all)
241
+ if n == 0 then
242
+ if #got > 0 then
243
+ all[#all + 1] = got
244
+ end
245
+ return
246
+ end
247
+ do
248
+ local j = 0
249
+ while j < #src do
250
+ local value = src[j + 1]
251
+ addCombinations(
252
+ nil,
253
+ n - 1,
254
+ __TS__ArraySlice(src, j + 1),
255
+ __TS__ArrayConcat(got, {value}),
256
+ all
257
+ )
258
+ j = j + 1
259
+ end
260
+ end
261
+ end
262
+ local all = {}
263
+ do
264
+ local i = min
265
+ while i < #array do
266
+ addCombinations(
267
+ nil,
268
+ i,
269
+ array,
270
+ {},
271
+ all
272
+ )
273
+ i = i + 1
274
+ end
275
+ end
276
+ if #array == max then
277
+ all[#all + 1] = array
278
+ end
279
+ __TS__ArrayUnshift(all, {})
280
+ return all
281
+ end
204
282
  --- Helper function to get an array containing the indexes of an array.
205
283
  --
206
284
  -- For example, an array of `["Apple", "Banana"]` would return an array of `[0, 1]`.
@@ -351,6 +429,7 @@ function ____exports.shuffleArray(self, originalArray, seedOrRNG)
351
429
  ____exports.shuffleArrayInPlace(nil, array, seedOrRNG)
352
430
  return array
353
431
  end
432
+ --- Helper function to sum every value in an array together.
354
433
  function ____exports.sumArray(self, array)
355
434
  return __TS__ArrayReduce(
356
435
  array,
@@ -1,4 +1,21 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /// <reference types="isaac-typescript-definitions" />
3
+ /// <reference types="isaac-typescript-definitions" />
4
+ /// <reference types="isaac-typescript-definitions" />
5
+ /** Helper function to convert a set of flags to a single `BitFlags` object. */
6
+ export declare function arrayToBitFlags<T extends BitFlag | BitFlag128>(array: T[] | readonly T[]): BitFlags<T>;
7
+ /** Helper function to convert an array of bits to the resulting decimal number. */
8
+ export declare function convertBinaryToDecimal(bits: int[]): number;
9
+ /** Helper function to convert a number to an array of bits. */
10
+ export declare function convertDecimalToBinary(number: number): int[];
11
+ /**
12
+ * Helper function to count the number of bits that are set to 1 in a binary representation of a
13
+ * number.
14
+ */
2
15
  export declare function countSetBits(n: int): int;
16
+ /** Helper function to get the value of a specific but in a binary representation of a number. */
3
17
  export declare function getKBitOfN(k: int, n: int): int;
18
+ /** Helper function to get the number of bits in a binary representation of a number. */
4
19
  export declare function getNumBitsOfN(n: int): int;
20
+ /** Helper function to convert a set of flags to a single `BitFlags` object. */
21
+ export declare function setToBitFlags<T extends BitFlag | BitFlag128>(set: Set<T> | ReadonlySet<T>): BitFlags<T>;
@@ -1,4 +1,35 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local __TS__ParseInt = ____lualib.__TS__ParseInt
3
+ local __TS__Iterator = ____lualib.__TS__Iterator
1
4
  local ____exports = {}
5
+ local ____flag = require("functions.flag")
6
+ local addFlag = ____flag.addFlag
7
+ --- Helper function to convert a set of flags to a single `BitFlags` object.
8
+ function ____exports.arrayToBitFlags(self, array)
9
+ local flags = 0
10
+ for ____, flag in ipairs(array) do
11
+ flags = addFlag(nil, flags, flag)
12
+ end
13
+ return flags
14
+ end
15
+ --- Helper function to convert an array of bits to the resulting decimal number.
16
+ function ____exports.convertBinaryToDecimal(self, bits)
17
+ local bitsString = table.concat(bits, "")
18
+ return __TS__ParseInt(bitsString, 2)
19
+ end
20
+ --- Helper function to convert a number to an array of bits.
21
+ function ____exports.convertDecimalToBinary(self, number)
22
+ local bits = {}
23
+ local i = 0
24
+ while number > 0 do
25
+ bits[i + 1] = number % 2
26
+ number = math.floor(number / 2)
27
+ i = i + 1
28
+ end
29
+ return bits
30
+ end
31
+ --- Helper function to count the number of bits that are set to 1 in a binary representation of a
32
+ -- number.
2
33
  function ____exports.countSetBits(self, n)
3
34
  local count = 0
4
35
  while n > 0 do
@@ -7,9 +38,11 @@ function ____exports.countSetBits(self, n)
7
38
  end
8
39
  return count
9
40
  end
41
+ --- Helper function to get the value of a specific but in a binary representation of a number.
10
42
  function ____exports.getKBitOfN(self, k, n)
11
43
  return n >> k & 1
12
44
  end
45
+ --- Helper function to get the number of bits in a binary representation of a number.
13
46
  function ____exports.getNumBitsOfN(self, n)
14
47
  local numBits = 0
15
48
  while n > 0 do
@@ -18,4 +51,12 @@ function ____exports.getNumBitsOfN(self, n)
18
51
  end
19
52
  return numBits
20
53
  end
54
+ --- Helper function to convert a set of flags to a single `BitFlags` object.
55
+ function ____exports.setToBitFlags(self, set)
56
+ local flags = 0
57
+ for ____, flag in __TS__Iterator(set:values()) do
58
+ flags = addFlag(nil, flags, flag)
59
+ end
60
+ return flags
61
+ end
21
62
  return ____exports
@@ -2,7 +2,7 @@
2
2
  /// <reference types="typescript-to-lua/language-extensions" />
3
3
  import { SerializationType } from "../enums/SerializationType";
4
4
  declare type SerializedColor = LuaTable<string, unknown> & {
5
- readonly __serializedColorBrand: unique symbol;
5
+ readonly __serializedColorBrand: symbol;
6
6
  };
7
7
  interface CopyColorReturn {
8
8
  [SerializationType.NONE]: Color;
@@ -7,6 +7,7 @@ export declare function closeAllDoors(): void;
7
7
  export declare function closeDoorFast(door: GridEntityDoor): void;
8
8
  export declare function doorSlotFlagToDoorSlot(doorSlotFlag: DoorSlotFlag): DoorSlot;
9
9
  export declare function doorSlotToDirection(doorSlot: DoorSlot): Direction;
10
+ export declare function doorSlotToDoorSlotFlag(doorSlot: DoorSlot): DoorSlotFlag;
10
11
  export declare function getAngelRoomDoor(): GridEntityDoor | undefined;
11
12
  export declare function getDevilRoomDoor(): GridEntityDoor | undefined;
12
13
  /**
@@ -30,6 +31,11 @@ export declare function getDoorEnterPosition(door: GridEntityDoor): Vector;
30
31
  * amount of units.
31
32
  */
32
33
  export declare function getDoorEnterPositionOffset(doorSlot: DoorSlot): Vector;
34
+ /**
35
+ * Helper function to convert an array of door slots or a set of door slots to the resulting bit
36
+ * flag number.
37
+ */
38
+ export declare function getDoorSlotFlags(doorSlots: DoorSlot[] | readonly DoorSlot[] | Set<DoorSlot> | ReadonlySet<DoorSlot>): BitFlags<DoorSlotFlag>;
33
39
  /** Helper function to get the possible door slots that can exist for a given room shape. */
34
40
  export declare function getDoorSlotsForRoomShape(roomShape: RoomShape): ReadonlySet<DoorSlot>;
35
41
  /**