"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PostKeyboardChanged = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const cachedEnumValues_1 = require("../../arrays/cachedEnumValues");
const input_1 = require("../../functions/input");
const CustomCallback_1 = require("../private/CustomCallback");
const v = {
    run: {
        pressedKeys: new Set(),
    },
};
class PostKeyboardChanged extends CustomCallback_1.CustomCallback {
    v = v;
    constructor() {
        super();
        this.callbacksUsed = [
            // 2
            [isaac_typescript_definitions_1.ModCallback.POST_RENDER, this.postRender],
        ];
    }
    shouldFire = (fireArgs, optionalArgs) => {
        const [keyboard, pressed] = fireArgs;
        const [callbackKeyboard, callbackPressed] = optionalArgs;
        return ((callbackKeyboard === undefined || callbackKeyboard === keyboard) &&
            (callbackPressed === undefined || callbackPressed === pressed));
    };
    postRender = () => {
        for (const keyboard of v.run.pressedKeys) {
            if (!(0, input_1.isKeyboardPressed)(keyboard)) {
                v.run.pressedKeys.delete(keyboard);
                this.fire(keyboard, false);
            }
        }
        for (const keyboard of cachedEnumValues_1.KEYBOARD_VALUES) {
            if (v.run.pressedKeys.has(keyboard)) {
                continue;
            }
            if ((0, input_1.isKeyboardPressed)(keyboard)) {
                v.run.pressedKeys.add(keyboard);
                this.fire(keyboard, true);
            }
        }
    };
}
exports.PostKeyboardChanged = PostKeyboardChanged;
