function selectProject()


	mouse.set(nothing)
	config.currentProject = nil
	
	if splashScreen.refresh or (not splashScreen.items) or (#splashScreen.items-3~=lume.count(config.projects)) then 
		splashScreen.items={}
		update = function(item,i)
			local opti = i-lume.count(config.projects)
			if item.opt then 
				item.x =   (screenWidth-170)
				item.y =   (screenHeight-opti*32) +32
				item.w = 150
			else
				item.x = mf((item.new and 150 or 100))
				item.y = mf((item.new and 120+i*32+16 or  120+i*32))
				item.w = mf(200+(item.new and -80  or 0))
			end
			item.h = 25
			item.hovered = mouseIn(item,{x=lmouse.getX(),y=lmouse.getY()})
			item.a = item.a or 0
			item.a = item.a + ((item.hovered and 1 or 0)-item.a)/4
			if item.hovered then 
				lmouse.setCursor(hand)
				mouse.set(function()item.click(item) end)
			end
		end
		draw = function(item)
			gfx.push()
			gfx.translate(item.x,item.y)
			gfx.setColor(0,0,0,item.a*0.5)
			gfx.rectangle("fill",-4,-2, item.w,item.h,2)
			gfx.setColor(1,1,1,0.3)
			gfx.rectangle("line",-4,-2, item.w,item.h,2)
			gfx.setColor(1,1,1,1)
			gfx.print(item.text or item.name,3,2.5)
			if item.new then 
				gfx.print("+",-20,2.5)
			end
			gfx.pop()
		end

		local numProjects = lume.count(config.projects)
		if numProjects>0 then 
			print("\n"..numProjects.." projects found :")
			for p,project in pairs(config.projects) do
				if  project.dir and project.path then 
					local ext = ".project"
					local proj = (project.dir.."/"..project.name..ext):gsub("//","/")
					print("  --> "..proj)
					if   exists(proj) then
						print("    -> exists!") 
						if exists(proj.."/.config") and not lfs.exists("projects/"..project.name) then 
							print("link "..proj.."  to  "..SAVE_DIR.."projects")
							os_link(proj, SAVE_DIR.."projects")
							local name2 = SAVE_DIR.."projects/"..project.name
							local name1 = name2..".project"
							print("file to folder")
							os.rename(name1,name2)
						end
					else
						print("nilled "..proj)
						config.projects[p]=nil
					end
				else 
					config.projects[p]=nil
				end
				print("")
			end
			for p,project in pairs(config.projects) do
				table.insert(splashScreen.items,{
					name = project.name,
					update=update,
					draw=draw,
					click=function(item)
						loadProject(item.name)
					end
				})
			end
		end

		table.insert(splashScreen.items,{
			new = true,
			text = "New Game",
			update=update,
			draw=draw,
			click=function(item)
				newProject()
				splashScreen.refresh=true
			end
		})
		table.insert(splashScreen.items,{
			new = true,
			text = "New Animation",
			update=update,
			draw=draw,
			click=function(item)
				local name = newProject(true)
				saveConfig()
				splashScreen.refresh=true
				loadProject(name,true)
			end
		})
		table.insert(splashScreen.items,{
			opt=true,
			text = "Toggle Autoload: "..(config.autoload and "On" or "Off"),
			update=update,
			draw=draw,
			click=function(item)
				config.autoload = not config.autoload
				saveConfig()
				splashScreen.refresh=true
			end
		})
		splashScreen.refresh=false
	end
	lmouse.setCursor()
	for i,item in ipairs(splashScreen.items) do
		item:update(i) 
	end
	saveConfig()
end

local msaaTest
function drawProjects()
	-- msaaTest=msaaTest or gfx.newCanvas(100,100,{msaa=4})
	-- gfx.setCanvas(msaaTest)
	-- gfx.circle("fill",10,10,50)
	-- gfx.setCanvas()
	-- gfx.draw(msaaTest)

	gfx.push("all")
	
	gfx.clear(0.1,0.13,0.18,1)
	gfx.fontSize(20)

	gfx.print(lume.count(config.projects)==0 and "looks like you don't have any projects" or "projects",50,40)

	gfx.fontSize(14)

	gfx.print(" - drag a folder into the window to set the default project location",50,80)
	gfx.print(" - or drag a .project project into the window to add it",50,100)
	
	gfx.setLineWidth(2)
	if splashScreen.items then 
		for i,item in ipairs(splashScreen.items) do
			item:draw() 
		end
	end

	gfx.fontSize(10)
	gfx.setColor(0,0,0,0.3)
	gfx.rectangle("fill",0,gfx.getHeight()-17,gfx.getWidth(),20)
	gfx.setColor(1,1,1,0.3)
	gfx.print("default project location: ")--..config.defaultProjectLocation,4,gfx.getHeight()-14)
	gfx.pop()

end

function newProject(anim)
	if anim then ZIP_MODE = true end
	local name1 = "Untitled "..nextUntitled(config.projects)
	local name2 = name1--..".project"
	local dir = (ZIP_MODE and "projects" or config.defaultProjectLocation).."/"..name2
	config.projects[name1]={
		name=name1,
		dir=config.defaultProjectLocation,
		path=ZIP_MODE and config.defaultProjectLocation or dir,
		modtime=os.time()
	}
	mkdir(dir)
	mkdir(dir.."/images")
	mkdir(dir.."/scripts")
	mkdir(dir.."/models")
	mkdir(dir.."/levels")
	mkdir(dir.."/audio")
	mkdir(dir.."/definitions")
	if anim then 
		mkdir(dir.."/export")
	end
	if not ZIP_MODE then 
		os_link(dir, SAVE_DIR.."projects")
	end
	os.rename(SAVE_DIR.."projects/"..name2,SAVE_DIR.."projects/"..name1)
	loader:writeFile(SAVE_DIR.."projects/"..name1.."/.config",Tserial.pack({preview=false,isAnim=anim},false,true))
	return name1
end

function nextUntitled(t)
	local nextUntitled = 0
	for k,v in pairs(t) do
		if type(v)=="table"  then 
			local n = tonumber(v.name:sub(10))
			if v.name:sub(1,9) == "Untitled " and type(n)=="number" and n>nextUntitled then 
				nextUntitled = n
			end
		end
	end
	return nextUntitled+1
end

function mkdir(...)
	local dir = ""
	for i,sub in ipairs({...}) do 
		dir = dir.."/"..sub
		if ZIP_MODE then 
			lfs.createDirectory(dir)
		else
			os.execute("mkdir \""..dir.."\"")
		end
	end
end

-- function os_rm(...)
-- 	local dir = ""
-- 	for i,sub in ipairs({...}) do 
-- 		dir = dir.."/"..sub
-- 		os.execute("mkdir \""..dir.."\"")
-- 	end
-- end

function os_link(dir1,dir2)
	os.execute("ln -s \""..dir1.."\" \""..dir2.."\"")
end
