local ret = ... or {}

local OldRedir = ret.Redir;
ret.Redir = function(sButton, sElement)
	-- To redirect files for Up to Down:
	-- if sButton == "Up" then sButton = "Down"; end

	if not (sElement == "Hold Body Active") and
	   not (sElement == "Hold Body Inactive") and
	   not (sElement == "Hold Bottomcap Active") and
	   not (sElement == "Hold Bottomcap Inactive")  and
	   not (sElement == "Roll Body Active") and
	   not (sElement == "Roll Body Inactive") and
	   not (sElement == "Roll Bottomcap Active") and
	   not (sElement == "Roll Bottomcap Inactive")
	then
		if sButton == "Up"
		then
		   sButton = "Left"
		end 
		if sButton == "Right"
		then
		   sButton = "Down"
		end 
	end

	return sButton, sElement;
end

ret.Rotate =
{
	Up = 90,
	Down = 0,
	Left = 0,
	Right = -90,
	UpLeft = 135,
	UpRight = 225,
};

ret.RedirTable =
{
	Up = "Left",
	Down = "Down",
	Left = "Left",
	Right = "Down",
	UpLeft = "Down",
	UpRight = "Down",
};

ret.PartsToRotate =
{
	["Receptor"] = false,
	["Go Receptor"] = false,
	["Ready Receptor"] = false,
	["Tap Note"] = true,
	["Tap Mine"] = true,
	["Tap Lift"] = true,
	["Tap Fake"] = true,
	["Hold Head Active"] = true,
	["Hold Head Inactive"] = true,
	["Roll Head Active"] = true,
	["Roll Head Inactive"] = true,
	["Explosion"] = true,
};

ret.Blank =
{
	["Hold Topcap Active"] = true,
	["Hold Topcap Inactive"] = true,
	["Hold Tail Active"] = true,
	["Hold Tail Inactive"] = true,
	["Roll Topcap Active"] = true,
	["Roll Topcap Inactive"] = true,
	["Roll Tail Active"] = true,
	["Roll Tail Inactive"] = true,
	["Roll Explosion"] = false,
};

local function func()
	local sButton = Var "Button";
	local sElement = Var "Element";

	if ret.Blank[sElement] then
		-- Return a blank element.  If SpriteOnly is set,
		-- we need to return a sprite; otherwise just return
		-- a dummy actor.
		local t;
		if Var "SpriteOnly" then
			t = LoadActor( "_blank" );
		else
			t = Def.Actor {};
		end
		return t .. {
			function(self)
				self:visible(false)
			end;
		};
	end

	local sButtonToLoad, sElementToLoad = ret.Redir(sButton, sElement);
	assert( sButtonToLoad );
	assert( sElementToLoad );

	local sPath = NOTESKIN:GetPath( sButtonToLoad, sElementToLoad );

	local t = LoadActor( sPath );

	if ret.PartsToRotate[sElement] then
		t.BaseRotationZ = ret.Rotate[sButton];
	end

	return t;
end

-- This is the only required function.
ret.Load = func;

-- Use this to override the game types' default Load() functions.
ret.CommonLoad = func;

return ret;
