1
0
mirror of https://github.com/ScrelliCopter/tmx2gba.git synced 2025-02-21 03:29:25 +11:00

restore build & basic functionality

This commit is contained in:
2024-04-10 02:31:43 +10:00
parent ebe83ffb68
commit 385f7b069f
7 changed files with 170 additions and 159 deletions

View File

@@ -1,5 +1,6 @@
add_library(base64 add_library(base64
base64.cpp base64.h) base64.cpp base64.h)
add_library(base64::base64 ALIAS base64) add_library(base64::base64 ALIAS base64)
set_target_properties(base64 PROPERTIES CXX_STANDARD 17)
target_include_directories(base64 target_include_directories(base64
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

View File

@@ -1,5 +1,6 @@
add_executable(tmx2gba add_executable(tmx2gba
argparse.hpp argparse.cpp argparse.hpp argparse.cpp
$<$<NOT:$<TARGET_EXISTS:ZLIB::ZLIB>>:gzip.hpp gzip.cpp>
tmxlayer.hpp tmxlayer.hpp
tmxobject.hpp tmxobject.hpp
tmxtileset.hpp tmxtileset.hpp
@@ -15,16 +16,21 @@ target_include_directories(tmx2gba PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
set_target_properties(tmx2gba PROPERTIES CXX_STANDARD 20) set_target_properties(tmx2gba PROPERTIES CXX_STANDARD 20)
target_compile_definitions(${PROJECT_NAME} PRIVATE
$<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WARNINGS> # disable msvc warning
$<$<TARGET_EXISTS:ZLIB::ZLIB>:USE_ZLIB>)
# Enable strong warnings # Enable strong warnings
target_compile_options(tmx2gba PRIVATE target_compile_options(tmx2gba PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/Wall> $<$<CXX_COMPILER_ID:MSVC>:/Wall>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall -Wextra -pedantic> $<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall -Wextra -pedantic>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded>) $<$<CXX_COMPILER_ID:Clang,AppleClang>:-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded>)
target_link_libraries(${PROJECT_NAME} base64::base64 pugixml Zstd::Zstd target_link_libraries(tmx2gba External::rapidxml)
#pugixml)
target_link_libraries(tmx2gba base64::base64 Zstd::Zstd
$<$<TARGET_EXISTS:ZLIB::ZLIB>:ZLIB::ZLIB> $<$<TARGET_EXISTS:ZLIB::ZLIB>:ZLIB::ZLIB>
$<$<TARGET_EXISTS:miniz::miniz>:miniz::miniz>) $<$<TARGET_EXISTS:miniz::miniz>:miniz::miniz>)
target_link_libraries(${PROJECT_NAME} External::rapidxml)
if (TMX2GBA_DKP_INSTALL) if (TMX2GBA_DKP_INSTALL)
if (DEFINED ENV{DEVKITPRO}) if (DEFINED ENV{DEVKITPRO})

View File

@@ -1,34 +1,33 @@
/* tmxlayer.hpp - Copyright (C) 2015-2022 a dinosaur (zlib, see COPYING.txt) */ /* tmxlayer.hpp - Copyright (C) 2015-2024 a dinosaur (zlib, see COPYING.txt) */
#ifndef TMXLAYER_HPP #ifndef TMXLAYER_HPP
#define TMXLAYER_HPP #define TMXLAYER_HPP
#include <vector>
#include <span>
#include <string> #include <string>
#include <string_view>
#include <cstdint> #include <cstdint>
#include <utility> #include <utility>
class TmxLayer class TmxLayer
{ {
std::string mName;
int mWidth, mHeight;
std::vector<uint32_t> mTileDat;
public: public:
static constexpr uint32_t FLIP_HORZ = 0x80000000; static constexpr uint32_t FLIP_HORZ = 0x80000000;
static constexpr uint32_t FLIP_VERT = 0x40000000; static constexpr uint32_t FLIP_VERT = 0x40000000;
static constexpr uint32_t FLIP_DIAG = 0x20000000; static constexpr uint32_t FLIP_DIAG = 0x20000000;
static constexpr uint32_t FLIP_MASK = 0xE0000000; static constexpr uint32_t FLIP_MASK = 0xE0000000;
TmxLayer() : mWidth(0), mHeight(0), mTileDat(nullptr) {} TmxLayer(int width, int height, const std::string_view name, std::vector<uint32_t>&& tileDat) noexcept
TmxLayer(int aWidth, int aHeight, std::string aName, uint32_t* aTileDat) : mName(name), mWidth(width), mHeight(height), mTileDat(std::move(tileDat)) {}
: mName(std::move(aName)), mWidth(aWidth), mHeight(aHeight), mTileDat(aTileDat) {}
inline ~TmxLayer() { delete[] mTileDat; }
constexpr const std::string& GetName() const { return mName; } [[nodiscard]] constexpr const std::string_view Name() const noexcept { return mName; }
constexpr int GetWidth() const { return mWidth; } [[nodiscard]] constexpr std::pair<int, int> TileCount() const noexcept { return { mWidth, mHeight }; }
constexpr int GetHeight() const { return mHeight; } [[nodiscard]] constexpr const std::span<const uint32_t> Tiles() const noexcept { return mTileDat; }
constexpr const uint32_t* GetData() const { return mTileDat; }
private:
std::string mName;
int mWidth, mHeight;
uint32_t* mTileDat;
}; };
#endif//TMXLAYER_HPP #endif//TMXLAYER_HPP

View File

@@ -1,4 +1,4 @@
/* tmxobject.hpp - Copyright (C) 2015-2022 a dinosaur (zlib, see COPYING.txt) */ /* tmxobject.hpp - Copyright (C) 2015-2024 a dinosaur (zlib, see COPYING.txt) */
#ifndef TMXOBJECT_HPP #ifndef TMXOBJECT_HPP
#define TMXOBJECT_HPP #define TMXOBJECT_HPP
@@ -9,17 +9,17 @@
class TmxObject class TmxObject
{ {
public: public:
TmxObject() : mX(0.0f), mY(0.0f) {} TmxObject(std::string_view name, float x, float y) : mName(name), mPos{ x, y } {}
TmxObject(std::string aName, float aX, float aY)
: mName(std::move(aName)), mX(aX), mY(aY) {}
~TmxObject() = default;
constexpr const std::string& GetName() const { return mName; } template <typename T>
inline void GetPos(float& aOutX, float& aOutY) const { aOutX = mX; aOutY = mY; } struct Position { T x, y; };
constexpr const std::string_view Name() const noexcept { return mName; }
constexpr Position<float> Pos() const noexcept { return mPos; }
private: private:
std::string mName; std::string mName;
float mX, mY; Position<float> mPos;
}; };
#endif//TMXOBJECT_HPP #endif//TMXOBJECT_HPP

View File

@@ -4,47 +4,74 @@
#include "tmxtileset.hpp" #include "tmxtileset.hpp"
#include "tmxobject.hpp" #include "tmxobject.hpp"
#include "tmxlayer.hpp" #include "tmxlayer.hpp"
#include "base64.h"
#ifdef USE_ZLIB
# include <zlib.h>
#else
# include "gzip.hpp"
#endif
#include <rapidxml/rapidxml.hpp>
#include <optional> #include <optional>
#include <algorithm> #include <algorithm>
#include <ranges>
#include <sstream>
#include <fstream>
bool TmxReader::DecodeMap(uint32_t* aOut, size_t aOutSize, const std::string& aBase64Dat)
class TmxMap
{
int mWidth = 0, mHeight = 0;
std::vector<TmxLayer> mLayers;
std::vector<TmxTileset> mTilesets;
std::vector<TmxObject> mObjects;
[[nodiscard]] bool Decode(std::span<uint32_t> out, const std::string_view base64);
void ReadTileset(rapidxml::xml_node<>* aXNode);
void ReadLayer(rapidxml::xml_node<>* aXNode);
void ReadObjects(rapidxml::xml_node<>* aXNode);
public:
[[nodiscard]] bool Load(const std::string_view inPath);
constexpr std::pair<int, int> TileCount() const noexcept { return { mWidth, mHeight }; }
constexpr const std::vector<TmxTileset>& Tilesets() const noexcept { return mTilesets; }
constexpr const std::vector<TmxLayer>& Layers() const noexcept { return mLayers; }
};
bool TmxMap::Decode(std::span<uint32_t> out, const std::string_view base64)
{ {
// Cut leading & trailing whitespace (including newlines) // Cut leading & trailing whitespace (including newlines)
auto beg = std::find_if_not(aBase64Dat.begin(), aBase64Dat.end(), ::isspace); auto beg = std::find_if_not(base64.begin(), base64.end(), ::isspace);
if (beg == std::end(aBase64Dat)) if (beg == std::end(base64))
return false; return false;
auto end = std::find_if_not(aBase64Dat.rbegin(), aBase64Dat.rend(), ::isspace); auto end = std::find_if_not(base64.rbegin(), base64.rend(), ::isspace);
std::size_t begOff = std::distance(aBase64Dat.begin(), beg); std::size_t begOff = std::distance(base64.begin(), beg);
std::size_t endOff = std::distance(end, aBase64Dat.rend()) - begOff; std::size_t endOff = std::distance(end, base64.rend()) - begOff;
auto trimmed = aBase64Dat.substr(begOff, endOff); const auto trimmed = base64.substr(begOff, endOff);
// Decode base64 string // Decode base64 string
std::string decoded = base64_decode(trimmed); std::string decoded = base64_decode(trimmed);
// Decompress compressed data // Decompress compressed data
auto dstSize = static_cast<mz_ulong>(aOutSize); auto dstSize = static_cast<uLongf>(sizeof(uint32_t) * out.size());
int res = uncompress( int res = uncompress(
reinterpret_cast<unsigned char*>(aOut), reinterpret_cast<unsigned char*>(out.data()),
&dstSize, &dstSize,
reinterpret_cast<const unsigned char*>(decoded.data()), reinterpret_cast<const unsigned char*>(decoded.data()),
static_cast<mz_ulong>(decoded.size())); static_cast<uLong>(decoded.size()));
decoded.clear();
if (res < 0)
return false;
return true; return res >= 0;
} }
void TmxReader::ReadTileset(rapidxml::xml_node<>* aXNode) void TmxMap::ReadTileset(rapidxml::xml_node<>* aXNode)
{ {
rapidxml::xml_attribute<>* xAttrib; std::string_view name, source;
uint32_t firstGid = 0, lastGid = 0;
const char* name = "";
const char* source = "";
uint32_t firstGid = 0;
// Read name // Read name
xAttrib = aXNode->first_attribute("name"); auto xAttrib = aXNode->first_attribute("name");
if (xAttrib != nullptr) if (xAttrib != nullptr)
name = xAttrib->value(); name = xAttrib->value();
@@ -58,19 +85,21 @@ void TmxReader::ReadTileset(rapidxml::xml_node<>* aXNode)
if (xAttrib != nullptr) if (xAttrib != nullptr)
firstGid = static_cast<uint32_t>(std::stoul(xAttrib->value())); firstGid = static_cast<uint32_t>(std::stoul(xAttrib->value()));
mTilesets.push_back(new TmxTileset(name, source, firstGid)); // Read last global ID
xAttrib = aXNode->first_attribute("lastgid");
if (xAttrib)
lastGid = static_cast<uint32_t>(std::stoul(xAttrib->value()));
mTilesets.emplace_back(TmxTileset(name, source, firstGid, lastGid));
} }
void TmxReader::ReadLayer(rapidxml::xml_node<>* aXNode) void TmxMap::ReadLayer(rapidxml::xml_node<>* aXNode)
{ {
rapidxml::xml_attribute<>* xAttrib; std::string_view name;
const char* name = ""; int width = 0, height = 0;
int width = 0;
int height = 0;
uint32_t* tileDat = nullptr;
// Read name // Read name
xAttrib = aXNode->first_attribute("name"); auto xAttrib = aXNode->first_attribute("name");
if (xAttrib != nullptr) if (xAttrib != nullptr)
name = xAttrib->value(); name = xAttrib->value();
@@ -86,34 +115,29 @@ void TmxReader::ReadLayer(rapidxml::xml_node<>* aXNode)
// Read tile data // Read tile data
auto xData = aXNode->first_node("data"); auto xData = aXNode->first_node("data");
if (xData != nullptr) if (xData == nullptr)
{ return;
// TODO: don't assume base64 & zlib
tileDat = new uint32_t[width * height];
if (!DecodeMap(tileDat, width * height * sizeof(uint32_t), std::string(xData->value())))
{
delete[] tileDat;
tileDat = nullptr;
}
}
mLayers.push_back(new TmxLayer(width, height, name, tileDat)); // TODO: don't assume base64
std::vector<uint32_t> tileDat(width * height);
if (!Decode(tileDat, xData->value()))
return;
mLayers.emplace_back(TmxLayer(width, height, name, std::move(tileDat)));
} }
void TmxReader::ReadObjects(rapidxml::xml_node<>* aXNode) void TmxMap::ReadObjects(rapidxml::xml_node<>* aXNode)
{ {
for (auto xNode = aXNode->first_node(); xNode != nullptr; xNode = xNode->next_sibling()) for (auto xNode = aXNode->first_node(); xNode != nullptr; xNode = xNode->next_sibling())
{ {
if (strcmp(xNode->name(), "object") != 0) if (strcmp(xNode->name(), "object") != 0)
continue; continue;
rapidxml::xml_attribute<>* xAttrib; std::string_view name;
const char* name = ""; float x = 0.0f, y = 0.0f;
float x = 0.0f;
float y = 0.0f;
// Read name // Read name
xAttrib = xNode->first_attribute("name"); auto xAttrib = xNode->first_attribute("name");
if (xAttrib != nullptr) if (xAttrib != nullptr)
name = xAttrib->value(); name = xAttrib->value();
@@ -127,27 +151,16 @@ void TmxReader::ReadObjects(rapidxml::xml_node<>* aXNode)
if (xAttrib != nullptr) if (xAttrib != nullptr)
y = std::stof(xAttrib->value()); y = std::stof(xAttrib->value());
mObjects.push_back(new TmxObject(name, x, y)); mObjects.emplace_back(TmxObject(name, x, y));
} }
} }
void TmxReader::Open(std::istream& aIn) bool TmxMap::Load(const std::string_view inPath)
{ {
// Delete old tilesets // Read file into a buffer
for (auto tileset : mTilesets) auto inFile = std::ifstream(inPath);
delete tileset;
mTilesets.clear();
// Delete old layers
for (auto layer : mLayers)
delete layer;
mLayers.clear();
mGidTable.clear();
// Read string into a buffer
std::stringstream buf; std::stringstream buf;
buf << aIn.rdbuf(); buf << inFile.rdbuf();
std::string strXml = buf.str(); std::string strXml = buf.str();
buf.clear(); buf.clear();
@@ -158,7 +171,7 @@ void TmxReader::Open(std::istream& aIn)
// Get map node // Get map node
auto xMap = xDoc.first_node("map"); auto xMap = xDoc.first_node("map");
if (xMap == nullptr) if (xMap == nullptr)
return; return false;
// Read map attribs // Read map attribs
rapidxml::xml_attribute<>* xAttrib = nullptr; rapidxml::xml_attribute<>* xAttrib = nullptr;
@@ -171,20 +184,16 @@ void TmxReader::Open(std::istream& aIn)
for (auto xNode = xMap->first_node(); xNode != nullptr; xNode = xNode->next_sibling()) for (auto xNode = xMap->first_node(); xNode != nullptr; xNode = xNode->next_sibling())
{ {
// Read layer nodes // Read layer nodes
if (strcmp(xNode->name(), "layer") == 0) const auto xName = xNode->name();
if (std::strcmp(xName, "layer") == 0)
ReadLayer(xNode); ReadLayer(xNode);
else else if (std::strcmp(xName, "tileset") == 0)
if (strcmp(xNode->name(), "tileset") == 0)
ReadTileset(xNode); ReadTileset(xNode);
else else if (std::strcmp(xName, "objectgroup") == 0)
if (strcmp(xNode->name(), "objectgroup") == 0)
ReadObjects(xNode); ReadObjects(xNode);
} }
// Generate global id table return true;
for (auto tileset : mTilesets)
mGidTable.push_back(tileset->GetFirstGid());
std::sort(mGidTable.rbegin(), mGidTable.rend());
} }
TmxReader::Error TmxReader::Open(const std::string& inPath, TmxReader::Error TmxReader::Open(const std::string& inPath,
@@ -193,98 +202,102 @@ TmxReader::Error TmxReader::Open(const std::string& inPath,
const std::string_view collisionName, const std::string_view collisionName,
const std::map<std::string, uint32_t>& objMapping) const std::map<std::string, uint32_t>& objMapping)
{ {
tmx::Map map; TmxMap map;
if (!map.load(inPath)) if (!map.Load(inPath))
return Error::LOAD_FAILED; return Error::LOAD_FAILED;
using tmx::TileLayer;
using tmx::ObjectGroup;
using std::optional; using std::optional;
using std::reference_wrapper; using std::reference_wrapper;
optional<reference_wrapper<const TileLayer>> layerGfx; optional<reference_wrapper<const TmxLayer>> layerGfx;
optional<reference_wrapper<const TileLayer>> layerCls; optional<reference_wrapper<const TmxLayer>> layerCls;
optional<reference_wrapper<const TileLayer>> layerPal; optional<reference_wrapper<const TmxLayer>> layerPal;
std::vector<reference_wrapper<const ObjectGroup>> objGroups; optional<reference_wrapper<std::vector<const TmxObject>>> objGroups;
// Read layers // Read layers
for (const auto& layer : map.getLayers()) for (const auto& layer : map.Layers())
{ {
auto name = layer->getName(); auto name = layer.Name();
if (layer->getType() == tmx::Layer::Type::Tile) //FIXME: no error reporting when a layer fails to load
{ if (layer.Tiles().empty())
const auto& tileLayer = layer->getLayerAs<TileLayer>(); continue;
// tmxlite unfortunately has no error reporting when a layer fails to load,
// empty check will suffice for the time being
if (tileLayer.getTiles().empty())
continue;
if (layerGfx == std::nullopt && (graphicsName.empty() || name == graphicsName)) if (!layerGfx.has_value() && (graphicsName.empty() || name == graphicsName)) { layerGfx = layer; }
layerGfx = tileLayer; if (!collisionName.empty() && !layerCls.has_value() && name == collisionName) { layerCls = layer; }
if (!collisionName.empty() && layerCls == std::nullopt && name == collisionName) if (!paletteName.empty() && !layerPal.has_value() && name == paletteName) { layerPal = layer; }
layerCls = tileLayer; /*
if (!paletteName.empty() && layerPal == std::nullopt && name == paletteName)
layerPal = tileLayer;
}
else if (!objMapping.empty() && layer->getType() == tmx::Layer::Type::Object) else if (!objMapping.empty() && layer->getType() == tmx::Layer::Type::Object)
{ {
objGroups.emplace_back(layer->getLayerAs<ObjectGroup>()); objGroups.emplace_back(layer->getLayerAs<ObjectGroup>());
} }
*/
} }
// Check layers // Check layers
if (layerGfx == std::nullopt) if (!layerGfx.has_value())
{ return graphicsName.empty()
if (graphicsName.empty()) ? Error::NO_LAYERS
return Error::NO_LAYERS; : Error::GRAPHICS_NOTFOUND;
else if (!layerCls.has_value() && !collisionName.empty())
return Error::GRAPHICS_NOTFOUND;
}
if (layerCls == std::nullopt && !collisionName.empty())
return Error::GRAPHICS_NOTFOUND; return Error::GRAPHICS_NOTFOUND;
if (layerPal == std::nullopt && !paletteName.empty()) if (!layerPal.has_value() && !paletteName.empty())
return Error::PALETTE_NOTFOUND; return Error::PALETTE_NOTFOUND;
// Read TMX map // Read TMX map
mSize = Size{ map.getTileCount().x, map.getTileCount().y }; mSize = Size{ map.TileCount().first, map.TileCount().second };
size_t numTiles = static_cast<size_t>(mSize.width) * static_cast<size_t>(mSize.height); size_t numTiles = static_cast<size_t>(mSize.width) * static_cast<size_t>(mSize.height);
// Read graphics layer // Read graphics layer
mGraphics.reserve(numTiles); mGraphics.reserve(numTiles);
for (auto tmxTile : layerGfx.value().get().getTiles()) for (auto tmxTile : layerGfx.value().get().Tiles())
mGraphics.emplace_back(Tile { tmxTile.ID, tmxTile.flipFlags }); mGraphics.emplace_back(Tile{ tmxTile & ~FLIP_MASK, static_cast<uint8_t>((tmxTile & FLIP_MASK) >> 28) });
// Read optional layers // Read optional layers
if (layerPal.has_value()) if (layerPal.has_value())
{ {
std::vector<uint32_t> v; std::vector<uint32_t> v;
v.reserve(numTiles); v.reserve(numTiles);
for (auto tmxTile : layerPal.value().get().getTiles()) for (auto tmxTile : layerPal.value().get().Tiles())
v.emplace_back(tmxTile.ID); v.emplace_back(tmxTile & ~FLIP_MASK);
mPalette.emplace(v); mPalette.emplace(v);
} }
if (layerCls.has_value()) if (layerCls.has_value())
{ {
std::vector<uint32_t> v; std::vector<uint32_t> v;
v.reserve(numTiles); v.reserve(numTiles);
for (auto tmxTile : layerCls.value().get().getTiles()) for (auto tmxTile : layerCls.value().get().Tiles())
v.emplace_back(tmxTile.ID); v.emplace_back(tmxTile & ~FLIP_MASK);
mCollision.emplace(v); mCollision.emplace(v);
} }
// Read tilesets // Read tilesets
const auto& tilesets = map.getTilesets(); const auto& tilesets = map.Tilesets();
mGidTable.reserve(tilesets.size()); mGidTable.reserve(tilesets.size());
for (const auto& set : tilesets) for (const auto& set : tilesets)
mGidTable.emplace_back(std::make_pair(set.getFirstGID(), set.getLastGID())); mGidTable.emplace_back(set.GidRange());
// Read objects // Read objects
if (!objMapping.empty()) if (!objMapping.empty())
{ {
std::vector<Object> v; std::vector<Object> v;
for (const auto& tmxObj : objGroups.value().get())
{
auto it = objMapping.find(std::string(tmxObj.Name()));
if (it == objMapping.end())
continue;
const auto& pos = tmxObj.Pos();
Object obj;
obj.id = it->second;
obj.x = pos.x;
obj.y = pos.y;
v.emplace_back(obj);
}
/*
for (const auto& group : objGroups) for (const auto& group : objGroups)
{ {
const auto& tmxObjects = group.get().getObjects(); const auto& tmxObjects = group.get().Objects();
v.reserve(v.size() + tmxObjects.size()); v.reserve(v.size() + tmxObjects.size());
for (const auto& tmxObj : tmxObjects) for (const auto& tmxObj : tmxObjects)
{ {
@@ -301,6 +314,7 @@ TmxReader::Error TmxReader::Open(const std::string& inPath,
v.emplace_back(obj); v.emplace_back(obj);
} }
} }
*/
mObjects.emplace(v); mObjects.emplace(v);
} }

View File

@@ -1,4 +1,4 @@
/* tmxreader.hpp - Copyright (C) 2015-2022 a dinosaur (zlib, see COPYING.txt) */ /* tmxreader.hpp - Copyright (C) 2015-2024 a dinosaur (zlib, see COPYING.txt) */
#ifndef TMXREADER_HPP #ifndef TMXREADER_HPP
#define TMXREADER_HPP #define TMXREADER_HPP
@@ -10,11 +10,6 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <optional> #include <optional>
#include <rapidxml/rapidxml.hpp>
class TmxTileset;
class TmxLayer;
class TmxObject;
class TmxReader class TmxReader
{ {

View File

@@ -1,28 +1,24 @@
/* tmxtileset.hpp - Copyright (C) 2015-2022 a dinosaur (zlib, see COPYING.txt) */ /* tmxtileset.hpp - Copyright (C) 2015-2024 a dinosaur (zlib, see COPYING.txt) */
#ifndef TMXTILESET_HPP #ifndef TMXTILESET_HPP
#define TMXTILESET_HPP #define TMXTILESET_HPP
#include <string> #include <string>
#include <string_view>
#include <cstdint> #include <cstdint>
#include <utility>
class TmxTileset class TmxTileset
{ {
std::string mName, mSource;
uint32_t mFirstGid = 0, mLastGid = 0;
public: public:
TmxTileset() : mFirstGid(0) {} TmxTileset(const std::string_view name, const std::string_view source, uint32_t firstGid, uint32_t lastGid)
TmxTileset(std::string aName, std::string aSource, uint32_t aFirstGid) : mName(name), mSource(source), mFirstGid(firstGid), mLastGid(lastGid) {}
: mName(std::move(aName)), mSource(std::move(aSource)), mFirstGid(aFirstGid) {}
~TmxTileset() = default;
constexpr const std::string& GetName() const { return mName; } [[nodiscard]] constexpr const std::string_view Name() const noexcept { return mName; }
constexpr const std::string& GetSource() const { return mSource; } [[nodiscard]] constexpr const std::string_view Source() const noexcept { return mSource; }
constexpr uint32_t GetFirstGid() const { return mFirstGid; } [[nodiscard]] constexpr const std::pair<uint32_t, uint32_t> GidRange() const noexcept { return { mFirstGid, mLastGid }; }
private:
std::string mName;
std::string mSource;
uint32_t mFirstGid;
}; };
#endif//TMXTILESET_HPP #endif//TMXTILESET_HPP