-- this separator works only in case of outfox default theme with 0% mini.
local param = ...
local pe = param.pe and param.pe or {true,false}
local color = param.color and param.color or {1,1,1,1}
local mode = param.mode and param.mode or 'alpha'
local songdir = GAMESTATE:GetCurrentSong():GetSongDir()
local wr = SCREEN_WIDTH/1280
local sw, sh = SCREEN_WIDTH, SCREEN_HEIGHT
local scx, scy = SCREEN_CENTER_X, SCREEN_CENTER_Y
local lanes = {-152,-87,-49,-19,19,49,87,117,155}
local stealth
local pn = GAMESTATE:GetMasterPlayerNumber() and tonumber(string.sub(GAMESTATE:GetMasterPlayerNumber(),-1,-1)) or 1

local function pa_fmod(int, base)
	return int - math.floor(int/base)*base
end

local af = Def.ActorFrame{
Name='Player',
InitCommand=function(self)
	local zoom = 1.5
	zoom = SCREENMAN:GetTopScreen():GetChild('PlayerP'..pn):GetZoom()
	self:fov(90):visible(false):zoom(zoom)
	if ActorFrame.fardistz then self:fardistz(sw*1.5) end
end}

local divider = Def.ActorFrame{Name='Divider'}
local BG = Def.ActorFrame{Name='BG'}
for i = 1, #lanes do
	divider[#divider+1] = Def.ActorMultiVertex{
		InitCommand=function(self)
			self:SetVertices{
				{{-1,-scy,0}, color},
				{{-1, scy*13/32,0}, color},
				{{ 0,-scy,4}, color},
				{{ 0, scy*13/32,4}, color},
				{{ 1,-scy,0}, color},
				{{ 1, scy*13/32,0}, color},
				{{ 0,-scy,-4}, color},
				{{ 0, scy*13/32,-4}, color},
				{{-1,-scy,0}, color},
				{{-1, scy*13/32,0}, color},
			}:SetDrawState{First=1,Num=-1,Mode='DrawMode_QuadStrip'}:x(lanes[i]):z(4)
			self:queuecommand('Update')
		end,
	}
end
for i = 1, #lanes-1 do
	BG[#BG+1] = Def.ActorMultiVertex{
		InitCommand=function(self)
			local v
			if mode == 'alpha' then
				v = {
					{{lanes[i],-scy,4}, {1,1,1,pa_fmod(i,2)*0.2}},
					{{lanes[i], scy*13/32,4}, {1,1,1,pa_fmod(i,2)*0.2}},
					{{lanes[i+1], scy*13/32,4}, {1,1,1,pa_fmod(i,2)*0.2}},
					{{lanes[i+1],-scy,4}, {1,1,1,pa_fmod(i,2)*0.2}}
				}
			else
				v = {
					{{lanes[i],-scy,4}, {pa_fmod(i,2)*0.1,pa_fmod(i,2)*0.1,pa_fmod(i,2)*0.1,1}},
					{{lanes[i], scy*13/32,4}, {pa_fmod(i,2)*0.1,pa_fmod(i,2)*0.1,pa_fmod(i,2)*0.1,1}},
					{{lanes[i+1], scy*13/32,4}, {pa_fmod(i,2)*0.1,pa_fmod(i,2)*0.1,pa_fmod(i,2)*0.1,1}},
					{{lanes[i+1],-scy,4}, {pa_fmod(i,2)*0.1,pa_fmod(i,2)*0.1,pa_fmod(i,2)*0.1,1}}
				}
			end
			self:SetVertices(v):SetDrawState{First=1,Num=-1,Mode='DrawMode_Quads'}
		end,
	}
end

local initc = function(self) self:zoomx(-(pn-1.5)*2):zoomy(1/wr):queuecommand('Update') end
local updc = function(self)
	stealth = GAMESTATE:GetPlayerState(pn-1):GetPlayerOptions('ModsLevel_Song'):Stealth()
	self:diffusealpha(1-stealth):sleep(1/120):queuecommand('Update')
end

divider['InitCommand'] = initc
divider['UpdateCommand'] = updc
BG['InitCommand'] = initc
BG['UpdateCommand'] = updc

-- Single/Versus compatibility.
local IsSingle = false
local IsVersus = false
if GAMESTATE:GetCurrentStyle():GetStepsType() == 'StepsType_Dance_Single' then
	IsSingle = true

	if pe[1] and pe[2] then
		IsVersus = true
	end
end

af[#af+1] = BG
af[#af+1] = divider
af[#af+1] = Def.ActorProxy{
	-- In this system, InitCommands in FG things are executed at beat 0. We can use SCREENMAN:GetTopScreen() in InitCommand.
	InitCommand=function(self)
		self:SetTarget(SCREENMAN:GetTopScreen():GetChild('PlayerP'..pn):GetChild('NoteField')):visible(true)
		SCREENMAN:GetTopScreen():GetChild('PlayerP'..pn):visible(false):fov(90):basezoom(1/wr)
	end
}
af[#af+1] = Def.ActorProxy{
	InitCommand=function(self)
		self:SetTarget(SCREENMAN:GetTopScreen():GetChild('PlayerP'..pn):GetChild('Combo')):visible(true)
		SCREENMAN:GetTopScreen():GetChild('PlayerP'..pn):visible(false):fov(90):basezoom(1/wr)
	end
}
af[#af+1] = Def.ActorProxy{
	InitCommand=function(self)
		self:SetTarget(SCREENMAN:GetTopScreen():GetChild('PlayerP'..pn):GetChild('Judgment')):visible(true)
		SCREENMAN:GetTopScreen():GetChild('PlayerP'..pn):visible(false):fov(90):basezoom(1/wr)
end
}
divider[#divider+1] = Def.Sprite{
	Name='pikapika',
	Texture=songdir..'fg/texture/pikapika.png',
	InitCommand=function(self)
		self:x(159+64*0.5):zoom(0.5):blend('BlendMode_Add'):diffusealpha(0.75):texcoordvelocity(0,-0.05)
	end,
}
divider[#divider+1] = Def.Sprite{
	name='coin',
	Texture=songdir..'fg/texture/coin',
	Frames={
		{Frame=0, Delay=0.06},
		{Frame=1, Delay=0.06},
		{Frame=2, Delay=0.06},
		{Frame=3, Delay=0.06},
		{Frame=4, Delay=0.06},
		{Frame=5, Delay=0.06},
	},
	InitCommand=function(self) self:x(-118):y(112):zoom(1.5):diffusealpha(0):animate(0) end,
	CoinMessageCommand=function(self)
		self:animate(1):diffusealpha(1):decelerate(0.25):addy(-64):accelerate(0.25):addy(64):linear(0):diffusealpha(0)
	end,
}
return af