
local ConsoleCommands = {};

ConsoleCommands['exit'] = 
	function (param)
		GetGameApp():Shutdown(true);
	end;

ConsoleCommands['level'] = 
    function (param)
    	local currentScreen = GetGameManager():GetCurrentScreen();
		if (currentScreen == nil or (currentScreen ~= nil and (IsLevelScreen(currentScreen) == true or IsMainMenuScreen(currentScreen) == true))) then
	       	if (currentScreen ~= nil) then
			    currentScreen:ScreenDestroy();
			end
	        StartLevel(GetLevelMap()[tonumber(param:get(1))], false);
		else
			return 'To execute this command either level screen or main menu screen must be active.';
		end
    end;

ConsoleCommands['minigame'] = 
    function (param)
    	local currentScreen = GetGameManager():GetCurrentScreen();
		if (currentScreen ~= nil and IsLevelScreen(currentScreen) == true) then
			local minigameFileName = GetMinigameFileNameByIndex(tonumber(param:get(1)));
	       	if (minigameFileName == '') then
				return 'There isn\'t registered mini-game on this level.';
			end
			if (gameState == nil) then
				return 'Current level game state not exists.';
			end
			playField:GetLevelScreen():RunMiniGame(minigameFileName);
		else
			return 'To execute this command level screen must be active.';
		end
    end;

ConsoleCommands['destroy_current_screen'] = 
    function (param)
    	local currentScreen = GetGameManager():GetCurrentScreen();
        if (currentScreen ~= nil) then
		    currentScreen:ScreenDestroy();
	    end
    end;

ConsoleCommands['proinfo'] = 
    function (param)
		local state = false;
        if (param:get(1) ~= '0') then
            state = true;
        end
		GetGameApp():EnableProfilingInfo(state);
    end;

--------------------------------------------------------------------------------
--
function RegisterConsoleCommands()
	assert(ConsoleCommands ~= nil);
	for commandName,commandFunction in pairs(ConsoleCommands) do
	    Console:RegisterCommand(commandName);
	end
end

--------------------------------------------------------------------------------
--
function ProcessConsoleCommand(console, command)
    local params = ExplodeString(' ', command);

    for name, command in pairs(ConsoleCommands) do
        if (params:get(0) == name) then
            return command(params) or '';
        end
    end

    return 'Command not found: ' .. command;
end
