This commit is contained in:
bofeng-song 2014-05-14 15:03:07 +08:00
commit 668ed34512
7 changed files with 45 additions and 34 deletions

View File

@ -24,43 +24,44 @@ bool ConfigParser::isInit()
void ConfigParser::readConfig() void ConfigParser::readConfig()
{ {
_isInit = true; _isInit = true;
string filecfg = "res/config.json"; string filecfg = "config.json";
FILE * pFile = nullptr;
string fileContent;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID && !defined(NDEBUG)) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS && defined(COCOS2D_DEBUG)) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID && !defined(NDEBUG)) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS && defined(COCOS2D_DEBUG))
string fullPathFile = FileUtils::getInstance()->getWritablePath(); string fullPathFile = FileUtils::getInstance()->getWritablePath();
fullPathFile.append("debugruntime/");
fullPathFile.append(filecfg.c_str()); fullPathFile.append(filecfg.c_str());
pFile = fopen (fullPathFile.c_str() , "r"); fileContent=FileUtils::getInstance()->getStringFromFile(fullPathFile.c_str());
#endif #endif
if (!pFile) if (fileContent.empty()) {
{ filecfg=FileUtils::getInstance()->fullPathForFilename(filecfg.c_str());
string fullPathFile = FileUtils::getInstance()->fullPathForFilename(filecfg); fileContent=FileUtils::getInstance()->getStringFromFile(filecfg.c_str());
pFile = fopen (fullPathFile.c_str() , "r");
} }
if(pFile) if(!fileContent.empty())
{ {
rapidjson::FileStream inputStream(pFile); _docRootjson.Parse<0>(fileContent.c_str());
_docRootjson.ParseStream<0>(inputStream); if (_docRootjson.HasMember("init_cfg"))
fclose(pFile);
if (_docRootjson.HasMember("init_cfg") && _docRootjson["init_cfg"].IsObject())
{ {
const rapidjson::Value& objectInitView = _docRootjson["init_cfg"]; if(_docRootjson["init_cfg"].IsObject())
if (objectInitView.HasMember("width") && objectInitView.HasMember("height"))
{ {
_initViewSize.width = objectInitView["width"].GetUint(); const rapidjson::Value& objectInitView = _docRootjson["init_cfg"];
_initViewSize.height = objectInitView["height"].GetUint(); if (objectInitView.HasMember("width") && objectInitView.HasMember("height"))
} {
if (objectInitView.HasMember("name") && objectInitView["name"].IsString()) _initViewSize.width = objectInitView["width"].GetUint();
{ _initViewSize.height = objectInitView["height"].GetUint();
_viewName = objectInitView["name"].GetString(); }
} if (objectInitView.HasMember("name") && objectInitView["name"].IsString())
if (objectInitView.HasMember("isLandscape") && objectInitView["isLandscape"].IsBool()) { {
_isLandscape = objectInitView["isLandscape"].GetBool(); _viewName = objectInitView["name"].GetString();
} }
if (objectInitView.HasMember("entry") && objectInitView["entry"].IsString()) { if (objectInitView.HasMember("isLandscape") && objectInitView["isLandscape"].IsBool()) {
_entryfile = objectInitView["entry"].GetString(); _isLandscape = objectInitView["isLandscape"].GetBool();
}
if (objectInitView.HasMember("entry") && objectInitView["entry"].IsString()) {
_entryfile = objectInitView["entry"].GetString();
}
} }
} }
if (_docRootjson.HasMember("simulator_screen_size")) if (_docRootjson.HasMember("simulator_screen_size"))

View File

@ -27,11 +27,8 @@
"to": "" "to": ""
}, },
{ {
"from": "../../../res", "from": "../../../config.json",
"to": "res", "to": ""
"include": [
"config.json"
]
}, },
{ {
"from": "../../cocos2d-x/external/lua/luasocket", "from": "../../cocos2d-x/external/lua/luasocket",

View File

@ -94,6 +94,8 @@
C03781F218BF656A00FE4F13 /* StudioConstants.lua in Resources */ = {isa = PBXBuildFile; fileRef = C03781CE18BF656A00FE4F13 /* StudioConstants.lua */; }; C03781F218BF656A00FE4F13 /* StudioConstants.lua in Resources */ = {isa = PBXBuildFile; fileRef = C03781CE18BF656A00FE4F13 /* StudioConstants.lua */; };
C03781F518BF65A900FE4F13 /* libluabindings Mac.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C03781B418BF654500FE4F13 /* libluabindings Mac.a */; }; 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 */; }; 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 */; }; 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 */; }; 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 */; }; 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 = "<group>"; }; C03781CC18BF656A00FE4F13 /* Opengl.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Opengl.lua; path = "../../cocos2d-x/cocos/scripting/lua-bindings/script/Opengl.lua"; sourceTree = "<group>"; };
C03781CD18BF656A00FE4F13 /* OpenglConstants.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = OpenglConstants.lua; path = "../../cocos2d-x/cocos/scripting/lua-bindings/script/OpenglConstants.lua"; sourceTree = "<group>"; }; C03781CD18BF656A00FE4F13 /* OpenglConstants.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = OpenglConstants.lua; path = "../../cocos2d-x/cocos/scripting/lua-bindings/script/OpenglConstants.lua"; sourceTree = "<group>"; };
C03781CE18BF656A00FE4F13 /* StudioConstants.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = StudioConstants.lua; path = "../../cocos2d-x/cocos/scripting/lua-bindings/script/StudioConstants.lua"; sourceTree = "<group>"; }; C03781CE18BF656A00FE4F13 /* StudioConstants.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = StudioConstants.lua; path = "../../cocos2d-x/cocos/scripting/lua-bindings/script/StudioConstants.lua"; sourceTree = "<group>"; };
C05D1C111923449100B808A4 /* config.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = config.json; path = ../../../config.json; sourceTree = "<group>"; };
C0619CD61896894800872C26 /* Runtime_ios-mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "Runtime_ios-mac.mm"; sourceTree = "<group>"; }; C0619CD61896894800872C26 /* Runtime_ios-mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "Runtime_ios-mac.mm"; sourceTree = "<group>"; };
C06C3794191A1D1E00617BED /* ConfigParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ConfigParser.cpp; path = ../Classes/ConfigParser.cpp; sourceTree = "<group>"; }; C06C3794191A1D1E00617BED /* ConfigParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ConfigParser.cpp; path = ../Classes/ConfigParser.cpp; sourceTree = "<group>"; };
C06C3795191A1D1E00617BED /* ConfigParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ConfigParser.h; path = ../Classes/ConfigParser.h; sourceTree = "<group>"; }; C06C3795191A1D1E00617BED /* ConfigParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ConfigParser.h; path = ../Classes/ConfigParser.h; sourceTree = "<group>"; };
@ -639,6 +642,7 @@
F293BC4615EB859D00256477 /* Resources */ = { F293BC4615EB859D00256477 /* Resources */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C05D1C111923449100B808A4 /* config.json */,
C03781B718BF655400FE4F13 /* res */, C03781B718BF655400FE4F13 /* res */,
C03781B818BF655400FE4F13 /* src */, C03781B818BF655400FE4F13 /* src */,
); );
@ -861,6 +865,7 @@
C03781DE18BF656A00FE4F13 /* DeprecatedEnum.lua in Resources */, C03781DE18BF656A00FE4F13 /* DeprecatedEnum.lua in Resources */,
C03781E818BF656A00FE4F13 /* json.lua in Resources */, C03781E818BF656A00FE4F13 /* json.lua in Resources */,
C03781D618BF656A00FE4F13 /* Cocos2dConstants.lua in Resources */, C03781D618BF656A00FE4F13 /* Cocos2dConstants.lua in Resources */,
C05D1C131923449100B808A4 /* config.json in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -911,6 +916,7 @@
C08D5D6618E567C6009071A4 /* tp.lua in Resources */, C08D5D6618E567C6009071A4 /* tp.lua in Resources */,
5023812117EBBCAC00990C9B /* Icon-72.png in Resources */, 5023812117EBBCAC00990C9B /* Icon-72.png in Resources */,
C08D5D6818E567C6009071A4 /* url.lua in Resources */, C08D5D6818E567C6009071A4 /* url.lua in Resources */,
C05D1C121923449100B808A4 /* config.json in Resources */,
C03781DD18BF656A00FE4F13 /* DeprecatedEnum.lua in Resources */, C03781DD18BF656A00FE4F13 /* DeprecatedEnum.lua in Resources */,
C03781E318BF656A00FE4F13 /* extern.lua in Resources */, C03781E318BF656A00FE4F13 /* extern.lua in Resources */,
C03781D918BF656A00FE4F13 /* Deprecated.lua in Resources */, C03781D918BF656A00FE4F13 /* Deprecated.lua in Resources */,

View File

@ -1,6 +1,7 @@
{ {
"remove_res" : [ "remove_res" : [
"src", "src",
"res" "res",
"config.json"
] ]
} }

View File

@ -112,6 +112,7 @@ mkdir "$(OutDir)\Resource\res"
xcopy "$(ProjectDir)..\..\cocos2d-x\cocos\scripting\lua-bindings\script" "$(OutDir)\Resource" /e /Y xcopy "$(ProjectDir)..\..\cocos2d-x\cocos\scripting\lua-bindings\script" "$(OutDir)\Resource" /e /Y
xcopy "$(ProjectDir)..\..\..\src" "$(OutDir)\Resource\src" /e /Y xcopy "$(ProjectDir)..\..\..\src" "$(OutDir)\Resource\src" /e /Y
xcopy "$(ProjectDir)..\..\..\res" "$(OutDir)\Resource\res" /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</Command> xcopy "$(ProjectDir)..\..\cocos2d-x\external\lua\luasocket\*.lua" "$(OutDir)\Resource" /e /Y</Command>
<Message>copy files</Message> <Message>copy files</Message>
</PreBuildEvent> </PreBuildEvent>
@ -167,6 +168,7 @@ mkdir "$(OutDir)\Resource\res"
xcopy "$(ProjectDir)..\..\cocos2d-x\cocos\scripting\lua-bindings\script" "$(OutDir)\Resource" /e /Y xcopy "$(ProjectDir)..\..\cocos2d-x\cocos\scripting\lua-bindings\script" "$(OutDir)\Resource" /e /Y
xcopy "$(ProjectDir)..\..\..\src" "$(OutDir)\Resource\src" /e /Y xcopy "$(ProjectDir)..\..\..\src" "$(OutDir)\Resource\src" /e /Y
xcopy "$(ProjectDir)..\..\..\res" "$(OutDir)\Resource\res" /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</Command> xcopy "$(ProjectDir)..\..\cocos2d-x\external\lua\luasocket\*.lua" "$(OutDir)\Resource" /e /Y</Command>
<Message>copy files</Message> <Message>copy files</Message>
</PreBuildEvent> </PreBuildEvent>

View File

@ -7,7 +7,11 @@
{ {
"from": "../../../res", "from": "../../../res",
"to": "res" "to": "res"
} },
{
"from": "../../../config.json",
"to": ""
},
], ],
"must_copy_resources": [ "must_copy_resources": [
{ {