"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FastReset = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const cachedClasses_1 = require("../../../core/cachedClasses");
const decorators_1 = require("../../../decorators");
const input_1 = require("../../../functions/input");
const run_1 = require("../../../functions/run");
const Feature_1 = require("../../private/Feature");
class FastReset extends Feature_1.Feature {
    enabled = false;
    /** @internal */
    constructor() {
        super();
        this.callbacksUsed = [
            // 2
            [isaac_typescript_definitions_1.ModCallback.POST_RENDER, this.postRender],
        ];
    }
    // ModCallback.POST_RENDER (2)
    postRender = () => {
        if (!this.enabled) {
            return;
        }
        checkResetInput();
    };
    /**
     * Enables the fast-reset feature, which allows you to restart the game instantaneously. If this
     * behavior is desired, call this function once at the beginning of your mod.
     *
     * This is useful for debugging, when you are resetting the game often.
     *
     * You can disable the fast-reset feature with the `disableFastReset` function.
     *
     * In order to use this function, you must upgrade your mod with `ISCFeature.FAST_RESET`.
     *
     * @public
     */
    enableFastReset() {
        this.enabled = true;
    }
    /**
     * Disables the fast-reset feature. Only useful if you have previously called the
     * `enableFastReset` function.
     *
     * In order to use this function, you must upgrade your mod with `ISCFeature.FAST_RESET`.
     *
     * @public
     */
    disableFastReset() {
        this.enabled = false;
    }
}
exports.FastReset = FastReset;
__decorate([
    decorators_1.Exported
], FastReset.prototype, "enableFastReset", null);
__decorate([
    decorators_1.Exported
], FastReset.prototype, "disableFastReset", null);
/** Check for fast-reset inputs. */
function checkResetInput() {
    const isPaused = cachedClasses_1.game.IsPaused();
    // Disable the fast-reset feature if the console is open. (This will also disable the feature when
    // the game is paused, but that's okay as well.)
    if (isPaused) {
        return;
    }
    // Disable the fast-reset feature if any custom consoles are open.
    if (AwaitingTextInput) {
        return;
    }
    // Don't fast-reset if any modifiers are pressed.
    if ((0, input_1.isModifierKeyPressed)()) {
        return;
    }
    // Check to see if the player has pressed the restart input. (We check all inputs instead of
    // `player.ControllerIndex` because a controller player might be using the keyboard to reset.)
    if ((0, input_1.isActionTriggeredOnAnyInput)(isaac_typescript_definitions_1.ButtonAction.RESTART)) {
        (0, run_1.restart)();
    }
}
