SimulatorConfig::SimulatorConfig(void) { m_screenSizeArray.push_back(SimulatorScreenSize("iPhone 3Gs (320x480)", 320, 480)); m_screenSizeArray.push_back(SimulatorScreenSize("iPhone 4 (640x960)", 640, 960)); m_screenSizeArray.push_back(SimulatorScreenSize("iPhone 5 (640x1136)", 640, 1136)); m_screenSizeArray.push_back(SimulatorScreenSize("iPhone 6 (750x1334)", 750, 1334 )); m_screenSizeArray.push_back(SimulatorScreenSize("iPhone 6 plus (640x1136)", 1242, 2208)); m_screenSizeArray.push_back(SimulatorScreenSize("iPad (768x1024)", 768, 1024)); m_screenSizeArray.push_back(SimulatorScreenSize("iPad Retina (1536x2048)", 1536, 2048)); m_screenSizeArray.push_back(SimulatorScreenSize("Android (480x800)", 480, 800)); m_screenSizeArray.push_back(SimulatorScreenSize("Android (480x854)", 480, 854)); m_screenSizeArray.push_back(SimulatorScreenSize("Android (540x960)", 540, 960)); m_screenSizeArray.push_back(SimulatorScreenSize("Android (600x1024)", 600, 1024)); m_screenSizeArray.push_back(SimulatorScreenSize("Android (720x1280)", 720, 1280)); m_screenSizeArray.push_back(SimulatorScreenSize("Android (800x1280)", 800, 1280)); m_screenSizeArray.push_back(SimulatorScreenSize("Android (1080x1920)", 1080, 1920)); }
void ConfigParser::readConfig() { _isInit = true; string filecfg = "config.json"; string fileContent; #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID && !defined(NDEBUG)) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS && defined(COCOS2D_DEBUG)) string fullPathFile = FileUtils::getInstance()->getWritablePath(); fullPathFile.append("debugruntime/"); fullPathFile.append(filecfg.c_str()); fileContent=FileUtils::getInstance()->getStringFromFile(fullPathFile.c_str()); #endif if (fileContent.empty()) { filecfg=FileUtils::getInstance()->fullPathForFilename(filecfg.c_str()); fileContent=FileUtils::getInstance()->getStringFromFile(filecfg.c_str()); } if(!fileContent.empty()) { _docRootjson.Parse<0>(fileContent.c_str()); if (_docRootjson.HasMember("init_cfg")) { if(_docRootjson["init_cfg"].IsObject()) { const rapidjson::Value& objectInitView = _docRootjson["init_cfg"]; if (objectInitView.HasMember("width") && objectInitView.HasMember("height")) { _initViewSize.width = objectInitView["width"].GetUint(); _initViewSize.height = objectInitView["height"].GetUint(); if (_initViewSize.height>_initViewSize.width) { float tmpvalue =_initViewSize.height; _initViewSize.height = _initViewSize.width; _initViewSize.width = tmpvalue; } } if (objectInitView.HasMember("name") && objectInitView["name"].IsString()) { _viewName = objectInitView["name"].GetString(); } if (objectInitView.HasMember("isLandscape") && objectInitView["isLandscape"].IsBool()) { _isLandscape = objectInitView["isLandscape"].GetBool(); } if (objectInitView.HasMember("entry") && objectInitView["entry"].IsString()) { _entryfile = objectInitView["entry"].GetString(); } } } if (_docRootjson.HasMember("simulator_screen_size")) { const rapidjson::Value& ArrayScreenSize = _docRootjson["simulator_screen_size"]; if (ArrayScreenSize.IsArray()) { for (int i=0; i<ArrayScreenSize.Size(); i++) { const rapidjson::Value& objectScreenSize = ArrayScreenSize[i]; if (objectScreenSize.HasMember("title") && objectScreenSize.HasMember("width") && objectScreenSize.HasMember("height")) { _screenSizeArray.push_back(SimulatorScreenSize(objectScreenSize["title"].GetString(), objectScreenSize["width"].GetUint(), objectScreenSize["height"].GetUint())); } } } } } }
void ConfigParser::readConfig() { #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) // add writable path to search path temporarily for reading config file vector<std::string> searchPathArray = FileUtils::getInstance()->getSearchPaths(); #if COCOS2D_DEBUG > 0 std::string writePath = FileServer::getShareInstance()->getWritePath(); #else std::string writePath = FileUtils::getInstance()->getWritablePath(); #endif searchPathArray.insert(searchPathArray.begin(), writePath); FileUtils::getInstance()->setSearchPaths(searchPathArray); #endif // read config file string fullPathFile = FileUtils::getInstance()->fullPathForFilename(CONFIG_FILE); string fileContent = FileUtils::getInstance()->getStringFromFile(fullPathFile); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) // revert search path searchPathArray.erase(searchPathArray.end() - 1); FileUtils::getInstance()->setSearchPaths(searchPathArray); #endif if(fileContent.empty()) return; if (_docRootjson.Parse<0>(fileContent.c_str()).HasParseError()) { cocos2d::log("read json file %s failed because of %s", fullPathFile.c_str(), _docRootjson.GetParseError()); return; } if (_docRootjson.HasMember("init_cfg")) { if(_docRootjson["init_cfg"].IsObject()) { const rapidjson::Value& objectInitView = _docRootjson["init_cfg"]; if (objectInitView.HasMember("width") && objectInitView.HasMember("height")) { _initViewSize.width = objectInitView["width"].GetUint(); _initViewSize.height = objectInitView["height"].GetUint(); if (_initViewSize.height>_initViewSize.width) { float tmpvalue = _initViewSize.height; _initViewSize.height = _initViewSize.width; _initViewSize.width = tmpvalue; } } if (objectInitView.HasMember("name") && objectInitView["name"].IsString()) { _viewName = objectInitView["name"].GetString(); } if (objectInitView.HasMember("isLandscape") && objectInitView["isLandscape"].IsBool()) { _isLandscape = objectInitView["isLandscape"].GetBool(); } if (objectInitView.HasMember("entry") && objectInitView["entry"].IsString()) { _entryfile = objectInitView["entry"].GetString(); } if (objectInitView.HasMember("consolePort")) { _consolePort = objectInitView["consolePort"].GetUint(); if(_consolePort <= 0) _consolePort = CONSOLE_PORT; } if (objectInitView.HasMember("uploadPort")) { _uploadPort = objectInitView["uploadPort"].GetUint(); if(_uploadPort <= 0) _uploadPort = UPLOAD_PORT; } if (objectInitView.HasMember("isWindowTop") && objectInitView["isWindowTop"].IsBool()) { _isWindowTop= objectInitView["isWindowTop"].GetBool(); } } } if (_docRootjson.HasMember("simulator_screen_size")) { const rapidjson::Value& ArrayScreenSize = _docRootjson["simulator_screen_size"]; if (ArrayScreenSize.IsArray()) { for (int i = 0; i < ArrayScreenSize.Size(); i++) { const rapidjson::Value& objectScreenSize = ArrayScreenSize[i]; if (objectScreenSize.HasMember("title") && objectScreenSize.HasMember("width") && objectScreenSize.HasMember("height")) { _screenSizeArray.push_back(SimulatorScreenSize(objectScreenSize["title"].GetString(), objectScreenSize["width"].GetUint(), objectScreenSize["height"].GetUint())); } } } } }
void ConfigParser::readConfig() { string fullPathFile = FileUtils::getInstance()->fullPathForFilename(CONFIG_FILE); string fileContent = FileUtils::getInstance()->getStringFromFile(fullPathFile); if(fileContent.empty()) return; if (_docRootjson.Parse<0>(fileContent.c_str()).HasParseError()) { cocos2d::log("read json file %s failed because of %s", fullPathFile.c_str(), _docRootjson.GetParseError()); return; } if (_docRootjson.HasMember("init_cfg")) { if(_docRootjson["init_cfg"].IsObject()) { const rapidjson::Value& objectInitView = _docRootjson["init_cfg"]; if (objectInitView.HasMember("width") && objectInitView.HasMember("height")) { _initViewSize.width = objectInitView["width"].GetUint(); _initViewSize.height = objectInitView["height"].GetUint(); if (_initViewSize.height>_initViewSize.width) { float tmpvalue = _initViewSize.height; _initViewSize.height = _initViewSize.width; _initViewSize.width = tmpvalue; } } if (objectInitView.HasMember("name") && objectInitView["name"].IsString()) { _viewName = objectInitView["name"].GetString(); } if (objectInitView.HasMember("isLandscape") && objectInitView["isLandscape"].IsBool()) { _isLandscape = objectInitView["isLandscape"].GetBool(); } if (objectInitView.HasMember("entry") && objectInitView["entry"].IsString()) { _entryfile = objectInitView["entry"].GetString(); } if (objectInitView.HasMember("consolePort")) { _consolePort = objectInitView["consolePort"].GetUint(); if(_consolePort <= 0) _consolePort = CONSOLE_PORT; } if (objectInitView.HasMember("uploadPort")) { _uploadPort = objectInitView["uploadPort"].GetUint(); if(_uploadPort <= 0) _uploadPort = UPLOAD_PORT; } if (objectInitView.HasMember("isWindowTop") && objectInitView["isWindowTop"].IsBool()) { _isWindowTop= objectInitView["isWindowTop"].GetBool(); } } } if (_docRootjson.HasMember("simulator_screen_size")) { const rapidjson::Value& ArrayScreenSize = _docRootjson["simulator_screen_size"]; if (ArrayScreenSize.IsArray()) { for (int i = 0; i<ArrayScreenSize.Size(); i++) { const rapidjson::Value& objectScreenSize = ArrayScreenSize[i]; if (objectScreenSize.HasMember("title") && objectScreenSize.HasMember("width") && objectScreenSize.HasMember("height")) { _screenSizeArray.push_back(SimulatorScreenSize(objectScreenSize["title"].GetString(), objectScreenSize["width"].GetUint(), objectScreenSize["height"].GetUint())); } } } } }
void ConfigParser::readConfig() { _isInit = true; _consolePort = 6010; #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) string filecfg = "gamecore/config/config.json"; #else string filecfg = "src/gamecore/config/config.json"; #endif string fileContent; //#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID && !defined(NDEBUG)) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS && defined(COCOS2D_DEBUG)) // string fullPathFile = FileUtils::getInstance()->getWritablePath(); // fullPathFile.append("debugruntime/"); // fullPathFile.append(filecfg.c_str()); // fileContent=FileUtils::getInstance()->getStringFromFile(fullPathFile.c_str()); //#endif if (fileContent.empty()) { filecfg=FileUtils::getInstance()->fullPathForFilename(filecfg.c_str()); fileContent=FileUtils::getInstance()->getStringFromFile(filecfg.c_str()); } if(!fileContent.empty()) { _docRootjson.Parse<0>(fileContent.c_str()); if (_docRootjson.HasMember("init_cfg")) { if(_docRootjson["init_cfg"].IsObject()) { const rapidjson::Value& objectInitView = _docRootjson["init_cfg"]; if (objectInitView.HasMember("width") && objectInitView.HasMember("height")) { _initViewSize.width = objectInitView["width"].GetUint(); _initViewSize.height = objectInitView["height"].GetUint(); if (_initViewSize.height>_initViewSize.width) { float tmpvalue =_initViewSize.height; _initViewSize.height = _initViewSize.width; _initViewSize.width = tmpvalue; } } if (objectInitView.HasMember("name") && objectInitView["name"].IsString()) { _viewName = objectInitView["name"].GetString(); } if (objectInitView.HasMember("terminalIp") && objectInitView["terminalIp"].IsString()) { _terminalIp = objectInitView["terminalIp"].GetString(); } if (objectInitView.HasMember("updateURL") && objectInitView["updateURL"].IsString()) { _updateURL = objectInitView["updateURL"].GetString(); } if (objectInitView.HasMember("gameplatform") && objectInitView["gameplatform"].IsString()) { _gameplatform = objectInitView["gameplatform"].GetString(); } if (objectInitView.HasMember("libver") && objectInitView["libver"].IsString()) { _libver = objectInitView["libver"].GetString(); } if (objectInitView.HasMember("isLandscape") && objectInitView["isLandscape"].IsBool()) { _isLandscape = objectInitView["isLandscape"].GetBool(); } if (objectInitView.HasMember("useCocosIde") && objectInitView["useCocosIde"].IsBool()) { _useCocosIde = objectInitView["useCocosIde"].GetBool(); } if (objectInitView.HasMember("cpplog") && objectInitView["cpplog"].IsBool()) { _cpplog = objectInitView["cpplog"].GetBool(); } if (objectInitView.HasMember("entry") && objectInitView["entry"].IsString()) { _entryfile = objectInitView["entry"].GetString(); } if (objectInitView.HasMember("consolePort")){ _consolePort = objectInitView["consolePort"].GetUint(); } } } if (_docRootjson.HasMember("simulator_screen_size")) { const rapidjson::Value& ArrayScreenSize = _docRootjson["simulator_screen_size"]; if (ArrayScreenSize.IsArray()) { for (int i=0; i<ArrayScreenSize.Size(); i++) { const rapidjson::Value& objectScreenSize = ArrayScreenSize[i]; if (objectScreenSize.HasMember("title") && objectScreenSize.HasMember("width") && objectScreenSize.HasMember("height")) { _screenSizeArray.push_back(SimulatorScreenSize(objectScreenSize["title"].GetString(), objectScreenSize["width"].GetUint(), objectScreenSize["height"].GetUint())); } } } } } }