main.lua 3.05 KB

cc.FileUtils:getInstance():setPopupNotify(false)
cc.FileUtils:getInstance():addSearchPath("src/")
cc.FileUtils:getInstance():addSearchPath("res/")

local engine_loaded = {};
for i,v in pairs(package.loaded) do
    engine_loaded[i] = v;
end

require "config";
require "cocos.init";
require "cocos.cocos2d.json";
require "core.utils.util";

__G__TRACKBACK__ = function(msg)
    local traceback = debug.traceback(msg, 3);
    print(traceback);
    logUI(traceback);
    return traceback;
end 

local function main()
    require "app.info.ConfigInfo";
    DEBUG = tonumber(ConfigInfo.getConfigInfo("debug"));
    CHANNEL = ConfigInfo.getConfigInfo("channel");
    PROXY_HTTP_ADDR = ConfigInfo.getConfigInfo("proxy_http_addr");
    PROXY_SOCK_ADDR = ConfigInfo.getConfigInfo("proxy_sock_addr");
    IS_TV = tonumber(ConfigInfo.getConfigInfo("is_tv"));
    ALONE_GAME_ID = tonumber(ConfigInfo.getConfigInfo("alone_game_id"));
    ALONE_GAME_ID = ALONE_GAME_ID or 0;

    require "core.log.init";
    require "core.net.socket_connection";

    if PROXY_HTTP_ADDR and PROXY_HTTP_ADDR ~= "" then
        setProxyAddress(PROXY_HTTP_ADDR);
    end

    CDN_CONFIG_URL = ConfigInfo.getConfigInfo("cdn_config_url") or "";
    if not CDN_CONFIG_URL or CDN_CONFIG_URL == "" then
        GAME_LOGIN_URL = ConfigInfo.getConfigInfo("game_login_url");
        print("本地配置 登录服务器地址:"..GAME_LOGIN_URL);
        PLATFORM = tonumber(ConfigInfo.getConfigInfo("platform"));
        print("本地配置 平台号PLATFORM:"..PLATFORM);
    end

    cc.Director:getInstance():setAnimationInterval(1/30);
    require("app.MyApp"):create():run("LoadingScene");
end

function reloadGame()
    for k,_ in pairs(package.loaded) do
        local has_k = false;
        for i,v in pairs(engine_loaded) do
            if k == i then
                has_k = true;
            end
        end
        if not has_k then
            print("remove:"..k);
            package.loaded[k] = nil;
        end
    end
    
    cc.Director:getInstance():purgeCachedData();
    cc.FileUtils:getInstance():purgeCachedEntries();
    
    require("main");
end

function loadGame(game_name)
    local searchPaths = cc.FileUtils:getInstance():getSearchPaths();
    local resPath = cc.FileUtils:getInstance():getWritablePath().."GameUpdate/"..game_name.."/";
    searchPaths = {};
    table.insert(searchPaths,1,resPath);
    table.insert(searchPaths,2,resPath .. 'res/');
    table.insert(searchPaths,3,resPath .. 'src/');
    cc.FileUtils:getInstance():setSearchPaths(searchPaths);

    for k,_ in pairs(package.loaded) do
        local has_k = false;
        for i,v in pairs(engine_loaded) do
            if k == i then
                has_k = true;
            end
        end
        if not has_k then
            print("remove:"..k);
            package.loaded[k] = nil;
        end
    end
    
    cc.FileUtils:getInstance():purgeCachedEntries();
    cc.Director:getInstance():purgeCachedData();

    app:enterScene("LoadingScene",{nextSceneName="main"});
end

local status, msg = xpcall(main, __G__TRACKBACK__)
if not status then
    print(msg)
end