"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.keyboardToString = exports.isShootActionTriggeredOnAnyInput = exports.isShootActionTriggered = exports.isShootActionPressedOnAnyInput = exports.isShootActionPressed = exports.isShootAction = exports.isMoveActionTriggeredOnAnyInput = exports.isMoveActionTriggered = exports.isMoveActionPressedOnAnyInput = exports.isMoveActionPressed = exports.isMoveAction = exports.isModifierKeyPressed = exports.isKeyboardPressed = exports.isActionTriggeredOnAnyInput = exports.isActionTriggered = exports.isActionPressedOnAnyInput = exports.isActionPressed = exports.getShootButtonActions = exports.getMoveButtonActions = exports.controllerToString = exports.SHOOTING_BUTTON_ACTIONS_SET = exports.SHOOTING_BUTTON_ACTIONS = exports.MOVEMENT_BUTTON_ACTIONS_SET = exports.MOVEMENT_BUTTON_ACTIONS = exports.MODIFIER_KEYS = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const cachedEnumValues_1 = require("../cachedEnumValues");
const keyboardToStringMap_1 = require("../maps/keyboardToStringMap");
const ReadonlySet_1 = require("../types/ReadonlySet");
const string_1 = require("./string");
exports.MODIFIER_KEYS = [
    isaac_typescript_definitions_1.Keyboard.LEFT_SHIFT,
    isaac_typescript_definitions_1.Keyboard.LEFT_CONTROL,
    isaac_typescript_definitions_1.Keyboard.LEFT_ALT,
    isaac_typescript_definitions_1.Keyboard.LEFT_SUPER,
    isaac_typescript_definitions_1.Keyboard.RIGHT_SHIFT,
    isaac_typescript_definitions_1.Keyboard.RIGHT_CONTROL,
    isaac_typescript_definitions_1.Keyboard.RIGHT_ALT,
    isaac_typescript_definitions_1.Keyboard.RIGHT_SUPER, // 347
];
exports.MOVEMENT_BUTTON_ACTIONS = [
    isaac_typescript_definitions_1.ButtonAction.LEFT,
    isaac_typescript_definitions_1.ButtonAction.RIGHT,
    isaac_typescript_definitions_1.ButtonAction.UP,
    isaac_typescript_definitions_1.ButtonAction.DOWN, // 3
];
exports.MOVEMENT_BUTTON_ACTIONS_SET = new ReadonlySet_1.ReadonlySet(exports.MOVEMENT_BUTTON_ACTIONS);
exports.SHOOTING_BUTTON_ACTIONS = [
    isaac_typescript_definitions_1.ButtonAction.SHOOT_LEFT,
    isaac_typescript_definitions_1.ButtonAction.SHOOT_RIGHT,
    isaac_typescript_definitions_1.ButtonAction.SHOOT_UP,
    isaac_typescript_definitions_1.ButtonAction.SHOOT_DOWN, // 7
];
exports.SHOOTING_BUTTON_ACTIONS_SET = new ReadonlySet_1.ReadonlySet(exports.SHOOTING_BUTTON_ACTIONS);
/**
 * Helper function to get the enum name for the specified `Controller` value. Note that this will
 * trim off the "BUTTON_" prefix.
 *
 * Returns undefined if the submitted controller value was not valid.
 */
function controllerToString(controller) {
    const key = isaac_typescript_definitions_1.Controller[controller];
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    if (key === undefined) {
        return undefined;
    }
    return (0, string_1.trimPrefix)(key, "BUTTON_");
}
exports.controllerToString = controllerToString;
/**
 * Helper function to get the movement actions that the specified `ControllerIndex` is currently
 * pressing down. This returns an array because a player can be holding down more than one movement
 * key at a time.
 */
function getMoveButtonActions(controllerIndex) {
    return exports.MOVEMENT_BUTTON_ACTIONS.filter((buttonAction) => Input.IsActionPressed(buttonAction, controllerIndex));
}
exports.getMoveButtonActions = getMoveButtonActions;
/**
 * Helper function to get the shooting actions that the specified `ControllerIndex` is currently
 * pressing down. This returns an array because a player can be holding down more than one shooting
 * key at a time.
 */
function getShootButtonActions(controllerIndex) {
    return exports.SHOOTING_BUTTON_ACTIONS.filter((buttonAction) => Input.IsActionPressed(buttonAction, controllerIndex));
}
exports.getShootButtonActions = getShootButtonActions;
/**
 * Helper function to check if a player is pressing a specific button (i.e. holding it down).
 *
 * This is a variadic version of `Input.IsActionPressed`, meaning that you can pass as many buttons
 * as you want to check for. This function will return true if any of the buttons are pressed.
 */
function isActionPressed(controllerIndex, ...buttonActions) {
    return buttonActions.some((buttonAction) => Input.IsActionPressed(buttonAction, controllerIndex));
}
exports.isActionPressed = isActionPressed;
/**
 * Helper function to iterate over all inputs to determine if a specific button is pressed (i.e.
 * being held down).
 *
 * This function is variadic, meaning you can pass as many buttons as you want to check for. This
 * function will return true if any of the buttons are pressed.
 */
function isActionPressedOnAnyInput(...buttonActions) {
    return cachedEnumValues_1.CONTROLLER_INDEX_VALUES.some((controllerIndex) => isActionPressed(controllerIndex, ...buttonActions));
}
exports.isActionPressedOnAnyInput = isActionPressedOnAnyInput;
/**
 * Helper function to check if a player is triggering a specific button (i.e. pressing and releasing
 * it).
 *
 * This is a variadic version of `Input.IsActionTriggered`, meaning that you can pass as many
 * buttons as you want to check for. This function will return true if any of the buttons are
 * triggered.
 */
function isActionTriggered(controllerIndex, ...buttonActions) {
    return buttonActions.some((buttonAction) => Input.IsActionTriggered(buttonAction, controllerIndex));
}
exports.isActionTriggered = isActionTriggered;
/**
 * Iterates over all inputs to determine if a specific button is triggered (i.e. held down and then
 * released).
 *
 * This function is variadic, meaning you can pass as many buttons as you want to check for. This
 * function will return true if any of the buttons are pressed.
 */
function isActionTriggeredOnAnyInput(...buttonActions) {
    return cachedEnumValues_1.CONTROLLER_INDEX_VALUES.some((controllerIndex) => isActionTriggered(controllerIndex, ...buttonActions));
}
exports.isActionTriggeredOnAnyInput = isActionTriggeredOnAnyInput;
/**
 * Helper function to see if a specific keyboard key is being held down by the player.
 *
 * This function is variadic, meaning you can pass as many keyboard values as you want to check for.
 * This function will return true if any of the values are pressed.
 */
function isKeyboardPressed(...keys) {
    return keys.some((key) => Input.IsButtonPressed(key, isaac_typescript_definitions_1.ControllerIndex.KEYBOARD));
}
exports.isKeyboardPressed = isKeyboardPressed;
/**
 * Helper function to check if one or more modifier keys are being pressed down on the keyboard.
 *
 * A modifier key is defined as shift, control, alt, or Windows.
 */
function isModifierKeyPressed() {
    return isKeyboardPressed(...exports.MODIFIER_KEYS);
}
exports.isModifierKeyPressed = isModifierKeyPressed;
function isMoveAction(buttonAction) {
    return exports.MOVEMENT_BUTTON_ACTIONS_SET.has(buttonAction);
}
exports.isMoveAction = isMoveAction;
function isMoveActionPressed(controllerIndex) {
    return isActionPressed(controllerIndex, ...exports.MOVEMENT_BUTTON_ACTIONS);
}
exports.isMoveActionPressed = isMoveActionPressed;
function isMoveActionPressedOnAnyInput() {
    return exports.MOVEMENT_BUTTON_ACTIONS.some((moveAction) => isActionPressedOnAnyInput(moveAction));
}
exports.isMoveActionPressedOnAnyInput = isMoveActionPressedOnAnyInput;
function isMoveActionTriggered(controllerIndex) {
    return isActionTriggered(controllerIndex, ...exports.MOVEMENT_BUTTON_ACTIONS);
}
exports.isMoveActionTriggered = isMoveActionTriggered;
function isMoveActionTriggeredOnAnyInput() {
    return exports.MOVEMENT_BUTTON_ACTIONS.some((moveAction) => isActionTriggeredOnAnyInput(moveAction));
}
exports.isMoveActionTriggeredOnAnyInput = isMoveActionTriggeredOnAnyInput;
function isShootAction(buttonAction) {
    return exports.SHOOTING_BUTTON_ACTIONS_SET.has(buttonAction);
}
exports.isShootAction = isShootAction;
function isShootActionPressed(controllerIndex) {
    return isActionPressed(controllerIndex, ...exports.SHOOTING_BUTTON_ACTIONS);
}
exports.isShootActionPressed = isShootActionPressed;
function isShootActionPressedOnAnyInput() {
    return exports.SHOOTING_BUTTON_ACTIONS.some((shootAction) => isActionPressedOnAnyInput(shootAction));
}
exports.isShootActionPressedOnAnyInput = isShootActionPressedOnAnyInput;
function isShootActionTriggered(controllerIndex) {
    return isActionTriggered(controllerIndex, ...exports.SHOOTING_BUTTON_ACTIONS);
}
exports.isShootActionTriggered = isShootActionTriggered;
function isShootActionTriggeredOnAnyInput() {
    return exports.SHOOTING_BUTTON_ACTIONS.some((shootAction) => isActionTriggeredOnAnyInput(shootAction));
}
exports.isShootActionTriggeredOnAnyInput = isShootActionTriggeredOnAnyInput;
/**
 * Helper function to get the string that would be typed if someone pressed the corresponding key.
 * This is useful for creating in-game chat.
 *
 * Note that this function will only work for the keyboard values that are printable. Thus, it will
 * return undefined for e.g. `Keyboard.LEFT_SHIFT` (340). If all you want is the corresponding name
 * of the key, then simply use the enum reverse mapping (e.g. `Keyboard[keyboard]`).
 */
function keyboardToString(keyboard, uppercase) {
    const tuple = keyboardToStringMap_1.KEYBOARD_TO_STRING_MAP.get(keyboard);
    if (tuple === undefined) {
        return undefined;
    }
    const [lowercaseCharacter, uppercaseCharacter] = tuple;
    return uppercase ? uppercaseCharacter : lowercaseCharacter;
}
exports.keyboardToString = keyboardToString;
