Get TMXTilesetInfo by name (#1522)

This commit is contained in:
Lich 2023-12-16 08:13:34 +09:00 committed by GitHub
parent 993b7f54c2
commit c43dbfff95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 2 deletions

View File

@ -89,9 +89,12 @@ bool FastTMXTiledMap::initWithXML(std::string_view tmxString, std::string_view r
return true;
}
FastTMXTiledMap::FastTMXTiledMap() : _mapSize(Vec2::ZERO), _tileSize(Vec2::ZERO) {}
FastTMXTiledMap::FastTMXTiledMap() : _mapSize(Vec2::ZERO), _tileSize(Vec2::ZERO), _mapInfo(nullptr) {}
FastTMXTiledMap::~FastTMXTiledMap() {}
FastTMXTiledMap::~FastTMXTiledMap()
{
AX_SAFE_RELEASE(_mapInfo);
}
// private
FastTMXLayer* FastTMXTiledMap::parseLayer(TMXLayerInfo* layerInfo, TMXMapInfo* mapInfo)
@ -191,6 +194,9 @@ void FastTMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
}
_layerCount = idx;
_mapInfo = mapInfo;
AX_SAFE_RETAIN(_mapInfo);
}
// public
@ -274,4 +280,34 @@ void FastTMXTiledMap::setTileAnimEnabled(bool enabled)
}
}
TMXTilesetInfo* FastTMXTiledMap::getTilesetInfo(std::string_view tsxNameString)
{
if (_mapInfo == nullptr)
return nullptr;
auto tileSets = _mapInfo->getTilesets();
for (auto tileSet : tileSets)
{
if (tileSet->_name == tsxNameString)
{
return tileSet;
}
}
return nullptr;
}
Vector<FastTMXLayer*> FastTMXTiledMap::getLayers() const
{
Vector<FastTMXLayer*> layers;
for (auto child : _children)
{
auto layer = dynamic_cast<FastTMXLayer*>(child);
if (layer)
{
layers.pushBack(layer);
}
}
return layers;
}
NS_AX_END

View File

@ -209,6 +209,12 @@ public:
std::string_view getResourceFile() const { return _tmxFile; }
TMXMapInfo* getMapInfo() const { return _mapInfo; }
TMXTilesetInfo* getTilesetInfo(std::string_view tsxNameString);
Vector<ax::FastTMXLayer*> getLayers() const;
/**
* @js ctor
*/
@ -248,6 +254,8 @@ protected:
std::string _tmxFile;
TMXMapInfo* _mapInfo;
private:
AX_DISALLOW_COPY_AND_ASSIGN(FastTMXTiledMap);
};