diff --git a/templates/lua-template-runtime/res/config.json b/templates/lua-template-runtime/config.json similarity index 100% rename from templates/lua-template-runtime/res/config.json rename to templates/lua-template-runtime/config.json diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp b/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp index 6dc44b3f84..3cc5bb8618 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp @@ -24,43 +24,44 @@ bool ConfigParser::isInit() void ConfigParser::readConfig() { _isInit = true; - string filecfg = "res/config.json"; - FILE * pFile = nullptr; - + 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()); - pFile = fopen (fullPathFile.c_str() , "r"); + fileContent=FileUtils::getInstance()->getStringFromFile(fullPathFile.c_str()); #endif - if (!pFile) - { - string fullPathFile = FileUtils::getInstance()->fullPathForFilename(filecfg); - pFile = fopen (fullPathFile.c_str() , "r"); + if (fileContent.empty()) { + filecfg=FileUtils::getInstance()->fullPathForFilename(filecfg.c_str()); + fileContent=FileUtils::getInstance()->getStringFromFile(filecfg.c_str()); } - if(pFile) + if(!fileContent.empty()) { - rapidjson::FileStream inputStream(pFile); - _docRootjson.ParseStream<0>(inputStream); - fclose(pFile); - if (_docRootjson.HasMember("init_cfg") && _docRootjson["init_cfg"].IsObject()) + _docRootjson.Parse<0>(fileContent.c_str()); + if (_docRootjson.HasMember("init_cfg")) { - const rapidjson::Value& objectInitView = _docRootjson["init_cfg"]; - if (objectInitView.HasMember("width") && objectInitView.HasMember("height")) + if(_docRootjson["init_cfg"].IsObject()) { - _initViewSize.width = objectInitView["width"].GetUint(); - _initViewSize.height = objectInitView["height"].GetUint(); - } - 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(); + 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 (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")) diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.android/build-cfg.json b/templates/lua-template-runtime/frameworks/runtime-src/proj.android/build-cfg.json index 323583608f..ad111cc1f2 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.android/build-cfg.json +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.android/build-cfg.json @@ -27,11 +27,8 @@ "to": "" }, { - "from": "../../../res", - "to": "res", - "include": [ - "config.json" - ] + "from": "../../../config.json", + "to": "" }, { "from": "../../cocos2d-x/external/lua/luasocket", diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj index b377f1e767..97e6644ead 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj @@ -94,6 +94,8 @@ C03781F218BF656A00FE4F13 /* StudioConstants.lua in Resources */ = {isa = PBXBuildFile; fileRef = C03781CE18BF656A00FE4F13 /* StudioConstants.lua */; }; C03781F518BF65A900FE4F13 /* libluabindings Mac.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C03781B418BF654500FE4F13 /* libluabindings Mac.a */; }; C03781F618BF65B100FE4F13 /* libluabindings iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C03781B618BF654500FE4F13 /* libluabindings iOS.a */; }; + C05D1C121923449100B808A4 /* config.json in Resources */ = {isa = PBXBuildFile; fileRef = C05D1C111923449100B808A4 /* config.json */; }; + C05D1C131923449100B808A4 /* config.json in Resources */ = {isa = PBXBuildFile; fileRef = C05D1C111923449100B808A4 /* config.json */; }; C0619CD71896894800872C26 /* Runtime_ios-mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0619CD61896894800872C26 /* Runtime_ios-mac.mm */; }; C0619CD81896894800872C26 /* Runtime_ios-mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0619CD61896894800872C26 /* Runtime_ios-mac.mm */; }; C06C3796191A1D1E00617BED /* ConfigParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C06C3794191A1D1E00617BED /* ConfigParser.cpp */; }; @@ -367,6 +369,7 @@ C03781CC18BF656A00FE4F13 /* Opengl.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Opengl.lua; path = "../../cocos2d-x/cocos/scripting/lua-bindings/script/Opengl.lua"; sourceTree = ""; }; C03781CD18BF656A00FE4F13 /* OpenglConstants.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = OpenglConstants.lua; path = "../../cocos2d-x/cocos/scripting/lua-bindings/script/OpenglConstants.lua"; sourceTree = ""; }; C03781CE18BF656A00FE4F13 /* StudioConstants.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = StudioConstants.lua; path = "../../cocos2d-x/cocos/scripting/lua-bindings/script/StudioConstants.lua"; sourceTree = ""; }; + C05D1C111923449100B808A4 /* config.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = config.json; path = ../../../config.json; sourceTree = ""; }; C0619CD61896894800872C26 /* Runtime_ios-mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "Runtime_ios-mac.mm"; sourceTree = ""; }; C06C3794191A1D1E00617BED /* ConfigParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ConfigParser.cpp; path = ../Classes/ConfigParser.cpp; sourceTree = ""; }; C06C3795191A1D1E00617BED /* ConfigParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ConfigParser.h; path = ../Classes/ConfigParser.h; sourceTree = ""; }; @@ -639,6 +642,7 @@ F293BC4615EB859D00256477 /* Resources */ = { isa = PBXGroup; children = ( + C05D1C111923449100B808A4 /* config.json */, C03781B718BF655400FE4F13 /* res */, C03781B818BF655400FE4F13 /* src */, ); @@ -861,6 +865,7 @@ C03781DE18BF656A00FE4F13 /* DeprecatedEnum.lua in Resources */, C03781E818BF656A00FE4F13 /* json.lua in Resources */, C03781D618BF656A00FE4F13 /* Cocos2dConstants.lua in Resources */, + C05D1C131923449100B808A4 /* config.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -911,6 +916,7 @@ C08D5D6618E567C6009071A4 /* tp.lua in Resources */, 5023812117EBBCAC00990C9B /* Icon-72.png in Resources */, C08D5D6818E567C6009071A4 /* url.lua in Resources */, + C05D1C121923449100B808A4 /* config.json in Resources */, C03781DD18BF656A00FE4F13 /* DeprecatedEnum.lua in Resources */, C03781E318BF656A00FE4F13 /* extern.lua in Resources */, C03781D918BF656A00FE4F13 /* Deprecated.lua in Resources */, diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/build-cfg.json b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/build-cfg.json index e93fceb246..7a138cb477 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/build-cfg.json +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/build-cfg.json @@ -1,6 +1,7 @@ { "remove_res" : [ "src", - "res" + "res", + "config.json" ] } diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/HelloLua.vcxproj b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/HelloLua.vcxproj index 65439a4446..dc70165991 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/HelloLua.vcxproj +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/HelloLua.vcxproj @@ -112,6 +112,7 @@ mkdir "$(OutDir)\Resource\res" xcopy "$(ProjectDir)..\..\cocos2d-x\cocos\scripting\lua-bindings\script" "$(OutDir)\Resource" /e /Y xcopy "$(ProjectDir)..\..\..\src" "$(OutDir)\Resource\src" /e /Y xcopy "$(ProjectDir)..\..\..\res" "$(OutDir)\Resource\res" /e /Y +copy "$(ProjectDir)..\..\..\config.json" "$(OutDir)\Resource\config.json" /Y xcopy "$(ProjectDir)..\..\cocos2d-x\external\lua\luasocket\*.lua" "$(OutDir)\Resource" /e /Y copy files @@ -167,6 +168,7 @@ mkdir "$(OutDir)\Resource\res" xcopy "$(ProjectDir)..\..\cocos2d-x\cocos\scripting\lua-bindings\script" "$(OutDir)\Resource" /e /Y xcopy "$(ProjectDir)..\..\..\src" "$(OutDir)\Resource\src" /e /Y xcopy "$(ProjectDir)..\..\..\res" "$(OutDir)\Resource\res" /e /Y +copy "$(ProjectDir)..\..\..\config.json" "$(OutDir)\Resource\config.json" /Y xcopy "$(ProjectDir)..\..\cocos2d-x\external\lua\luasocket\*.lua" "$(OutDir)\Resource" /e /Y copy files diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/build-cfg.json b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/build-cfg.json index 8642706ca3..87c51f385f 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/build-cfg.json +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/build-cfg.json @@ -7,7 +7,11 @@ { "from": "../../../res", "to": "res" - } + }, + { + "from": "../../../config.json", + "to": "" + }, ], "must_copy_resources": [ {