Console = nil;
--------------------------------------------------------------------------------
-- Add function for console
function StartById(params)
    OnCompletedGame()
    GameStateClear()
    if params:size() <= 1 then
        Console:Log('No input number level..');
        return 
    end
    StartLevelById(params:get(1))
end

function DebugLocalization(params)
    debug_localization = toboolean(params:get(1))
    local l = 'off'
    if debug_localization then
        l = 'on'
    end
    Console:Log('Localization debugging is '..l)
end

function GetLevelId()
	if play_field == nil then
		Console:Log("No level loaded")
	else
		local path = play_field:GetName()
	    local i, r = GetCurLevelId(path)
		Console:Log('Level id is '..r.." ("..path..")")
	end
end

function GetLevelPathByIDConsole()
    if play_field == nil then
		Console:Log("No level loaded")
	else
	    local path = play_field:GetName();
		Console:Log('Level id is '..path)
	end
end

--------------------------------------------------------------------------------
-- Register command
local ConsoleCommands = {};
ConsoleCommands['start'] = StartById;
ConsoleCommands['debuglocalization'] = DebugLocalization;
ConsoleCommands['levelid'] = GetLevelId;
ConsoleCommands['levelpath'] = GetLevelPathByIDConsole;
ConsoleCommands['restart'] = Restart;

function RegisterConsoleCommands()
    Console:RegisterCommand('start');
    Console:RegisterCommand('levelid');
    Console:RegisterCommand('levelpath');
    Console:RegisterCommand('debuglocalization');
    Console:RegisterCommand('restart');
    Console:RegisterCommand('loadlevel');
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

--------------------------------------------------------------------------------