isaacscript-common 4.6.1 → 4.7.2

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.
@@ -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
package/index.d.ts CHANGED
@@ -26,7 +26,7 @@ export { anyPlayerUsingPony, isPlayerUsingPony, } from "./features/ponyDetection
26
26
  export { preventCollectibleRotation } from "./features/preventCollectibleRotation";
27
27
  export { registerHotkey, unregisterHotkey } from "./features/registerHotkey";
28
28
  export { getRoomClearGameFrame, getRoomClearRoomFrame, } from "./features/roomClearFrame";
29
- export { runInNGameFrames, runInNRenderFrames, runNextGameFrame, runNextRenderFrame, } from "./features/runInNFrames";
29
+ export { runInNGameFrames, runInNRenderFrames, runNextGameFrame, runNextRenderFrame, setIntervalGameFrames, setIntervalRenderFrames, } from "./features/runInNFrames";
30
30
  export * from "./features/saveDataManager/exports";
31
31
  export { hasSirenStolenFamiliar, setFamiliarNoSirenSteal, } from "./features/sirenHelpers";
32
32
  export { getStageHistory, hasVisitedStage } from "./features/stageHistory";
package/index.lua CHANGED
@@ -210,10 +210,14 @@ do
210
210
  local runInNRenderFrames = ____runInNFrames.runInNRenderFrames
211
211
  local runNextGameFrame = ____runInNFrames.runNextGameFrame
212
212
  local runNextRenderFrame = ____runInNFrames.runNextRenderFrame
213
+ local setIntervalGameFrames = ____runInNFrames.setIntervalGameFrames
214
+ local setIntervalRenderFrames = ____runInNFrames.setIntervalRenderFrames
213
215
  ____exports.runInNGameFrames = runInNGameFrames
214
216
  ____exports.runInNRenderFrames = runInNRenderFrames
215
217
  ____exports.runNextGameFrame = runNextGameFrame
216
218
  ____exports.runNextRenderFrame = runNextRenderFrame
219
+ ____exports.setIntervalGameFrames = setIntervalGameFrames
220
+ ____exports.setIntervalRenderFrames = setIntervalRenderFrames
217
221
  end
218
222
  do
219
223
  local ____export = require("features.saveDataManager.exports")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "4.6.1",
3
+ "version": "4.7.2",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",