local vector2 = require("#microsoft.xna.framework.vector2")
local coroutineEntity = monocle.Entity()

function onBegin()
    disableRetry()
    disableMovement()
	walkTo(15324, false, 0.9, false)
	celeste.Audio.SetMusicParam("dialog", 1.0)
	celeste.Audio.SetMusicParam("kick", 0.0)
	say("SJ2021_SOLOIINI_SPECTACLE_A")
	engine.Scene:add(coroutineEntity)
	coroutineEntity:add(monocle.Coroutine(getLevel():ZoomTo(vector2(148, 80), 1.15, 0.5)))
	say("SJ2021_SOLOIINI_SPECTACLE_B")
	coroutineEntity:add(monocle.Coroutine(getLevel():ZoomAcross(vector2(148, 75), 1.3, 0.5)))
	say("SJ2021_SOLOIINI_SPECTACLE_C")
	coroutineEntity:add(monocle.Coroutine(getLevel():ZoomAcross(vector2(148, 70), 1.45, 0.5)))
	say("SJ2021_SOLOIINI_SPECTACLE_D")
	coroutineEntity:add(monocle.Coroutine(getLevel():ZoomAcross(vector2(148, 90), 1.1, 0.5)))
	say("SJ2021_SOLOIINI_SPECTACLE_E")
	playSound("event:/Kataiser/nelumbo_fire_on")
	wait(0.02)
	setFlag("spectacleBFout", true)
	setFlag("spectacleFireSFX", false)
	if not getFlag("SJ_Solar_noFlash") then
		   setFlag("spectacleOpenRift", true)
		end
	wait(0.18)
	celeste.Audio.SetMusicParam("kick", 1.0)
	setFlag("spectaclePortal", true)
	setFlag("spectacleOpenRift", false)
	player.DummyAutoAnimate = false
	player.Sprite:Play("runSlow", true, false)
	walkTo(15296, false, 0.6, false)
	setFlag("spectacleBFout", false)
	player.Sprite:Play("runFast", true, false)
	walkTo(15284, false, 0.2, false)
	player.Sprite:Play("runStumble", true, false)
	walkTo(15408, true, 1.6, false)
	player.DummyAutoAnimate = true
	coroutine.yield(getLevel():ZoomBack(0.01))
    end

function onEnd(level, wasSkipped)
	getLevel():remove(coroutineEntity)
    player.Facing = luanet.enum(luanet.import_type("Celeste.Facings"), "Right")
	celeste.Audio.SetMusicParam("kick", 1.0)
	teleportTo(16176, -1656, "Halcyon Promenade")
    enableRetry()
    enableMovement()
	if wasSkipped then
		setFlag("spectacle_skipped", true)
	end
end