-- the mysterious middle, now with only one function, but WHAT a function it is!

local function RealtimeSDG(pn)
	local JudgeNames = {
		"TapNoteScore_W1",
		"TapNoteScore_W2",
		"TapNoteScore_W3",
		"TapNoteScore_W4",
		"TapNoteScore_W5",
		"TapNoteScore_Miss",
	};
	
	local PlayerStats = STATSMAN:GetCurStageStats():GetPlayerStageStats(pn);
	local totalSteps = GAMESTATE:GetCurrentSteps(pn):GetRadarValues(pn):GetValue('RadarCategory_TapsAndHolds');
	local startX = pn == PLAYER_1 and 3 or -3;
	local barSize = 7;
	local nextPos = pn == PLAYER_1 and -barSize or barSize;
	
	local x = Def.ActorFrame{};
	
	for i = 1,#JudgeNames do
		x[#x+1] = LoadActor("_sdg bar")..{
			Name="Bar"..i..pn;
			InitCommand=cmd(zoomto,8,0;x,startX+(i*nextPos);y,30;diffuse,JudgeColor(JudgeNames[i]));
			BeginCommand=cmd(vertalign,bottom;ztest,true);
			JudgmentMessageCommand=function(self,params)
				if params.Player ~= pn then return end;
				if not params.TapNoteScore then return end;
				self:zoomy((PlayerStats:GetTapNoteScores(JudgeNames[i]) / totalSteps ) * 60);
			end;
		};
	end;
	
	return x;
end;

local t = Def.ActorFrame{
	-- let's start with the frame:
	LoadActor("_middle section1")..{
		Name="MiddleWithDivider";
		InitCommand=cmd();
	};
	
	-- then the mask
	LoadActor("_middle mask")..{
		InitCommand=cmd(clearzbuffer,true;zwrite,true;blend,'BlendMode_NoEffect');
	};
};

-- and since it was being bitchy let's add shit this way
for pn in ivalues(GAMESTATE:GetHumanPlayers()) do
	t[#t+1] = RealtimeSDG(pn);
end;

return t;

-- coded by Synikal over a Winter