local function mirror_init()
	checked = false;
	
	mod_firstSeenBeat = GAMESTATE:GetSongBeat()
end

--how can I make simple m0d?
--this will instantly turn a mod on to max and then quickly turn it off with the specified parameters
--it's a simple mod

function simple_m0d(beat,strength,mult,mod,pn)
	if not strength then strength = 400 end
	if not mult then mult = 1 end
	if not mod then mod = 'drunk' end
	
	local alive = math.max(2*mult*math.abs(strength)/100,0.25)
	
	table.insert(mods,{beat,'*100000 '..strength..' '..mod,pn});
	table.insert(mods,{beat+.1,'*'..((1/mult)*math.abs(strength)/100)..' no '..mod,pn});
end

--lua course :D
curmod = 1;
--{beat,mod,player}
mods = {
{9,'*2 50 stealth'},
{41,'*2 0 stealth'},

}

local fluct = 1

local function mirror_mod_internal(str, pn)
	local ps= GAMESTATE:GetPlayerState(pn)
	local pmods= ps:GetPlayerOptionsString('ModsLevel_Song')
	ps:SetPlayerOptions('ModsLevel_Song', pmods .. ', ' .. str)
	--GAMESTATE:ApplyGameCommand('mod,'..str, pn)
end

local function mirror_mod(str)
	for i=1,2 do
		mirror_mod_internal(str, 'PlayerNumber_P' .. i)
	end
end

local function mirror_update(self, delta)
	local beat = GAMESTATE:GetSongBeat()

	-- Collect all the mods that will be applied in this frame into one string.
	-- Mod tweening doesn't work correctly if the mods are in seperate commands.
	local mods_this_frame= {}
	local function add_mod(mod_str)
		mods_this_frame[#mods_this_frame+1]= mod_str
	end
	local function execute_mods()
		if #mods_this_frame <= 0 then return end
		local total_mod_str= ""
		for i, ms in ipairs(mods_this_frame) do
			if #total_mod_str > 0 then
				total_mod_str= total_mod_str .. ", "
			end
			total_mod_str= total_mod_str .. ms
		end
		mirror_mod(total_mod_str)
	end
	
	while curmod<= #mods and GAMESTATE:GetSongBeat()>=mods[curmod][1] do
		if table.getn(mods[curmod]) < 3 then
			add_mod(mods[curmod][2])
		else
			mirror_mod_internal(mods[curmod][2], 'PlayerNumber_P' .. mods[curmod][3])
		end
		curmod = curmod+1
	end

	execute_mods()
end


return Def.ActorFrame{
	OnCommand= function(self)
		mirror_init()
		self:SetUpdateFunction(mirror_update)
							
		end,
	Def.Quad{
		Name= "I may be sleeping, but I preserve the world.",
		InitCommand= cmd(visible,false),
		OnCommand= cmd(sleep,1000),
	},
}