zoukankan      html  css  js  c++  java
  • quick如何打开工程或者示例

    quick如何打开工程或者示例

    1. 那里打开工程

     cc.ui.UIPushButton.new(images, {scale9 = true})
        :setButtonSize(buttonWidth, buttonHeight)
        :setButtonLabel("normal", cc.ui.UILabel.new({
    		    UILabelType = 2,
                text = "打开",
                size = 18,
            }))
        :pos(display.width-padding, top)
        :addTo(node)
        :onButtonClicked(function()
       		//新打开工程的配置
            local projectConfig = ProjectConfig:new()
            local argumentVector = vector_string_:new_local()
            local index = self.localProjectListView_:getCurrentIndex()
            if index > 0 then
                local arguments = cc.player.settings.PLAYER_OPEN_RECENTS[index].args
                for _,v in ipairs(arguments) do
                    argumentVector:push_back(v)
                end
                projectConfig:parseCommandLine(argumentVector)
      //根据工程配置打开工程,下面分析:         
     PlayerProtocol:getInstance():openNewPlayerWithProjectConfig(projectConfig)
            end
        end)
    
    

    2.打开新工程

    void PlayerMac::openNewPlayerWithProjectConfig(const ProjectConfig& config)
    {
        if (_appController && [_appController respondsToSelector:NSSelectorFromString(@"launch:")])
        {
            NSString *commandLine = [NSString stringWithCString:config.makeCommandLine().c_str()
                                                       encoding:NSUTF8StringEncoding];
            NSArray *arguments = [NSMutableArray arrayWithArray:[commandLine componentsSeparatedByString:@" "]];
            
            //对工程配置进行处理转换,然后调用AppController中的launch方法, 并把工程配置参数传递过去
            [_appController performSelector:NSSelectorFromString(@"launch:") withObject:arguments];
        }
    }
    
    - (void) launch:(NSArray*)args
    {
    	//重新打开模拟器,也就是这个app,然后把新的工程配置信息传递过去, 这样重新打开的模拟器
    	//就是新的工程了
        NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
        NSMutableDictionary *configuration = [NSMutableDictionary dictionaryWithObject:args forKey:NSWorkspaceLaunchConfigurationArguments];
        NSError *error = nil;
        [[NSWorkspace sharedWorkspace] launchApplicationAtURL:url
                                                      options:NSWorkspaceLaunchNewInstance
                                                configuration:configuration error:&error];
    }
    
    

    3.重新进入工程

    //相当于重新打开模拟器,只不过传递了新的工程配置信息,那这样就打开新的工程了
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        [self installUncaughtExceptionHandler];
        
        auto player = player::PlayerMac::create();
        player->setController(self);
      	 ...
      	 ...
      	 //updateProjectFromCommandLineArgs分析传递过来的新的工程信息,并转化为
      	 //ProjectConfig工程配置,然后打开新的工程
        [self updateProjectFromCommandLineArgs:&_project];
        
        //下面这些就跟第一次打开模拟器的时候一样了,只不过ProjectConfig使用的是新的
        [self createWindowAndGLView];
        [self registerEventsHandler];
        [self startup];
    }
    
    
    

    4. .quick_player.lua文件内容,其实我们可以直接修改这个文件,加入我们自己的工程,

    下面那个test就是我直接添加的,这些配置项的具体含义可以参看最下面的部分:

    PLAYER_WINDOW_WIDTH = 960,
    PLAYER_WINDOW_HEIGHT = 640,
    PLAYER_COCOACHINA_USER = "USER_NAME",
    PLAYER_WINDOW_X = 0,
    PLAYER_OPEN_LAST_PROJECT = true,
    PLAYER_WINDOW_Y = 0,
    PLAYER_COCOACHINA_KEY = "USER_KEY",
    PLAYER_OPEN_RECENTS ={
      {
        title = "/Users/staff/Documents/cocos-quick/cocos-quick-lua/quick/samples/drag/",
        args ={
          "-quick",
          "/Users/staff/Documents/cocos-quick/cocos-quick-lua/",
          "-workdir",
          "/Users/staff/Documents/cocos-quick/cocos-quick-lua/quick/samples/drag/",
          "-file",
          "/Users/staff/Documents/cocos-quick/cocos-quick-lua/quick/samples/drag/src/main.lua",
          "-writable",
          "/Users/staff/Documents/cocos-quick/cocos-quick-lua/quick/samples/drag/",
          "-size",
          "960x640",
          "-write-debug-log",
          "-console",
          "-disable-load-framework",
          "-disable-debugger",
        },
      },
      {
        title = "/Users/staff/Documents/cocos-quick/sampletest/test/",
        args ={
          "-quick",
          "/Users/staff/Documents/cocos-quick/cocos-quick-lua/",
          "-workdir",
          "/Users/staff/Documents/cocos-quick/sampletest/test/",
          "-file",
          "/Users/staff/Documents/cocos-quick/sampletest/test/src/main.lua",
          "-writable",
          "/Users/staff/Documents/cocos-quick/sampletest/test/",
          "-size",
          "960x640",
          "-disable-write-debug-log",
          "-console",
          "-disable-load-framework",
          "-offset",
          "{790,207}",
          "-disable-debugger",
        },
      },
    
    void ProjectConfig::parseCommandLine(const vector<string> &args)
    {
        auto it = args.begin();
        while (it != args.end())
        {
            string arg = *it;
    
            if (arg.compare("-quick") == 0)
            {
                ++it;
                if (it == args.end()) break;
                setQuickCocos2dxRootPath((*it).c_str());
            }
            else if (arg.compare("-workdir") == 0)
            {
                ++it;
                if (it == args.end()) break;
                setProjectDir(*it);
                if (_writablePath.length() == 0) setWritablePath(*it);
            }
            else if (arg.compare("-writable") == 0)
            {
                ++it;
                if (it == args.end()) break;
                setWritablePath(*it);
            }
            else if (arg.compare("-file") == 0)
            {
                ++it;
                if (it == args.end()) break;
                setScriptFile(*it);
            }
            else if (arg.compare("-package.path") == 0)
            {
                ++it;
                if (it == args.end()) break;
                setPackagePath(*it);
            }
            else if (arg.compare("-landscape") == 0)
            {
                setFrameSize(cocos2d::Size(DEFAULT_HEIGHT, DEFAULT_WIDTH));
            }
            else if (arg.compare("-portrait") == 0)
            {
                setFrameSize(cocos2d::Size(DEFAULT_WIDTH, DEFAULT_HEIGHT));
            }
            else if (arg.compare("-size") == 0)
            {
                ++it;
                if (it == args.end()) break;
                const string& sizeStr(*it);
                size_t pos = sizeStr.find('x');
                int width = 0;
                int height = 0;
                if (pos != sizeStr.npos && pos > 0)
                {
                    string widthStr, heightStr;
                    widthStr.assign(sizeStr, 0, pos);
                    heightStr.assign(sizeStr, pos + 1, sizeStr.length() - pos);
                    width = atoi(widthStr.c_str());
                    height = atoi(heightStr.c_str());
                    setFrameSize(cocos2d::Size(width, height));
                }
            }
            else if (arg.compare("-scale") == 0)
            {
                ++it;
                if (it == args.end()) break;
                float scale = atof((*it).c_str());
                setFrameScale(scale);
            }
            else if (arg.compare("-write-debug-log") == 0)
            {
                setWriteDebugLogToFile(true);
            }
            else if (arg.compare("-disable-write-debug-log") == 0)
            {
                setWriteDebugLogToFile(false);
            }
            else if (arg.compare("-console") == 0)
            {
                setShowConsole(true);
            }
            else if (arg.compare("-disable-console") == 0)
            {
                setShowConsole(false);
            }
            else if (arg.compare("-load-framework") == 0)
            {
                setLoadPrecompiledFramework(true);
            }
            else if (arg.compare("-disable-load-framework") == 0)
            {
                setLoadPrecompiledFramework(false);
            }
            else if (arg.compare("-offset") == 0)
            {
                ++it;
                if (it == args.end()) break;
                setWindowOffset(cocos2d::PointFromString((*it).c_str()));
            }
            else if (arg.compare("-app-menu") == 0)
            {
                _isAppMenu = true;
            }
            else if (arg.compare("-resize-window") == 0)
            {
                _isResizeWindow = true;
            }
            else if (arg.compare("-retina-display") == 0)
            {
                _isRetinaDisplay = true;
            }
    
            ++it;
        }
        
        setDebuggerType(kCCLuaDebuggerNone);
    }
    
    
  • 相关阅读:
    规则引擎.Net Core
    GDPR(Cookie处理)
    NSSM把.Net Core部署至 Windows 服务
    Consul实现服务治理1
    微服务
    Consul实现服务治理
    NET Core Web发布包
    NET API 分析器
    NET Core 2.1 Global Tools
    css3中-moz、-ms、-webkit,-o分别代表的意思,以及微信浏览器内核分析
  • 原文地址:https://www.cnblogs.com/ZhYQ-Note/p/6187192.html
Copyright © 2011-2022 走看看