From 505a4e8ab0807fd88a6943945d6e53b79e33e551 Mon Sep 17 00:00:00 2001 From: "yusheng.lu" Date: Mon, 29 Dec 2014 19:37:53 +0800 Subject: [PATCH 1/3] Feature of version check. When reading a csb file, if the engine's reader version dismatch the version saved in the csb file, an assert will be triggered. User must go to a website to get a reader to match the csb file. Removed the version compatible control code before. --- .../cocostudio/ActionTimeline/CSLoader.cpp | 22 +++++++--- .../cocostudio/ActionTimeline/CSLoader.h | 4 +- .../WidgetReader/NodeReader/NodeReader.cpp | 1 - .../cocostudio/WidgetReader/WidgetReader.cpp | 41 +++---------------- 4 files changed, 22 insertions(+), 46 deletions(-) diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index 04164ab28b..3eff6259f9 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -181,6 +181,7 @@ CSLoader::CSLoader() , _jsonPath("") , _monoCocos2dxVersion("") , _rootNode(nullptr) +, _csBuildID("2.0.8.0") { CREATE_CLASS_NODE_READER_INFO(NodeReader); CREATE_CLASS_NODE_READER_INFO(SingleNodeReader); @@ -782,6 +783,21 @@ Node* CSLoader::nodeWithFlatBuffersFile(const std::string &fileName) Data buf = FileUtils::getInstance()->getDataFromFile(fullPath); auto csparsebinary = GetCSParseBinary(buf.getBytes()); + + auto csBuildId = csparsebinary->version(); + if (csBuildId) + { + CCASSERT(strcmp(_csBuildID.c_str(), csBuildId->c_str()) == 0, + String::createWithFormat("%s%s%s%s%s%s%s%s", + "The build id of your CocosStudio exported file(", + csBuildId->c_str(), + ") and the build id of your cocos reader(", + _csBuildID.c_str(), + ") are not match.\n", + "Please get the correct cocos reader from ", + "https://github.com/chukong/cocos-reader", + " and replace the reader in your Cocos2d-x")->getCString()); + } // decode plist auto textures = csparsebinary->textures(); @@ -791,9 +807,6 @@ Node* CSLoader::nodeWithFlatBuffersFile(const std::string &fileName) { SpriteFrameCache::getInstance()->addSpriteFramesWithFile(textures->Get(i)->c_str()); } - - auto v = csparsebinary->version(); - if (v) _csdVersion = v->c_str(); Node* node = nodeWithFlatBuffers(csparsebinary->nodeTree()); @@ -1137,9 +1150,6 @@ Node* CSLoader::createNodeWithFlatBuffersForSimulator(const std::string& filenam auto nodeTree = csparsebinary->nodeTree(); - auto v = csparsebinary->version(); - if (v) _csdVersion = v->c_str(); - Node* node = nodeWithFlatBuffersForSimulator(nodeTree); _rootNode = nullptr; diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h index 93b2e16d7a..505645e5fc 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h @@ -104,7 +104,6 @@ public: cocos2d::Node* createNodeWithFlatBuffersForSimulator(const std::string& filename); cocos2d::Node* nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree* nodetree); - std::string getCsdVersion() { return _csdVersion; } protected: @@ -151,8 +150,7 @@ protected: std::string _monoCocos2dxVersion; Node* _rootNode; -// std::vector _loadingNodeParentHierarchy; - std::string _csdVersion; + std::string _csBuildID; }; NS_CC_END diff --git a/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp index 1ec46e2fc6..131b28921c 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp @@ -517,7 +517,6 @@ namespace cocostudio void NodeReader::setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions) { auto layoutComponentTable = ((WidgetOptions*)nodeOptions)->layoutComponent(); - if (!layoutComponentTable) return; auto layoutComponent = ui::LayoutComponent::bindLayoutComponent(node); diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index 7e462d7033..ab8536c381 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -771,41 +771,11 @@ namespace cocostudio widget->setCascadeOpacityEnabled(true); widget->setAnchorPoint(Vec2::ZERO); - widget->setUnifySizeEnabled(true); - bool ignoreSize = options->ignoreSize(); - widget->ignoreContentAdaptWithSize(ignoreSize); - - std::string versionString = CSLoader::getInstance()->getCsdVersion(); - //assume versionString is like "2.0.6.0" - if (versionString.length() > 0) - { - int p1, p2, p3, v1, v2, v3; - p1 = p2 = p3 = v1 = v2 = v3 = 0; - p1 = versionString.find('.'); - if (p1 > 0) - { - p2 = versionString.find('.', p1 + 1); - v1 = atoi(versionString.substr(0, p1).c_str()); - } - if (p2 > p1) - { - p3 = versionString.find('.', p2 + 1); - v2 = atoi(versionString.substr(p1 + 1, p2 - p1 - 1).c_str()); - } - if (p3 > p2) - { - v3 = atoi(versionString.substr(p2 + 1, p3 - p2 - 1).c_str()); - } - - if (!(v1 <= 2 && v2 == 0 && v3 <= 6)) - { - widget->setUnifySizeEnabled(false); - widget->setLayoutComponentEnabled(true); - widget->ignoreContentAdaptWithSize(false); - Size contentSize(options->size()->width(), options->size()->height()); - widget->setContentSize(contentSize); - } - } + widget->setUnifySizeEnabled(false); + widget->setLayoutComponentEnabled(true); + widget->ignoreContentAdaptWithSize(false); + Size contentSize(options->size()->width(), options->size()->height()); + widget->setContentSize(contentSize); int tag = options->tag(); widget->setTag(tag); @@ -866,7 +836,6 @@ namespace cocostudio void WidgetReader::setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions) { auto layoutComponentTable = ((WidgetOptions*)nodeOptions)->layoutComponent(); - if (!layoutComponentTable) return; auto layoutComponent = ui::LayoutComponent::bindLayoutComponent(node); From 88f0a1e6425b3fe970beecdad1ae693ecabec65a Mon Sep 17 00:00:00 2001 From: "yusheng.lu" Date: Tue, 30 Dec 2014 10:33:07 +0800 Subject: [PATCH 2/3] prevent the crush of the cocosstudio demos --- .../cocostudio/WidgetReader/NodeReader/NodeReader.cpp | 1 + cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp index 131b28921c..1ec46e2fc6 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp @@ -517,6 +517,7 @@ namespace cocostudio void NodeReader::setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions) { auto layoutComponentTable = ((WidgetOptions*)nodeOptions)->layoutComponent(); + if (!layoutComponentTable) return; auto layoutComponent = ui::LayoutComponent::bindLayoutComponent(node); diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index ab8536c381..9169faf960 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -838,6 +838,7 @@ namespace cocostudio auto layoutComponentTable = ((WidgetOptions*)nodeOptions)->layoutComponent(); auto layoutComponent = ui::LayoutComponent::bindLayoutComponent(node); + if (!layoutComponentTable) return; bool positionXPercentEnabled = layoutComponentTable->positionXPercentEnabled(); bool positionYPercentEnabled = layoutComponentTable->positionYPercentEnabled(); From 9a0f302370ba3d11c349047184d469fa08eb3e53 Mon Sep 17 00:00:00 2001 From: "yusheng.lu" Date: Tue, 30 Dec 2014 10:47:00 +0800 Subject: [PATCH 3/3] revert the layoutComponent codes to prevent the demos crush. --- cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index 9169faf960..c67b8c0ac0 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -836,9 +836,9 @@ namespace cocostudio void WidgetReader::setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions) { auto layoutComponentTable = ((WidgetOptions*)nodeOptions)->layoutComponent(); + if (!layoutComponentTable) return; auto layoutComponent = ui::LayoutComponent::bindLayoutComponent(node); - if (!layoutComponentTable) return; bool positionXPercentEnabled = layoutComponentTable->positionXPercentEnabled(); bool positionYPercentEnabled = layoutComponentTable->positionYPercentEnabled();