diff --git a/include/types.h b/include/types.h index 70d3c802..789bd394 100644 --- a/include/types.h +++ b/include/types.h @@ -140,12 +140,16 @@ struct RGBATile { * Porytiles to give much more detailed error messages. */ TileType type; + + // raw tile index, used for FREESTANDING and ANIM types std::size_t tileIndex; + + // LAYERED specific metadata TileLayer layer; - // metatileIndex is which metatile on the sheet, used in compile-primary and compile-secondary std::size_t metatileIndex; - // Subtile within the metatile Subtile subtile; + + // ANIM specific metadata std::string anim; std::string frame; @@ -160,6 +164,16 @@ struct RGBATile { return pixels[row * TILE_SIDE_LENGTH + col]; } + [[nodiscard]] bool transparent(const RGBA32 &transparencyColor) const + { + for (std::size_t i = 0; i < pixels.size(); i++) { + if (pixels[i] != transparencyColor && pixels[i].alpha != ALPHA_TRANSPARENT) { + return false; + } + } + return true; + } + auto operator==(const RGBATile &other) const { return this->pixels == other.pixels; } // Ignore the other fields for purposes of ordering the tiles @@ -174,7 +188,7 @@ struct RGBATile { return std::strong_ordering::greater; } - friend std::ostream &operator<<(std::ostream &, const RGBATile &); + friend std::ostream &operator<<(std::ostream &os, const RGBATile &tile); }; extern const RGBATile RGBA_TILE_BLACK; @@ -612,8 +626,9 @@ struct CompilerConfig { CompilerMode mode; RGBA32 transparencyColor; std::size_t maxRecurseCount; + bool tripleLayer; - CompilerConfig() : mode{}, transparencyColor{RGBA_MAGENTA}, maxRecurseCount{2'000'000} {} + CompilerConfig() : mode{}, transparencyColor{RGBA_MAGENTA}, maxRecurseCount{2'000'000}, tripleLayer{true} {} }; struct CompilerContext { diff --git a/src/importer.cpp b/src/importer.cpp index eb768ad3..b1af548e 100644 --- a/src/importer.cpp +++ b/src/importer.cpp @@ -31,15 +31,15 @@ DecompiledTileset importTilesFromPng(PtContext &ctx, const png::image bottomTiles{}; + std::vector middleTiles{}; + std::vector topTiles{}; + for (std::size_t bottomTileIndex = 0; bottomTileIndex < METATILE_TILE_SIDE_LENGTH * METATILE_TILE_SIDE_LENGTH; bottomTileIndex++) { - size_t tileRow = bottomTileIndex / METATILE_TILE_SIDE_LENGTH; - size_t tileCol = bottomTileIndex % METATILE_TILE_SIDE_LENGTH; + std::size_t tileRow = bottomTileIndex / METATILE_TILE_SIDE_LENGTH; + std::size_t tileCol = bottomTileIndex % METATILE_TILE_SIDE_LENGTH; RGBATile bottomTile{}; bottomTile.type = TileType::LAYERED; bottomTile.layer = TileLayer::BOTTOM; bottomTile.metatileIndex = metatileIndex; bottomTile.subtile = static_cast(bottomTileIndex); for (std::size_t pixelIndex = 0; pixelIndex < TILE_NUM_PIX; pixelIndex++) { - size_t pixelRow = + std::size_t pixelRow = (metatileRow * METATILE_SIDE_LENGTH) + (tileRow * TILE_SIDE_LENGTH) + (pixelIndex / TILE_SIDE_LENGTH); - size_t pixelCol = + std::size_t pixelCol = (metatileCol * METATILE_SIDE_LENGTH) + (tileCol * TILE_SIDE_LENGTH) + (pixelIndex % TILE_SIDE_LENGTH); bottomTile.pixels[pixelIndex].red = bottom[pixelRow][pixelCol].red; bottomTile.pixels[pixelIndex].green = bottom[pixelRow][pixelCol].green; @@ -111,20 +114,21 @@ DecompiledTileset importLayeredTilesFromPngs(PtContext &ctx, const png::image(middleTileIndex); for (std::size_t pixelIndex = 0; pixelIndex < TILE_NUM_PIX; pixelIndex++) { - size_t pixelRow = + std::size_t pixelRow = (metatileRow * METATILE_SIDE_LENGTH) + (tileRow * TILE_SIDE_LENGTH) + (pixelIndex / TILE_SIDE_LENGTH); - size_t pixelCol = + std::size_t pixelCol = (metatileCol * METATILE_SIDE_LENGTH) + (tileCol * TILE_SIDE_LENGTH) + (pixelIndex % TILE_SIDE_LENGTH); middleTile.pixels[pixelIndex].red = middle[pixelRow][pixelCol].red; middleTile.pixels[pixelIndex].green = middle[pixelRow][pixelCol].green; @@ -132,20 +136,21 @@ DecompiledTileset importLayeredTilesFromPngs(PtContext &ctx, const png::image(topTileIndex); for (std::size_t pixelIndex = 0; pixelIndex < TILE_NUM_PIX; pixelIndex++) { - size_t pixelRow = + std::size_t pixelRow = (metatileRow * METATILE_SIDE_LENGTH) + (tileRow * TILE_SIDE_LENGTH) + (pixelIndex / TILE_SIDE_LENGTH); - size_t pixelCol = + std::size_t pixelCol = (metatileCol * METATILE_SIDE_LENGTH) + (tileCol * TILE_SIDE_LENGTH) + (pixelIndex % TILE_SIDE_LENGTH); topTile.pixels[pixelIndex].red = top[pixelRow][pixelCol].red; topTile.pixels[pixelIndex].green = top[pixelRow][pixelCol].green; @@ -153,7 +158,28 @@ DecompiledTileset importLayeredTilesFromPngs(PtContext &ctx, const png::image 0) { + die_errorCount(ctx.err, ctx.inputPaths.modeBasedInputPath(ctx.compilerConfig.mode), + "errors generated during layered tile import"); } return decompiledTiles; @@ -205,18 +231,18 @@ void importAnimTiles(PtContext &ctx, const std::vector