diff --git a/cocos/editor-support/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp index 8f4a642f3d..35bede0e21 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp @@ -24,6 +24,8 @@ #include "GameMapReader.h" +#include "2d/CCTMXXMLParser.h" + #include "cocostudio/CSParseBinary_generated.h" #include "cocostudio/WidgetReader/NodeReader/NodeReader.h" @@ -159,6 +161,77 @@ namespace cocostudio } if (fileExist) { + /* Whether tileset is valid. */ + auto mapInfo = TMXMapInfo::create(path); + auto& layers = mapInfo->getLayers(); + bool valid = false; + std::string layerName = ""; + for (const auto &layerInfo : layers) + { + valid = false; + + if (layerInfo->_visible) + { + Size size = layerInfo->_layerSize; + auto& tilesets = mapInfo->getTilesets(); + if (tilesets.size()>0) + { + TMXTilesetInfo* tileset = nullptr; + for (auto iter = tilesets.crbegin(); iter != tilesets.crend(); ++iter) + { + tileset = *iter; + if (tileset) + { + for( int y=0; y < size.height; y++ ) + { + for( int x=0; x < size.width; x++ ) + { + int pos = static_cast(x + size.width * y); + int gid = layerInfo->_tiles[ pos ]; + + if( gid != 0 ) + { + if( (gid & kTMXFlippedMask) >= tileset->_firstGid ) + { + valid = true; + break; + } + } + } + + if (valid) + { + break; + } + } + } + } + } + + if (!valid) + { + layerName = layerInfo->_name; + break; + } + } + else + { + valid = true; + } + } + + if (!valid) + { + Node* node = Node::create(); + setPropsWithFlatBuffers(node, (Table*)gameMapOptions); + auto label = Label::create(); + label->setString(__String::createWithFormat("Some error of gid are in TMX Layer '%s'", layerName.c_str())->getCString()); + node->setScale(1.0f); + node->addChild(label); + return node; + } + /**/ + tmx = TMXTiledMap::create(path); if (tmx) {