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 = {
{21,'*2 -50 wave'},
{23,'*2 50 wave'},

{25,'*5 -50 wave'},
{27,'*2 50 wave'},

{29,'*5 -50 wave'},
{31,'*2 50 wave'},

{33,'*5 -50 wave'},
{35,'*2 50 wave'},

{36.5,'*2 0 wave'},

{37,'*0.25 25% tipsy'},
{37.5,'*0.25 100% tipsyoffset'},

{66,'*2 100% dark'},
{67,'*5 0% tipsy'},
{68,'*2 0% dark'},

{69,'*0.5 100 wave'},
{72,'*5 0 wave'},

{77,'*0.5 100 wave'},
{80,'*5 0 wave'},

{85,'*0.5 100 wave'},
{88,'*5 0 wave'},

{101,'*0.25 25% tipsy'},
{101.5,'*0.25 100% tipsyoffset'},

{130,'*2 100% dark'},
{132,'*2 0% dark'},

{132.1,'*5 0% tipsy'},

{133,'*0.25 -100 wave'},
{137,'*0.25 0 wave'},

{141,'*0.25 -100 wave'},
{145,'*0.25 0 wave'},

{149,'*0.25 -100 wave'},
{153,'*0.25 0 wave'},

{157,'*0.25 -100 wave'},
{161,'*0.25 0 wave'},

{165.75,'*0.1 10 confusion'},
{166.5,'*5 0 confusion'},

{167.75,'*0.1 -10 confusion'},
{168.5,'*5 0 confusion'},

{173.75,'*0.1 10 confusion'},
{174.5,'*5 0 confusion'},

{175.75,'*0.1 -10 confusion'},
{176.5,'*5 0 confusion'},

{181.75,'*0.1 10 confusion'},
{182.5,'*5 0 confusion'},

{183.75,'*0.1 -10 confusion'},
{184.5,'*5 0 confusion'},

{189.75,'*0.1 10 confusion'},
{190.5,'*5 0 confusion'},

{191.75,'*0.1 -10 confusion'},
{192.5,'*5 0 confusion'},

{195.75,'*0.1 10 confusion'},
{196.5,'*0.1 0 confusion'},

-- {90,'*2 0 mini'}, --clearall
-- {90,'*2 -70 mini'},
-- {103,'*2 -50 mini'},
-- {124,'*2 -70 mini'},
-- {136,'*2 0 mini'}, --clearall
-- {160,'*2 0 mini'}, --clearall
-- {199,'*1 -75 mini'},
-- {225,'*2 -100 mini'},
-- {232,'*2 0 mini'}, --clearall
-- {232,'*2 -100 beat'},
-- {264,'*2 -150 beat'},
-- {295,'*2 0 beat'}, --clearall
-- {298,'*2 -100 beat'},
-- {330,'*2 -150 beat'},
-- {351,'*2 0 beat'}, --clearall
-- {354,'*0.125 100 dark'},
-- {355,'*0.5 -450 mini'},
--{358,'*2 -600 mini'},
}

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),
	},
}