isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
54 lines (53 loc) • 2.18 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RunNextRoom = void 0;
const decorators_1 = require("../../../decorators");
const ModCallbackCustom_1 = require("../../../enums/ModCallbackCustom");
const array_1 = require("../../../functions/array");
const Feature_1 = require("../../private/Feature");
const v = {
run: {
queuedFunctions: [],
},
};
class RunNextRoom extends Feature_1.Feature {
/** @internal */
v = v;
vConditionalFunc = () => false;
/** @internal */
constructor() {
super();
this.customCallbacksUsed = [
[ModCallbackCustom_1.ModCallbackCustom.POST_NEW_ROOM_REORDERED, this.postNewRoomReordered],
];
}
// ModCallbackCustom.POST_NEW_ROOM_REORDERED
postNewRoomReordered = () => {
for (const func of v.run.queuedFunctions) {
func();
}
(0, array_1.emptyArray)(v.run.queuedFunctions);
};
/**
* Supply a function to run on the next `POST_NEW_ROOM` callback.
*
* 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_NEXT_ROOM`.
*/
runNextRoom(func) {
v.run.queuedFunctions.push(func);
}
}
exports.RunNextRoom = RunNextRoom;
__decorate([
decorators_1.Exported
], RunNextRoom.prototype, "runNextRoom", null);