"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.teleport = exports.reloadRoom = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const cachedClasses_1 = require("../core/cachedClasses");
const roomData_1 = require("./roomData");
const utils_1 = require("./utils");
/**
 * Helper function to reload the current room using `Game.StartRoomTransition`.
 *
 * This is useful for canceling the "goto" console command or to make the `Level.SetStage` method
 * take effect.
 */
function reloadRoom() {
    const roomGridIndex = (0, roomData_1.getRoomGridIndex)();
    teleport(roomGridIndex, isaac_typescript_definitions_1.Direction.NO_DIRECTION, isaac_typescript_definitions_1.RoomTransitionAnim.FADE);
}
exports.reloadRoom = reloadRoom;
/**
 * Helper function to change the current room. It can be used for both teleportation and "normal"
 * room transitions, depending on what is passed for the `direction` and `roomTransitionAnim`
 * arguments.
 *
 * Use this function instead of invoking the `Game.StartRoomTransition` method directly so that:
 * - you do not forget to set the `Level.LeaveDoor` field
 * - to prevent crashing on invalid room grid indexes
 *
 * Note that if the current floor has Curse of the Maze, it may redirect the intended teleport.
 *
 * @param roomGridIndex The room grid index of the destination room.
 * @param direction Optional. Default is `Direction.NO_DIRECTION`.
 * @param roomTransitionAnim Optional. Default is `RoomTransitionAnim.TELEPORT`.
 */
function teleport(roomGridIndex, direction = isaac_typescript_definitions_1.Direction.NO_DIRECTION, roomTransitionAnim = isaac_typescript_definitions_1.RoomTransitionAnim.TELEPORT) {
    const level = cachedClasses_1.game.GetLevel();
    const roomData = (0, roomData_1.getRoomData)(roomGridIndex);
    (0, utils_1.assertDefined)(roomData, `Failed to change the room to grid index ${roomGridIndex} because that room does not exist.`);
    // This must be set before every `Game.StartRoomTransition` method invocation or else the function
    // can send you to the wrong room.
    level.LeaveDoor = isaac_typescript_definitions_1.DoorSlot.NO_DOOR_SLOT;
    cachedClasses_1.game.StartRoomTransition(roomGridIndex, direction, roomTransitionAnim);
}
exports.teleport = teleport;
