local lua_helper = celeste.Mod.LuaCutscenes.LuaHelper
local monocle = require("#monocle")
local coroutineEntity = monocle.Entity()
local resetCookie = false

function onBegin()
    local level = getLevel()
    disableMovement()
    if getFlag("cookie_complete") then
        setFlag("cookie_complete", false)
        resetCookie = true
    end
    level:add(coroutineEntity)
    coroutineEntity:add(monocle.Coroutine(celeste.CutsceneEntity.CameraTo(vector2(11792, 2742), 3)))
    playSound("event:/new_content/char/granny/dissipate")
    playSound("event:/new_content/char/granny/dissipate")
    playSound("event:/game/general/touchswitch_gate_open")
    playSound("event:/game/general/touchswitch_gate_open")
    wait(1)
    playSound("event:/ui/main/postcard_ch4_in")
    playSound("event:/ui/main/postcard_ch4_in")
    wait(1)
    coroutineEntity:add(monocle.Coroutine(level:ZoomTo(vector2(160, 90), 1.1, 4)))
    playSound("event:/ui/main/assist_button_yes")
    wait(4)
    playSound("event:/ui/main/postcard_ch4_out")
    wait(0.5)
    enableMovement()
    level:ResetZoom()
end

function onEnd(room, wasSkipped)
    getLevel():remove(coroutineEntity)
    setFlag("HeartGateZoomA_Done", true)
    if resetCookie then
        setFlag("cookie_complete", true)
    end
    enableMovement()
    level:ResetZoom()
end