mirror of https://github.com/axmolengine/axmol.git
Merge pull request #10208 from pipu/modify_parse_TMXTiledMap
Checking whether tileset is valid during parses TMXTiledMap.
This commit is contained in:
commit
5dc09d8489
|
@ -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<int>(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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue