import * as utils from "../../utils/index";
import { ComponentNPC } from "./base";
export class JigStatTrackerComponent extends ComponentNPC {
    constructor(statEvents) {
        super();
        this.callbacks = [];
        this.statEvents = statEvents;
    }
    async onComponentAdded(npc) {
        super.onComponentAdded(npc);
        this.statEvents.forEach(key => {
            utils.getScore(utils.GlobalNamespace.Namespace + key, "jig_computer.addon_stats");
            const callback = () => { utils.modifyScore(utils.GlobalNamespace.Namespace + key, "jig_computer.addon_stats", 1); };
            this.callbacks.push(callback);
            npc.subscribeToBroadcast(key, callback);
        });
    }
    async onComponentRemoved(npc) {
        this.statEvents.forEach((key, index) => {
            const callback = this.callbacks[index];
            npc.unsubscribeToBroadcast(key, callback);
        });
    }
}
