local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local Direction = ____isaac_2Dtypescript_2Ddefinitions.Direction
local DoorSlot = ____isaac_2Dtypescript_2Ddefinitions.DoorSlot
local RoomTransitionAnim = ____isaac_2Dtypescript_2Ddefinitions.RoomTransitionAnim
local ____cachedClasses = require("core.cachedClasses")
local game = ____cachedClasses.game
local ____roomData = require("functions.roomData")
local getRoomData = ____roomData.getRoomData
local getRoomGridIndex = ____roomData.getRoomGridIndex
local ____utils = require("functions.utils")
local assertDefined = ____utils.assertDefined
--- 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 ____exports.teleport(self, roomGridIndex, direction, roomTransitionAnim)
    if direction == nil then
        direction = Direction.NO_DIRECTION
    end
    if roomTransitionAnim == nil then
        roomTransitionAnim = RoomTransitionAnim.TELEPORT
    end
    local level = game:GetLevel()
    local roomData = getRoomData(nil, roomGridIndex)
    assertDefined(
        nil,
        roomData,
        ("Failed to change the room to grid index " .. tostring(roomGridIndex)) .. " because that room does not exist."
    )
    level.LeaveDoor = DoorSlot.NO_DOOR_SLOT
    game:StartRoomTransition(roomGridIndex, direction, roomTransitionAnim)
end
--- 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 ____exports.reloadRoom(self)
    local roomGridIndex = getRoomGridIndex(nil)
    ____exports.teleport(nil, roomGridIndex, Direction.NO_DIRECTION, RoomTransitionAnim.FADE)
end
return ____exports
