UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

35 lines (34 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PostNPCStateChanged = void 0; const isaac_typescript_definitions_1 = require("isaac-typescript-definitions"); const shouldFire_1 = require("../../shouldFire"); const DefaultMap_1 = require("../DefaultMap"); const CustomCallback_1 = require("../private/CustomCallback"); const v = { run: { stateMap: new DefaultMap_1.DefaultMap((state) => state), }, }; class PostNPCStateChanged extends CustomCallback_1.CustomCallback { v = v; constructor() { super(); this.callbacksUsed = [ // 0 [isaac_typescript_definitions_1.ModCallback.POST_NPC_UPDATE, this.postNPCUpdate], ]; } shouldFire = shouldFire_1.shouldFireNPC; // ModCallback.POST_NPC_UPDATE (0) postNPCUpdate = (npc) => { const ptrHash = GetPtrHash(npc); const previousState = v.run.stateMap.getAndSetDefault(ptrHash, npc.State); const currentState = npc.State; v.run.stateMap.set(ptrHash, currentState); if (previousState !== currentState) { this.fire(npc, previousState, currentState); } }; } exports.PostNPCStateChanged = PostNPCStateChanged;