"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PickupChangeDetection = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const ISCFeature_1 = require("../../../enums/ISCFeature");
const Feature_1 = require("../../private/Feature");
const v = {
    room: {
        pickupVariants: new Map(),
        pickupSubTypes: new Map(),
    },
};
class PickupChangeDetection extends Feature_1.Feature {
    v = v;
    postPickupChanged;
    pickupIndexCreation;
    constructor(postPickupChanged, pickupIndexCreation) {
        super();
        this.featuresUsed = [ISCFeature_1.ISCFeature.PICKUP_INDEX_CREATION];
        this.callbacksUsed = [
            // 35
            [isaac_typescript_definitions_1.ModCallback.POST_PICKUP_UPDATE, this.postPickupUpdate],
        ];
        this.postPickupChanged = postPickupChanged;
        this.pickupIndexCreation = pickupIndexCreation;
    }
    // ModCallback.POST_PICKUP_UPDATE (35)
    postPickupUpdate = (pickup) => {
        const pickupIndex = this.pickupIndexCreation.getPickupIndex(pickup);
        const oldVariant = v.room.pickupVariants.get(pickupIndex);
        v.room.pickupVariants.set(pickupIndex, pickup.Variant);
        const oldSubType = v.room.pickupSubTypes.get(pickupIndex);
        v.room.pickupSubTypes.set(pickupIndex, pickup.SubType);
        // If this is the first update frame for the pickup, it cannot have changed.
        if (oldVariant === undefined || oldSubType === undefined) {
            return;
        }
        if (oldVariant !== pickup.Variant || oldSubType !== pickup.SubType) {
            this.postPickupChanged.fire(pickup, oldVariant, oldSubType, pickup.Variant, pickup.SubType);
        }
    };
}
exports.PickupChangeDetection = PickupChangeDetection;
