mirror of
https://github.com/ScrelliCopter/tmx2gba.git
synced 2025-02-21 03:29:25 +11:00
zstd support
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "convert.hpp"
|
||||
#include "tmxreader.hpp"
|
||||
#include <cassert>
|
||||
|
||||
|
||||
bool convert::ConvertCharmap(std::vector<uint16_t>& out, int idxOffset, uint32_t defaultPal, const TmxReader& tmx)
|
||||
@@ -10,6 +11,10 @@ bool convert::ConvertCharmap(std::vector<uint16_t>& out, int idxOffset, uint32_t
|
||||
const auto palTiles = tmx.GetPaletteTiles();
|
||||
|
||||
const size_t numTiles = tmx.TileCount();
|
||||
assert(gfxTiles.size() == numTiles);
|
||||
if (palTiles.has_value())
|
||||
assert(palTiles.value().size() == numTiles);
|
||||
|
||||
out.reserve(numTiles);
|
||||
for (size_t i = 0; i < numTiles; ++i)
|
||||
{
|
||||
@@ -38,9 +43,12 @@ bool convert::ConvertCharmap(std::vector<uint16_t>& out, int idxOffset, uint32_t
|
||||
|
||||
bool convert::ConvertCollision(std::vector<uint8_t>& out, const TmxReader& tmx)
|
||||
{
|
||||
assert(tmx.GetCollisionTiles().has_value());
|
||||
const auto clsTiles = tmx.GetCollisionTiles().value();
|
||||
|
||||
size_t numTiles = tmx.TileCount();
|
||||
assert(clsTiles.size() == numTiles);
|
||||
|
||||
out.reserve(numTiles);
|
||||
for (size_t i = 0; i < numTiles; ++i)
|
||||
{
|
||||
@@ -54,6 +62,7 @@ bool convert::ConvertCollision(std::vector<uint8_t>& out, const TmxReader& tmx)
|
||||
|
||||
bool convert::ConvertObjects(std::vector<uint32_t>& out, const TmxReader& tmx)
|
||||
{
|
||||
assert(tmx.GetObjects().has_value());
|
||||
const auto objects = tmx.GetObjects().value();
|
||||
|
||||
for (auto obj : objects)
|
||||
|
||||
@@ -34,12 +34,18 @@ TmxReader::Error TmxReader::Open(const std::string& inPath,
|
||||
auto name = layer->getName();
|
||||
if (layer->getType() == tmx::Layer::Type::Tile)
|
||||
{
|
||||
const auto& tileLayer = layer->getLayerAs<TileLayer>();
|
||||
// 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))
|
||||
layerGfx = layer->getLayerAs<TileLayer>();
|
||||
layerGfx = tileLayer;
|
||||
if (!collisionName.empty() && layerCls == std::nullopt && name == collisionName)
|
||||
layerCls = layer->getLayerAs<TileLayer>();
|
||||
layerCls = tileLayer;
|
||||
if (!paletteName.empty() && layerPal == std::nullopt && name == paletteName)
|
||||
layerPal = layer->getLayerAs<TileLayer>();
|
||||
layerPal = tileLayer;
|
||||
}
|
||||
else if (!objMapping.empty() && layer->getType() == tmx::Layer::Type::Object)
|
||||
{
|
||||
@@ -70,7 +76,7 @@ TmxReader::Error TmxReader::Open(const std::string& inPath,
|
||||
mGraphics.emplace_back(Tile { tmxTile.ID, tmxTile.flipFlags });
|
||||
|
||||
// Read optional layers
|
||||
if (layerPal != std::nullopt)
|
||||
if (layerPal.has_value())
|
||||
{
|
||||
std::vector<uint32_t> v;
|
||||
v.reserve(numTiles);
|
||||
@@ -78,7 +84,7 @@ TmxReader::Error TmxReader::Open(const std::string& inPath,
|
||||
v.emplace_back(tmxTile.ID);
|
||||
mPalette.emplace(v);
|
||||
}
|
||||
if (layerCls != std::nullopt)
|
||||
if (layerCls.has_value())
|
||||
{
|
||||
std::vector<uint32_t> v;
|
||||
v.reserve(numTiles);
|
||||
|
||||
Reference in New Issue
Block a user