isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
49 lines (48 loc) • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SlotRenderDetection = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const entitiesSpecific_1 = require("../../../functions/entitiesSpecific");
const DefaultMap_1 = require("../../DefaultMap");
const Feature_1 = require("../../private/Feature");
const v = {
room: {
slotAnimations: new DefaultMap_1.DefaultMap((slot) => {
const sprite = slot.GetSprite();
return sprite.GetAnimation();
}),
brokenSlots: new Set(),
},
};
class SlotRenderDetection extends Feature_1.Feature {
v = v;
postSlotRender;
postSlotAnimationChanged;
constructor(postSlotRender, postSlotAnimationChanged) {
super();
this.callbacksUsed = [
// 2
[isaac_typescript_definitions_1.ModCallback.POST_RENDER, this.postRender],
];
this.postSlotRender = postSlotRender;
this.postSlotAnimationChanged = postSlotAnimationChanged;
}
// ModCallback.POST_RENDER (2)
postRender = () => {
for (const slot of (0, entitiesSpecific_1.getSlots)()) {
this.postSlotRender.fire(slot);
this.checkSlotAnimationChanged(slot);
}
};
checkSlotAnimationChanged(slot) {
const sprite = slot.GetSprite();
const currentAnimation = sprite.GetAnimation();
const ptrHash = GetPtrHash(slot);
const previousAnimation = v.room.slotAnimations.getAndSetDefault(ptrHash, slot);
v.room.slotAnimations.set(ptrHash, currentAnimation);
if (currentAnimation !== previousAnimation) {
this.postSlotAnimationChanged.fire(slot, previousAnimation, currentAnimation);
}
}
}
exports.SlotRenderDetection = SlotRenderDetection;