isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
154 lines • 7.66 kB
TypeScript
import type { PlayerType } from "isaac-typescript-definitions";
import { Feature } from "../../private/Feature";
export declare class RunInNFrames extends Feature {
vConditionalFunc: () => boolean;
private readonly roomHistory;
private readonly postUpdate;
private readonly postRender;
/**
* Helper function to restart on the next render frame. Useful because it is impossible to restart
* the game inside of the `POST_NEW_ROOM`, `POST_NEW_LEVEL`, or `POST_GAME_STARTED` callbacks when
* a run is first starting.
*
* In order to use this function, you must upgrade your mod with `ISCFeature.RUN_IN_N_FRAMES`.
*
* @param character Optional. If specified, will restart the game as the specified character.
* @public
*/
restartNextRenderFrame(character?: PlayerType): void;
/**
* Supply a function to run N game frames from now in the `POST_UPDATE` callback.
*
* For a usage example, see the documentation for the `runNextGameFrame`, which is used in a
* similar way.
*
* Note that this function will not handle saving and quitting. If a player saving and quitting
* before the deferred function fires would cause a bug in your mod, then you should handle
* deferred functions manually using serializable data.
*
* In order to use this function, you must upgrade your mod with `ISCFeature.RUN_IN_N_FRAMES`.
*
* @param func The function to run.
* @param numGameFrames The amount of game frames to wait before running the function.
* @param cancelIfRoomChanges Optional. Whether to cancel running the function if a new room is
* loaded in the interim. Default is false.
* @public
*/
runInNGameFrames(func: () => void, numGameFrames: int, cancelIfRoomChanges?: boolean): void;
/**
* Supply a function to run N render frames from now in the `POST_RENDER` callback.
*
* For a usage example, see the documentation for the `runNextGameFrame`, which is used in a
* similar way.
*
* Note that this function will not handle saving and quitting. If a player saving and quitting
* before the deferred function fires would cause a bug in your mod, then you should handle
* deferred functions manually using serializable data.
*
* In order to use this function, you must upgrade your mod with `ISCFeature.RUN_IN_N_FRAMES`.
*
* @param func The function to run.
* @param numRenderFrames The amount of render frames to wait before running the function.
* @param cancelIfRoomChanges Optional. Whether to cancel running the function if a new room is
* loaded in the interim. Default is false.
* @public
*/
runInNRenderFrames(func: () => void, numRenderFrames: int, cancelIfRoomChanges?: boolean): void;
/**
* Supply a function to run on the next `POST_UPDATE` callback.
*
* For example:
*
* ```ts
* const NUM_EXPLODER_EXPLOSIONS = 5;
*
* function useItemExploder(player: EntityPlayer) {
* playSound("exploderBegin");
* explode(player, NUM_EXPLODER_EXPLOSIONS);
* }
*
* function explode(player: EntityPlayer, numFramesLeft: int) {
* Isaac.Explode(player, undefined, 1);
* numFramesLeft -= 1;
* if (numFramesLeft === 0) {
* runNextFrame(() => {
* explode(player, numFramesLeft);
* });
* }
* }
* ```
*
* Note that this function will not handle saving and quitting. If a player saving and quitting
* before the deferred function fires would cause a bug in your mod, then you should handle
* deferred functions manually using serializable data.
*
* In order to use this function, you must upgrade your mod with `ISCFeature.RUN_IN_N_FRAMES`.
*
* @param func The function to run.
* @param cancelIfRoomChanges Optional. Whether to cancel running the function if a new room is
* loaded in the interim. Default is false.
* @public
*/
runNextGameFrame(func: () => void, cancelIfRoomChanges?: boolean): void;
/**
* Supply a function to run on the next `POST_RENDER` callback.
*
* For a usage example, see the documentation for the `runNextGameFrame`, which is used in a
* similar way.
*
* Note that this function will not handle saving and quitting.
*
* In order to use this function, you must upgrade your mod with `ISCFeature.RUN_IN_N_FRAMES`.
*
* @param func The function to run.
* @param cancelIfRoomChanges Optional. Whether to cancel running the function if a new room is
* loaded in the interim. Default is false.
* @public
*/
runNextRenderFrame(func: () => void, cancelIfRoomChanges?: boolean): void;
/**
* Supply a function to be repeatedly run on an interval of N game frames in the `POST_UPDATE`
* callback. The function will continue to be fired until `false` is returned from the function.
*
* This is similar to the `setInterval` vanilla JavaScript function, except there is no
* corresponding `clearInterval` function. (Instead, the return value from the supplied function
* is used to stop the interval.)
*
* Note that this function will not handle saving and quitting. You must manually restart any
* intervals if the player saves and quits in the middle of a run.
*
* In order to use this function, you must upgrade your mod with `ISCFeature.RUN_IN_N_FRAMES`.
*
* @param func The function to repeatedly run on an interval.
* @param numGameFrames The amount of game frames to wait between each run.
* @param runImmediately Whether to execute the function right now before waiting for the
* interval.
* @param cancelIfRoomChanges Optional. Whether to cancel running the function if a new room is
* loaded in the interim. Default is false.
* @public
*/
setIntervalGameFrames(func: () => boolean, numGameFrames: int, runImmediately: boolean, cancelIfRoomChanges?: boolean): void;
/**
* Supply a function to be repeatedly run on an interval of N render frames in the `POST_RENDER`
* callback. The function will continue to be fired until `false` is returned from the function.
*
* This is similar to the `setInterval` vanilla JavaScript function, except there is no
* corresponding `clearInterval` function. (Instead, the return value from the supplied function
* is used to stop the interval.)
*
* Note that this function will not handle saving and quitting. You must manually restart any
* intervals if the player saves and quits in the middle of a run.
*
* In order to use this function, you must upgrade your mod with `ISCFeature.RUN_IN_N_FRAMES`.
*
* @param func The function to repeatedly run on an interval.
* @param numRenderFrames The amount of game frames to wait between each run.
* @param runImmediately Whether to execute the function right now before waiting for the
* interval.
* @param cancelIfRoomChanges Optional. Whether to cancel running the function if a new room is
* loaded in the interim. Default is false.
* @public
*/
setIntervalRenderFrames(func: () => boolean, numRenderFrames: int, runImmediately: boolean, cancelIfRoomChanges?: boolean): void;
}
//# sourceMappingURL=RunInNFrames.d.ts.map