diff --git a/include/emitter.h b/include/emitter.h index 27273fbb..8056109e 100644 --- a/include/emitter.h +++ b/include/emitter.h @@ -47,6 +47,12 @@ void emitAnim(PtContext &ctx, std::vector> &outFram void emitAttributes(PtContext &ctx, std::ostream &out, std::unordered_map behaviorReverseMap, const CompiledTileset &tileset); +/** + * TODO : fill in doc comment + */ +void emitDecompiled(PtContext &ctx, png::image &bottom, png::image &middle, + png::image &top, const DecompiledTileset &tileset); + } // namespace porytiles #endif // PORYTILES_EMITTER_H diff --git a/include/types.h b/include/types.h index 626adcc1..c112a274 100644 --- a/include/types.h +++ b/include/types.h @@ -223,6 +223,16 @@ struct RGBATile { pixels.at(row * TILE_SIDE_LENGTH + col) = value; } + bool equalsAfterBgrConversion(const RGBATile &other) + { + for (std::size_t i = 0; i < TILE_NUM_PIX; i++) { + if (rgbaToBgr(this->pixels.at(i)) != rgbaToBgr(other.pixels.at(i))) { + 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 diff --git a/src/decompiler.cpp b/src/decompiler.cpp index 9d5d91e8..b46bd859 100644 --- a/src/decompiler.cpp +++ b/src/decompiler.cpp @@ -1,8 +1,11 @@ #include "decompiler.h" #include +#include #include +#include "compiler.h" +#include "importer.h" #include "ptcontext.h" #include "types.h" @@ -37,3 +40,28 @@ std::unique_ptr decompile(PtContext &ctx, const CompiledTiles } } // namespace porytiles + +TEST_CASE("decompile should decompile a basic tileset") +{ + porytiles::PtContext ctx{}; + ctx.fieldmapConfig.numPalettesInPrimary = 6; + ctx.fieldmapConfig.numPalettesTotal = 13; + ctx.compilerConfig.mode = porytiles::CompilerMode::PRIMARY; + + REQUIRE(std::filesystem::exists("res/tests/simple_metatiles_2/primary/bottom.png")); + REQUIRE(std::filesystem::exists("res/tests/simple_metatiles_2/primary/middle.png")); + REQUIRE(std::filesystem::exists("res/tests/simple_metatiles_2/primary/top.png")); + png::image bottomPrimary{"res/tests/simple_metatiles_2/primary/bottom.png"}; + png::image middlePrimary{"res/tests/simple_metatiles_2/primary/middle.png"}; + png::image topPrimary{"res/tests/simple_metatiles_2/primary/top.png"}; + porytiles::DecompiledTileset decompiledPrimary = porytiles::importLayeredTilesFromPngs( + ctx, std::unordered_map{}, bottomPrimary, middlePrimary, topPrimary); + auto compiledPrimary = porytiles::compile(ctx, decompiledPrimary); + + auto decompiledViaAlgorithm = porytiles::decompile(ctx, *compiledPrimary); + + CHECK(decompiledViaAlgorithm->tiles.size() == decompiledPrimary.tiles.size()); + for (std::size_t i = 0; i < decompiledViaAlgorithm->tiles.size(); i++) { + CHECK(decompiledViaAlgorithm->tiles.at(i).equalsAfterBgrConversion(decompiledPrimary.tiles.at(i))); + } +} \ No newline at end of file diff --git a/src/emitter.cpp b/src/emitter.cpp index 5e27603d..afe95069 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -229,6 +229,16 @@ void emitAttributes(PtContext &ctx, std::ostream &out, std::unordered_map &bottom, png::image &middle, + png::image &top, const DecompiledTileset &tileset) { + // TODO : this function needs to receive the attributes map so it knows the number of metatiles + + // For now just assume triple layer + for(std::size_t metatileIndex = 0; metatileIndex < tileset.tiles.size() / 12; metatileIndex++) { + + } +} + } // namespace porytiles // --------------------