diff --git a/include/Map.h b/include/Map.h index 3a6019a..244322e 100644 --- a/include/Map.h +++ b/include/Map.h @@ -33,7 +33,7 @@ private: }; struct TileSetData { - const char* texturePath{}; + std::string texturePath{}; tmx::Vector2i textureSize; uint32_t tileCount{}; tmx::Vector2u tileCount2D; @@ -45,32 +45,8 @@ private: std::vector> tileConstructors; void loadTileLayer(const tmx::TileLayer& layer); - static void addTile(float x, float y, const tmx::Vector2u& mapTileSize, int u, int v, int zIndex, const char* texturePath, bool hasCollision); + static void addTile(float x, float y, const tmx::Vector2u& mapTileSize, int u, int v, int zIndex, std::string texturePath, bool hasCollision); template static std::optional getLayerProperty(const std::vector& properties, std::string propertyName) { return std::nullopt; }; - template<> std::optional getLayerProperty(const std::vector& properties, std::string propertyName) { - auto zIndexIterator = std::ranges::find_if(properties, [propertyName](const tmx::Property& property) { - return property.getName().compare(propertyName) == 0; - }); - - if (zIndexIterator != properties.end() && zIndexIterator->getType() == tmx::Property::Type::Boolean) { - return zIndexIterator->getBoolValue(); - } - - return std::nullopt; - } - - template<> std::optional getLayerProperty(const std::vector& properties, std::string propertyName) - { - auto zIndexIterator = std::ranges::find_if(properties, [propertyName](const tmx::Property& property) { - return property.getName().compare(propertyName) == 0; - }); - - if (zIndexIterator != properties.end() && zIndexIterator->getType() == tmx::Property::Type::Int) { - return zIndexIterator->getIntValue(); - } - - return std::nullopt; - } }; \ No newline at end of file diff --git a/src/Map.cpp b/src/Map.cpp index e75db70..dab109b 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -26,6 +26,32 @@ #include "TileComponent.h" #include "VEGO.h" + +template<> std::optional Map::getLayerProperty(const std::vector& properties, std::string propertyName) { + auto zIndexIterator = std::ranges::find_if(properties, [propertyName](const tmx::Property& property) { + return property.getName().compare(propertyName) == 0; + }); + + if (zIndexIterator != properties.end() && zIndexIterator->getType() == tmx::Property::Type::Boolean) { + return zIndexIterator->getBoolValue(); + } + + return std::nullopt; +} + +template<> std::optional Map::getLayerProperty(const std::vector& properties, std::string propertyName) +{ + auto zIndexIterator = std::ranges::find_if(properties, [propertyName](const tmx::Property& property) { + return property.getName().compare(propertyName) == 0; + }); + + if (zIndexIterator != properties.end() && zIndexIterator->getType() == tmx::Property::Type::Int) { + return zIndexIterator->getIntValue(); + } + + return std::nullopt; +} + Map::Map(const char* path) { if (!this->map.load(path)) { @@ -138,12 +164,12 @@ void Map::loadTileLayer(const tmx::TileLayer& layer) this->tileConstructors.insert(this->tileConstructors.end(), tileConstructorRange.begin(), tileConstructorRange.end()); } -void Map::addTile(float x, float y, const tmx::Vector2u& mapTileSize, int u, int v, int zIndex, const char* texturePath, bool hasCollision) +void Map::addTile(float x, float y, const tmx::Vector2u& mapTileSize, int u, int v, int zIndex, std::string texturePath, bool hasCollision) { auto& tile(VEGO_Game().manager.addEntity()); tile.addComponent(x, y, mapTileSize.x, mapTileSize.y, 1); - tile.addComponent("assets/grassy-river-tiles.png" /*texturePath*/, v, u, zIndex); // why does uv need to be reversed? + tile.addComponent(texturePath.c_str(), v, u, zIndex); // why does uv need to be reversed? if (hasCollision) { // tag currently does not have a clear purposes, TODO: figure out appropriate tag name