diff --git a/core/2d/FastTMXTiledMap.cpp b/core/2d/FastTMXTiledMap.cpp index 28accc6e42..d89e1ba48b 100644 --- a/core/2d/FastTMXTiledMap.cpp +++ b/core/2d/FastTMXTiledMap.cpp @@ -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 FastTMXTiledMap::getLayers() const +{ + Vector layers; + for (auto child : _children) + { + auto layer = dynamic_cast(child); + if (layer) + { + layers.pushBack(layer); + } + } + return layers; +} + NS_AX_END diff --git a/core/2d/FastTMXTiledMap.h b/core/2d/FastTMXTiledMap.h index dac2db0afe..6ab508cb54 100644 --- a/core/2d/FastTMXTiledMap.h +++ b/core/2d/FastTMXTiledMap.h @@ -209,6 +209,12 @@ public: std::string_view getResourceFile() const { return _tmxFile; } + TMXMapInfo* getMapInfo() const { return _mapInfo; } + + TMXTilesetInfo* getTilesetInfo(std::string_view tsxNameString); + + Vector getLayers() const; + /** * @js ctor */ @@ -248,6 +254,8 @@ protected: std::string _tmxFile; + TMXMapInfo* _mapInfo; + private: AX_DISALLOW_COPY_AND_ASSIGN(FastTMXTiledMap); };