pTime = GetFloatParam("time", 10)
gPaths = {}
gTime = 0
gCurrent = 1

function init()
	local locs = FindLocations()
	if #locs % 2 == 0 then
		for i=1, #locs, 2 do
			local index = #gPaths+1
			gPaths[index] = {}
			gPaths[index].startLoc = locs[i+0]
			gPaths[index].endLoc = locs[i+1]
			gPaths[index].duration = pTime
		end
	else
		DebugPrint(GetTranslatedStringByKey("THERE_MUST"))
	end
end


function tick(dt)
	if #gPaths > 0 then
		gTime = gTime + dt
		
		if gTime > gPaths[gCurrent].duration then
			gTime = gTime - gPaths[gCurrent].duration
			gCurrent = gCurrent + 1
			if gCurrent > #gPaths then
				gCurrent = 1
			end
		end
			
		local t = gTime / gPaths[gCurrent].duration
		local startTransform = GetLocationTransform(gPaths[gCurrent].startLoc)
		local endTransform = GetLocationTransform(gPaths[gCurrent].endLoc)
		
		local pos = VecLerp(startTransform.pos, endTransform.pos, t)
		local rot = QuatSlerp(startTransform.rot, endTransform.rot, t)
		SetCameraTransform(Transform(pos, rot))
	end
end


function draw()
	if #gPaths > 0 then
		local fadeTime = 0.5
		local alpha = 0
		if gTime <  fadeTime then
			alpha = 1.0 - gTime / fadeTime
		elseif gTime >  gPaths[gCurrent].duration - fadeTime then
			alpha = (gTime - (gPaths[gCurrent].duration-fadeTime)) / fadeTime
		end
		if alpha > 0 then
			UiColor(0,0,0,alpha)
			UiRect(UiWidth(), UiHeight())
		end
	end
end
