UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

53 lines (52 loc) 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SlotUpdateDetection = void 0; const isaac_typescript_definitions_1 = require("isaac-typescript-definitions"); const ModCallbackCustom_1 = require("../../../enums/ModCallbackCustom"); const entitiesSpecific_1 = require("../../../functions/entitiesSpecific"); const Feature_1 = require("../../private/Feature"); const v = { room: { initializedSlots: new Set(), }, }; class SlotUpdateDetection extends Feature_1.Feature { v = v; postSlotInit; postSlotUpdate; constructor(postSlotInit, postSlotUpdate) { super(); this.callbacksUsed = [ // 1 [isaac_typescript_definitions_1.ModCallback.POST_UPDATE, this.postUpdate], ]; this.customCallbacksUsed = [ // This has to be the reordered callback because we don't want the `POST_SLOT_INIT` callback // firing on the first room of a floor before the `POST_NEW_LEVEL` callback. [ModCallbackCustom_1.ModCallbackCustom.POST_NEW_ROOM_REORDERED, this.postNewRoomReordered], ]; this.postSlotInit = postSlotInit; this.postSlotUpdate = postSlotUpdate; } // ModCallback.POST_UPDATE (1) postUpdate = () => { for (const slot of (0, entitiesSpecific_1.getSlots)()) { this.checkNewEntity(slot); this.postSlotUpdate.fire(slot); } }; // ModCallbackCustom.POST_NEW_ROOM_REORDERED postNewRoomReordered = () => { for (const slot of (0, entitiesSpecific_1.getSlots)()) { this.checkNewEntity(slot); } }; checkNewEntity(slot) { const ptrHash = GetPtrHash(slot); if (!v.room.initializedSlots.has(ptrHash)) { v.room.initializedSlots.add(ptrHash); this.postSlotInit.fire(slot); } } } exports.SlotUpdateDetection = SlotUpdateDetection;