jumping = PlayerCanJump()
function fif(test, if_true, if_false)
  if test then return if_true else return if_false end
end

hifi = GetQualityLevel() > 2 -- GetQualityLevel returns 1,2,or 3
function ifhifi(if_true, if_false)
  if hifi then return if_true else return if_false end
end

skinvars = GetSkinProperties()
trackWidth = skinvars["trackwidth"]
--trackWidth = fif(jumping, 11.5, 7)
ispuzzle = skinvars.colorcount>1
fullsteep = jumping or skinvars.prefersteep or (not ispuzzle)

SetScene{
	glowpasses = ifhifi(2,0),
	glowspread = ifhifi(0.5,0),
	radialblur_strength = ifhifi(.75,0),
--	radialblur_strength = fif(jumping,2,0),
	--environment = "city",
	watertype = 2,
	water = jumping, --only use the water cubes in wakeboard mode
	watertint = {r=255,g=255,b=255,a=234},
	watertexture = "WaterCubesBlue_BlackTop_WhiteLowerTier.png",--texture used to color the dynamic "digital water" surface
	towropes = jumping,--use the tow ropes if jumping
	airdebris_count = ifhifi(1000,100),
	airdebris_density = ifhifi(40,2),
	airdebris_texture = "star.png",
	useblackgrid=false,
	twistmode={curvescaler=1, steepscaler=fif(fullsteep,1,.65)} -- note: "cork" is the same as {curvescaler=1, steepscaler=1} and "cork_flatish" is the same as {curvescaler=1, steepscaler=.4}
}

SetBlockFlashes{
	texture="hit2.jpg"
}
SetPuzzleGraphics{
	usesublayerclone = false,
	puzzlematchmaterial = {shader="Unlit/Transparent",texture="tileMatchingBars2.png",aniso=9},
	puzzleflyupmaterial = {shader="VertexColorUnlitTintedAddFlyup",texture="black.png"},
	puzzlematerial = {shader="VertexColorUnlitTintedAlpha2",texture="tilesSquare.png",texturewrap="clamp",aniso=9, usemipmaps="false",shadercolors={_Color={255,255,255,255}}}
}

if not jumping then
	SetBlocks{
		maxvisiblecount = fif(hifi,200,50),
		allow_mod_block_scaling = false,
		colorblocks={
			--mesh = "SingleLozenge.obj",
			mesh = "NewBlock.obj",
			reflect = true,
			--shader = fif(ispuzzle, "Diffuse", "Rim Light"),
			--shader = fif(ispuzzle, "Diffuse", "VertexColorUnlitTinted"),
			shader = fif(ispuzzle, "UnlitEdgedBlock", "UnlitEdgedBlock"),
			shadersettings={_Brightness=1.42},
			texture = "NewBlock.png",
		    height = 0,
		    float_on_water = false,
		    scale = {1,1,1}
		},
		greyblocks={
			--mesh = "singlespike.obj",
			mesh = "NewBlockSpike2.obj",
			reflect = true,
			shader = "UnlitEdgedSpike",
			texture = "NewBlock.png"
			--shader = "VertexColorUnlitTinted",
			--texture = "doublespike.png"
		},
		powerups={--override the following objects in case the mod uses them
			powerpellet={
				--mesh = squareMesh,
				mesh = "PowerStar.obj",
				--shader = fif(hifi,"MatCap/Vertex/Textured Lit Double", "MatCap/Vertex/PlainBright"),
				shader = fif(ispuzzle, "UnlitEdgedBlock", "UnlitEdgedBlock"),
				--shadersettings = fif(hifi, {_Brightness=3.0}, {_Brightness=5}),
				shadersettings={_Brightness=1.42},
				--textures = {_MainTex="White.png", _MatCap="matcapchrome.jpg"},
				texture = "NewBlock.png",
				scale = {1,1,1},
				--scale = {2.7,2.7,2.7},
				shadercolors = {_Color="highway", scaletype="intensity", minscaler=2, maxscaler=2.5},
				reflect = true
			}
		}
	}
end
if jumping then
	SetPlayer{
		--showsurfer = true,
		--showboard = true,
		cameramode = "first_jumpthird",
		--cameramode_air = "third",--"first_jumptrickthird", --start in first, go to third for jumps and tricks

		camfirst={ --sets the camera position when in first person mode. Can change this while the game is running.
			pos={0,2.7,-3.50475},
			rot={20.49113,0,0},
			strafefactor = 1
		},
		camthird={ --sets the two camera positions for 3rd person mode. lerps out towards pos2 when the song is less intense
			pos={0,2.7,-3.50475},
			rot={20.49113,0,0},
			strafefactor = 0.75,
			pos2={0,2.8,-3.50475},
			rot2={20.49113,0,0},
			strafefactorFar = 1},
		surfer={ --set all the models used to represent the surfer
			arms={
				--mesh="arm.obj",
				shader="RimLightHatchedSurfer",
				shadercolors={
					_Color={colorsource="highway", scaletype="intensity", minscaler=3, maxscaler=6, param="_Threshold", paramMin=2, paramMax=2},
					_RimColor={0,63,192}
				},
				texture="FullLeftArm_1024_wAO.png"
			},
			board={
				--mesh="wakeboard.obj",
				shader=ifhifi("RimLightHatchedSurferExternal","VertexColorUnlitTinted"), -- don't use the transparency shader in lofi mode. less fillrate needed that way
				renderqueue=3999,
				shadercolors={ --each color in the shader can be set to a static color, or change every frame like the arm model above
					_Color={colorsource="highway", scaletype="intensity", minscaler=5, maxscaler=5},
					_RimColor={0,0,0}
				},
				shadersettings={
					_Threshold=11
				},
				texture="board_internalOutline.png"
			},
			body={
				--mesh="surferbot.obj",
				shader="RimLightHatchedSurferExternal", -- don't use the transparency shader in lofi mode. less fillrate needed that way
				renderqueue=3000,
				shadercolors={
					_Color={colorsource="highway", scaletype="intensity", minscaler=3, maxscaler=3},
					_RimColor={0,0,0}
				},
				shadersettings={
					_Threshold=1.7
				},
				texture="robot_HighContrast.png"
			}
		}
	}
else
	SetPlayer{
		--showsurfer = false,
		--showboard = false,
		cameramode = "third",
	--	cameramode_air = "first",--"first_jumptrickthird", --start in first, go to third for jumps and tricks

		camthird={
			pos={0,2,-0.5},
			rot={30,0,0},
			strafefactorFar = .75,
			pos2={0,5,-4},
			rot2={30,0,0},
			strafefactorFar = 1,
			transitionspeed = 1,
			puzzleoffset=-0.65,
			puzzleoffset2=-1.5},
		vehicle={ --livecoding not supported here
			min_hover_height= 0.4,
			max_hover_height = 0.6,
			use_water_rooster = false,
            smooth_tilting = false,
            smooth_tilting_speed = 5,
            smooth_tilting_max_offset = -10,
			pos={x=0,y=0,z=0},
			mesh="Apollo.obj",
			shader="VertexColorUnlitTinted",
			layer = 14,
			renderqueue = 2000,
			shadercolors={
				_Color = {colorsource="highway", scaletype="intensity", minscaler=1, maxscaler=1.5}},
			material="Apollo2.mtl",
			scale = {x=1,y=1,z=1},
			thrusters = {crossSectionShape={{-.35,-.35,0},{-.5,0,0},{-.35,.35,0},{0,.5,0},{.35,.35,0},{.5,0,0},{.35,-.35,0}},
					perShapeNodeColorScalers={.5,1,1,1,1,1,.5},
					--shader="VertexColorUnlitTinted",
						shader="VertexColorUnlitTintedAddSmooth",
						layer = 15,
						renderqueue = 2999,
						minrenderedsize = 0.05,
						colorscaler = 2,
						extrusions=18,
						stretch=-0.4591,
					updateseconds = 0.010,
						instances={
							{pos={.23,0.21,-.8},rot={0,0,58.713},scale={.4,.4,.4}},
							{pos={-.23,0.21,-.8},rot={0,0,313.7366},scale={.4,.4,.4}},
							
						}}
		}
	}
end

SetSkybox{
	skyscreen = "Skyscreen/TheGrid"
}

---------------------------------------------MADE BY: .:Mozzie:.-----------]
track_colors_choices = {
{
	{r=0, g=0, b=0},
	{r=197, g=0, b=43},
	{r=212, g=0, b=85},
	{r=232, g=0, b=133},
	{r=191, g=0, b=141},
	{r=225, g=0, b=203},
	{r=198, g=0, b=213},
	{r=186, g=0, b=248},
	{r=136, g=0, b=240},
	{r=100, g=0, b=250},
	{r=49, g=0, b=224},
	{r=9, g=0, b=183},
	{r=0, g=27, b=246},
	{r=0, g=58, b=212},
	{r=0, g=89, b=202},
	{r=0, g=166, b=209},
	{r=0, g=238, b=247},
	{r=0, g=208, b=184},
	{r=0, g=193, b=136},
	{r=0, g=232, b=122},
	{r=0, g=205, b=73},
	{r=0, g=207, b=5},
	{r=34, g=242, b=0},
	{r=75, g=245, b=0},
	{r=118, g=237, b=0},
	{r=164, g=246, b=0},
	{r=248, g=207, b=0},
	{r=225, g=250, b=0},
	{r=236, g=115, b=0},
	{r=211, g=67, b=0},
	{r=252, g=42, b=0},
	{r=0, g=0, b=0},
},
{
	{r=0, g=0, b=0},
	{r=197, g=0, b=43},
	{r=212, g=0, b=85},
	{r=232, g=0, b=133},
	{r=191, g=0, b=141},
	{r=225, g=0, b=203},
	{r=198, g=0, b=213},
	{r=186, g=0, b=248},
	{r=136, g=0, b=240},
	{r=100, g=0, b=250},
	{r=49, g=0, b=224},
	{r=9, g=0, b=183},
	{r=0, g=27, b=246},
	{r=0, g=58, b=212},
	{r=0, g=89, b=202},
	{r=0, g=166, b=209},
	{r=0, g=238, b=247},
	{r=0, g=208, b=184},
	{r=0, g=193, b=136},
	{r=0, g=232, b=122},
	{r=0, g=205, b=73},
	{r=0, g=207, b=5},
	{r=34, g=242, b=0},
	{r=75, g=245, b=0},
	{r=118, g=237, b=0},
	{r=164, g=246, b=0},
	{r=197, g=235, b=0},
	{r=232, g=232, b=0},
	{r=248, g=207, b=0},
	{r=225, g=250, b=0},
	{r=236, g=115, b=0},
	{r=211, g=67, b=0},
	{r=252, g=42, b=0},
},
}

if skinvars.colorcount > 5 then
	blockColors={
	{r=0, g=0, b=0},
	{r=197, g=0, b=43},
	{r=212, g=0, b=85},
	{r=232, g=0, b=133},
	{r=191, g=0, b=141},
	{r=225, g=0, b=203},
	{r=198, g=0, b=213},
	{r=186, g=0, b=248},
	{r=136, g=0, b=240},
	{r=100, g=0, b=250},
	{r=49, g=0, b=224},
	{r=9, g=0, b=183},
	{r=0, g=27, b=246},
	{r=0, g=58, b=212},
	{r=0, g=89, b=202},
	{r=0, g=166, b=209},
	{r=0, g=238, b=247},
	{r=0, g=208, b=184},
	{r=0, g=193, b=136},
	{r=0, g=232, b=122},
	{r=0, g=205, b=73},
	{r=0, g=207, b=5},
	{r=34, g=242, b=0},
	{r=75, g=245, b=0},
	{r=118, g=237, b=0},
	{r=164, g=246, b=0},
	{r=197, g=235, b=0},
	{r=232, g=232, b=0},
	{r=248, g=207, b=0},
	{r=225, g=250, b=0},
	{r=236, g=115, b=0},
	{r=211, g=67, b=0},
	{r=252, g=42, b=0},
    }
end

track_colors_index = math.random(#track_colors_choices)
track_colors = track_colors_choices[track_colors_index]
SetTrackColors(track_colors)
print("random track color palette: #" .. track_colors_index)
-- in puzzle modes (eraser, vegas, pusher, and pointmain), we also need to set the blocks' colors
if ispuzzle then 
	if skinvars.colorcount < 5 then
		blockColors ={
			{r=126, g=0, b=255}, -- purple
		   {r=0, g=66, b=240}, -- blue
		   {r=255, g=189, b=15}, -- yelloworange
			{r=227, g=38, b=0} -- red
		}
	else
		blockColors ={
			{r=126, g=0, b=255}, -- purple
		   {r=0, g=66, b=240}, -- blue
		   {r=0, g=184, b=0}, -- green
		   {r=255, g=189, b=15}, -- yelloworange
			{r=227, g=38, b=0} -- red
		}
	end
	SetBlockColors(blockColors)	
end
---------------------------------------------MADE BY: .:Mozzie:.-----------]
if ispuzzle then
	CreateLight{
		type= "directional",
		railoffset = -1,
		range = 10,
		intensity = 1,
		transform = {
			position={0,2,0}, rotation={.4,346.2,0}
		},
		color={255,255,255}
	}
end

SetRings{ --setup the tracks tunnel rings. the airtexture is the tunnel used when you're up in a jump
	texture="Classic_OnBlack_1024.png",
	--texture="Classic_OnBlack",
	layer=12,
	shader="VertexColorUnlitTintedAddSmooth",
	size=18,
	percentringed=.2,--ifhifi(2,.01),-- .2,
	airtexture="wide_bits.png",
	airshader="VertexColorUnlitTintedAddSmoothNoDepth",
	airsize=16
}

wakeHeight=(ifhifi(6,2))
extraWidth = trackWidth - 5
if jumping then extraWidth = 0 end
wakeStrafe = 7.5 + extraWidth
--wakeStrafe = 14.7
if jumping then wakeHeight=2 else wakeHeight = 2 end
SetWake{ --setup the spray coming from the two pulling "boats"
	height = wakeHeight,
	fallrate = .95,
	--offsets = {{wakeStrafe,0,0}, {-wakeStrafe,0,0}, {0,0,0}},
	offsets = {{wakeStrafe,0,0}, {-wakeStrafe,0,0}},
	--strafe = wakeStrafe,
	shader = fif(jumping, "VertexColorUnlitTintedAddSmooth", "VertexColorUnlitTintedAddSmoothQuarter"),
	layer = 11,
	bottomcolor = fif{r=0,g=0,b=0},
	topcolor = {r=0,g=0,b=0}
}

CreateObject{
	name="EndCookie",
	tracknode="end",
	gameobject={
		transform={pos={0,0,126},scale={scaletype="intensity",min={55,99,900},max={66,120,900}}},
		mesh="danishCookie_boxes.obj",
		shader="VertexColorUnlitTintedAdd",
		shadercolors={
			_Color="highway"
		}
	}
}
track = GetTrack()--get the track data from the game engine


CreateObject{--skywires, the red lines in the sky. A railed object is attached to the track and moves along it with the player.
	railoffset=0,
	floatonwaterwaves = false,
	gameobject={
		name="scriptSkyWires",
		pos={x=0,y=0,z=0},
		mesh="skywires.obj",
		renderqueue=1000,
		layer=ifhifi(18,13), -- in low detail the glow camera (layer 18) is disabled, so move the skywires to the main camera's layer (13)
		shader="VertexColorUnlitTintedSkywire",
		shadercolors={
			_Color="highway",
		},
		texture="White.png",
		scale = {x=1,y=1,z=1},
		lookat = "end"
	}
}

--RAILS. rails are the bulk of the graphics in audiosurf. Each one is a 2D shape extruded down the length of the track.

if not jumping then
	local laneDividers = skinvars["lanedividers"]
	for i=1,#laneDividers do
		CreateRail{ -- lane line
			positionOffset={
				x=laneDividers[i],
				y=0.1},
			crossSectionShape={
				{x=-.07,y=0},
				{x=.07,y=0}},
			perShapeNodeColorScalers={
				1,
				1},
			colorMode="highway",
			color = {r=255,g=255,b=255},
			flatten=false,
			nodeskip = 2,
			wrapnodeshape = false,
			shader="VertexColorUnlitTinted"
		}
	end
end

CreateRail{--big cliff
	positionOffset={
		x=0,
		y=0},
	crossSectionShape={
		{x=14,y=-2},
		{x=28,y=-8},
		{x=22,y=-40},
		{x=-22,y=-40},
		{x=-28,y=-8},
		{x=-14,y=-2}
		},
	perShapeNodeColorScalers={
		1,
		1,
		.4,
		.4,
		1,
		1},
	colorMode="aurora",
	color = {r=255,g=255,b=255},
	flatten=false,
	wrapnodeshape = true,
 	layer=12,
	texture="cliffRails.png",
	fullfuture = true,--ifhifi(true,false),
	stretch = 3,
	calculatenormals = true,
	shader="Cliff"
}

if not jumping then
	CreateRail{--road surface
		positionOffset={
			x=0,
			y=0},
		crossSectionShape={
			{x=-trackWidth,y=0},
			{x=trackWidth,y=0}},
		perShapeNodeColorScalers={
			1,
			1},
		colorMode="static",
		color = {r=0,g=0,b=0,a=225},
		flatten=false,
		renderqueue = 3001,
		--texture="cliffRails.png",
		shader="VertexColorUnlitTintedAlpha"
	}
end

CreateRail{--left rail
	positionOffset={
		x=-trackWidth - .2,
		y=0},
	crossSectionShape={
		{x=-.65,y=0.5},
		{x=.3,y=0.5},
		{x=.3,y=-1},
		{x=-.65,y=-1}},
	perShapeNodeColorScalers={
		.5,
		1,
		0,
		0},
	colorMode="highway",
	color = {r=255,g=255,b=255},
	flatten=false,
	--texture="cliffRails.png",
	shader="ProximityEmissionVertexColor",
	shadercolors={_Color={r=0,g=0,b=0}},
	shadersettings={_StartDistance=3.92, _FullDistance=11.9},
	layer=12
}

CreateRail{--right rail
	positionOffset={
		x=trackWidth + .2,
		y=0},
	crossSectionShape={
		{x=-.65,y=0.5},
		{x=.3,y=0.5},
		{x=.3,y=-1},
		{x=-.65,y=-1}},
	perShapeNodeColorScalers={
		.5,
		1,
		0,
		0},
	colorMode="highway",
	color = {r=255,g=255,b=255},
	flatten=false,
	--texture="cliffRails.png",
	shader="ProximityEmissionVertexColor",
	shadercolors={_Color={r=0,g=0,b=0}},
	shadersettings={_StartDistance=3.92, _FullDistance=11.9},
	layer=12
}
if not jumping then
	auroraExtent = ifhifi(77, 22)

CreateRail{--left aurora
	positionOffset={
		x=0,
		y=-8},
	crossSectionShape={
		{x=-auroraExtent,y=.5},
		{x=-11,y=.5},
		{x=-11,y=-.5},
		{x=-auroraExtent,y=-.5}},
	perShapeNodeColorScalers={
		0,
		1,
		1,
		0},
	colorMode="aurora",
	color = {r=255,g=255,b=255},
	flatten=true,
    layer=12,
	texture="White.png",
	renderqueue=2999,
	shader="VertexColorUnlitTintedAddSmooth"
}

CreateRail{--right aurora
	positionOffset={
		x=0,
		y=-8},
	crossSectionShape={
		{x=11,y=.5},
		{x=auroraExtent,y=.5},
		{x=auroraExtent,y=-.5},
		{x=11,y=-.5}},
	perShapeNodeColorScalers={
		1,
		0,
		0,
		1},
	colorMode="aurora",
	color = {r=255,g=255,b=255},
	flatten=true,
    layer=12,
	texture="White.png",
	renderqueue=2999,
	shader="VertexColorUnlitTintedAddSmooth"
}

end