local teleportsFull = {
    {name = "map_reflection", room = "f08", X = 2542, Y = 1380},
    {name = "map_oldsite", room = "e05", X = 1430, Y = 2028},
    {name = "map_temple", room = "i05", X = 691, Y = 1732},
    {name = "map_resort", room = "d02", X = -602, Y = 2668},
    {name = "map_city", room = "c03", X = -962, Y = 1556},
    {name = "map_ridge", room = "b09", X = -2242, Y = 1556},
    {name = "map_summit", room =  "a06", X = -482, Y = 268},
    {name = "map_core", room = "h06", X = 944, Y = 633},
    {name = "map_farewell", room = "g07", X = 2382, Y = 460},

}

local teleports = {}

local currArea = 1

function nextArea()





    log(teleports[1])

    if currArea + 1 > #teleports then
        currArea = 1
        coroutine.yield(celeste.CutsceneEntity.CameraTo(vector2(teleports[currArea].X + 16, teleports[currArea].Y + 16), 0.5))
        return
    end

    currArea = currArea + 1

    coroutine.yield(celeste.CutsceneEntity.CameraTo(vector2(teleports[currArea].X + 16, teleports[currArea].Y + 16), 0.5))
end

function prevArea()
    if currArea - 1 < 1 then
        currArea = #teleports
        coroutine.yield(celeste.CutsceneEntity.CameraTo(vector2(teleports[currArea].X + 16, teleports[currArea].Y + 16), 0.5))
        return
    end

    currArea = currArea - 1

    coroutine.yield(celeste.CutsceneEntity.CameraTo(vector2(teleports[currArea].X + 16, teleports[currArea].Y + 16), 0.5))
end



function onTalk()
    disableMovement()
    disableRetry()

    local letters = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'}

    for _, value in ipairs(letters) do
        if getFlag('ChallengeActive_'..value) then
            
        
            say("GREENcontest25_grog_notravel")

            return

        end
    end


    setFlag("inMap", true)
    

    for _, value in ipairs(teleportsFull) do
        if getFlag("explored_"..value.room) then
            teleports[#teleports+1] = value
        end
    end

    


    local currentRoom = arguments

    if not getFlag("seenBench") then
        say("GREENcontest25_grog_mapintro")
        setFlag("seenBench", true)
    end

    for index, value in ipairs(teleports) do
        if value.room == arguments then
            currArea = index
            coroutine.yield(celeste.CutsceneEntity.CameraTo(vector2(teleports[currArea].X + 16, teleports[currArea].Y + 16), 0.5))
            break
        end
    end

    

-- WARP POSITIONS

-- 2542, 1380 : Reflection
-- 2382, 460 : Farewell
-- 944, 633 : Core
-- -170, 1284 : GREENCORE
-- -586, 2668 : Resort
-- 1430, 2028 : Old Site
-- 707, 1748 : Temple
-- -2242, 1556 : Cliffside
-- -962, 1556 : City
-- -482, 268 : Summit

    

    while getFlag("inMap") do
        
        if getFlag("right") then
            nextArea()
            setFlag("right", false)
        end

        if getFlag("left") then
            prevArea()
            setFlag("left", false)
        end

        if getFlag("jump") then
            setFlag("mapBlack", true)
            wait(0.6)
            setFlag("teleport"..teleports[currArea].name, true)
            return
        end

        wait(0.1)

    end

end

function onEnd(room, wasSkipped)
    enableMovement()
    enableRetry()

    setFlag("inMap", false)
    setColorGrade("none")
end