"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDirectionName = exports.directionToVector = exports.directionToShootAction = exports.directionToMoveAction = exports.directionToDegrees = exports.angleToDirection = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const directionNames_1 = require("../objects/directionNames");
const directionToDegrees_1 = require("../objects/directionToDegrees");
const directionToMoveAction_1 = require("../objects/directionToMoveAction");
const directionToShootAction_1 = require("../objects/directionToShootAction");
const directionToVector_1 = require("../objects/directionToVector");
/**
 * Helper function to convert the degrees of an angle to the `Direction` enum.
 *
 * Note that this function considers 0 degrees to be pointing to the right, which is unusual because
 * 0 normally corresponds to up. (This corresponds to how the `Vector.GetAngleDegrees` method
 * works.)
 */
function angleToDirection(angleDegrees) {
    let positiveDegrees = angleDegrees;
    while (positiveDegrees < 0) {
        positiveDegrees += 360;
    }
    const normalizedDegrees = positiveDegrees % 360;
    if (normalizedDegrees < 45) {
        return isaac_typescript_definitions_1.Direction.RIGHT;
    }
    if (normalizedDegrees < 135) {
        return isaac_typescript_definitions_1.Direction.DOWN;
    }
    if (normalizedDegrees < 225) {
        return isaac_typescript_definitions_1.Direction.LEFT;
    }
    if (normalizedDegrees < 315) {
        return isaac_typescript_definitions_1.Direction.UP;
    }
    return isaac_typescript_definitions_1.Direction.RIGHT;
}
exports.angleToDirection = angleToDirection;
/**
 * Helper function to convert a direction to degrees. For example, `Direction.LEFT` (0) would return
 * 180 and `Direction.RIGHT` (2) would return 0. (This corresponds to how the
 * `Vector.GetAngleDegrees` method works.)
 */
function directionToDegrees(direction) {
    return directionToDegrees_1.DIRECTION_TO_DEGREES[direction];
}
exports.directionToDegrees = directionToDegrees;
/**
 * Helper function to convert a direction to a shoot `ButtonAction`. For example, `Direction.LEFT`
 * (0) would return `ButtonAction.LEFT` (0).
 */
function directionToMoveAction(direction) {
    return directionToMoveAction_1.DIRECTION_TO_MOVE_ACTION[direction];
}
exports.directionToMoveAction = directionToMoveAction;
/**
 * Helper function to convert a direction to a shoot `ButtonAction`. For example, `Direction.LEFT`
 * (0) would return `ButtonAction.SHOOT_LEFT` (4).
 */
function directionToShootAction(direction) {
    return directionToShootAction_1.DIRECTION_TO_SHOOT_ACTION[direction];
}
exports.directionToShootAction = directionToShootAction;
/**
 * Helper function to convert a direction to a `Vector`. For example, `Direction.LEFT` (0) would
 * convert to `Vector(-1, 0).
 */
function directionToVector(direction) {
    return directionToVector_1.DIRECTION_TO_VECTOR[direction];
}
exports.directionToVector = directionToVector;
/**
 * Helper function to get the lowercase name of a direction. For example, `Direction.LEFT` (0) would
 * return "left".
 */
function getDirectionName(direction) {
    return directionNames_1.DIRECTION_NAMES[direction];
}
exports.getDirectionName = getDirectionName;
