IsRecording = false
IsRecorded = false

SetBool("game.path.show", true)

function tick()
	local alarm_enabled = GetBool("level.alarm")

	if alarm_enabled and not IsRecording and not IsRecorded then
		StartRecording()
	elseif IsRecording and (GetString("level.state") ~= "" or (not alarm_enabled and GetBool("game.path.recording"))) then
		StopRecording()
	end
end

function StartRecording()
	Command("game.path.record")
	IsRecording = true
end

function StopRecording()
	if GetBool("game.path.recording") then
		Command("game.path.stop")
		Command("game.path.save", GetString("game.levelid").."-last")
		IsRecording = false
		IsRecorded = true
	end
end
