-- Simulate VC menu specific bound functions when using generic reed player
isFirstLaunch = false


local keyConfigurations = {
		{1, 2 ,3 ,4, 14, 14, 12, 14, 9, 10 ,11, 13 },
		{1, 2 ,3 ,4, 14, 14, 12, 14, 9, 10 ,11, 13 },
		{1, 2 ,3 ,4, 14, 14, 12, 14, 9, 10 ,11, 13 },
		{1, 2 ,3 ,4, 14, 14, 12, 14, 9, 10 ,11, 13 },
		{1, 2 ,3 ,4, 14, 14, 12, 14, 9, 10 ,11, 13 },
		{1, 2 ,3 ,4, 14, 14, 12, 14, 9 ,10 ,11, 13 },
		{1, 2 ,3 ,4, 14, 14, 12, 14, 9, 10 ,11, 13 },
		{1, 2 ,3 ,4, 14, 14, 12, 14, 9, 10 ,11, 13 }
}


if not VC_hasState then	
	VC_hasState = function()
		return true
	end
end

if not VC_saveState then	
	VC_saveState = function()
	end
end

if not VC_isUseSRAM then
	VC_isUseSRAM = function()
		return 1
	end
end

if not VC_isSaveFinished then
	VC_isSaveFinished = function()
		if g_menu.timer == g_menu.timer2 + 300 then
			return 1
		else
			return 0
		end
	end
end

if not VC_saveStarted then
	VC_saveStarted = function()
		print("save start")
	end
end

if not VC_saveFinished then
	VC_saveFinished = function()
		print("save finished")
	end
end

if not VC_isHomePressed then
	VC_isHomePressed = function()
		if g_menu.timer == g_menu.timer2 + 299 or g_menu.timer == g_menu.timer2 + 100 or  g_menu.timer == g_menu.timer2 + 110 then
			return 1
		else
			return 0
		end
	end
end

if not VC_restoreState then
	VC_restoreState = function()
	end
end

VC_getSaveStateDate = function()
	return VC_getSaveStateYear(), VC_getSaveStateMonth(), VC_getSaveStateDay(), VC_getSaveStateHour(), VC_getSaveStateMinute(), VC_getSaveStateSecond()
end


if not VC_getSaveStateYear then	
	VC_getSaveStateYear = function()
		return 2014
	end
end

if not VC_getSaveStateMonth then	
	VC_getSaveStateMonth = function()
		return 07
	end
end

if not VC_getSaveStateDay then	
	VC_getSaveStateDay = function()
		return 17
	end
end

if not VC_getSaveStateHour then	
	VC_getSaveStateHour = function()
		return 12
	end
end

if not VC_getSaveStateMinute then	
	VC_getSaveStateMinute = function()
		return 12
	end
end

if not VC_getSaveStateSecond then	
	VC_getSaveStateSecond = function()
		return 12
	end
end

if not VC_reset then
	VC_reset = function()
	end
end

if not VC_quitMenu then
	VC_quitMenu = function()
	end
end

if not VC_getPlatformLanguage then
	VC_getPlatformLanguage = function()
		return 0
	end
end

if not VC_getNumberOfPlayers then
	VC_getNumberOfPlayers = function()
		return 4
	end
end

if not VC_openBrowser then
	VC_openBrowser = function(url)
		print("open url : "..url)
	end
end

if not VC_openPDF then
	VC_openPDF = function()
	end
end


if not VC_replaceTexture then
	VC_hasBgTextureForScreen = function(id)
		return false
	end
	
	VC_replaceTexture = function(resource, screen)
	end
end

if not VC_playSound then
	VC_playSound = function(sound)
	end
end

if not VC_playSoundId then
	VC_playSoundId = function(id)
		print("Play sound " .. id)
	end
end

if not VC_stopSounds then
	VC_stopSounds = function()
	end
end

if not VC_getControllerType then
	VC_getControllerType = function(index)
		local controllerType = {nil, "drc", "cla", "urcc"}
		local idx
		for i = 1, 4 do
			if controllerType[i] == connectedControllersInfo[index].controller_type then
				idx = i - 1
				break
			end
		end
		return idx
	end
end

if not VC_getControllerPlayerID then
	VC_getControllerPlayerID = function(index)
		local idx
		if connectedControllersInfo[1].playerId ~= nil then
			idx = connectedControllersInfo[1].playerId
		else 
			idx = 0 
		end
		return idx
	end
end

if not VC_getControllerInvoker then
	VC_getControllerInvoker = function(index)
		local invoker = {nil, nil, true}
		local idx
		for i = 1, 3 do
			if invoker[i]  == connectedControllersInfo[index].invoker then
				idx = i - 1
				break
			end
		end
		return idx
	end
end

if not VC_setDRC0PlayID then
	VC_setDRC0PlayID = function(id)
		connectedControllersInfo[1].playerId = id + 1
	end
end

if not VC_getKeyConfig then
	VC_getKeyConfig = function(mapindex, keyindex)
		return keyConfigurations[mapindex][keyindex]
	end
end

if not VC_setKeyConfig then
	VC_setKeyConfig = function(mapindex, keyindex, n64key)
		keyConfigurations[mapindex][keyindex] = n64key
	end
end

function VC_getKeyConfigurations()
	local configs = {}
	for i = 1, 8 do
		configs[i] ={}
		for j = 1, 12 do
			configs[i][j] = clamp(VC_getKeyConfig(i, j), 1, 14)
		end
	end
	return configs
end

function VC_setKeyConfigMap(mapindex, binding)
	for i = 1, 12 do
		VC_setKeyConfig(mapindex, i, binding[i])
	end
end

if not VC_saveKeyConfigFile then
	VC_saveKeyConfigFile = function()
		print("Key config file saved!")	
	end
end


if not VC_drcGameScreenOff then
	VC_drcGameScreenOff = function ()
	end
end


function VC_setControllerInfo()
	local controllerType = {nil, "drc", "cla", "urcc"}
	local playerid = {nil, 1, 2, 3, 4}
	local invoker = {nil, nil, true}

	for i = 1, 5 do
		if i == 1 then 
			connectedControllers[1].playerId = playerid[VC_getControllerPlayerID(1) + 1]
		end
		connectedControllers[i].controller_type = controllerType[VC_getControllerType(i) + 1]			
		connectedControllers[i].invoker = invoker[VC_getControllerInvoker(i) + 1]
	end
	-- print(connectedControllers[i].controller_type)
	-- print(connectedControllers[i].playerId)
	-- print(connectedControllers[i].invoker)


end

function VC_invokeMenu()
	g_menu.state = MENU_STATE_STARTUP
end

