From a5bdad448f7e1d274d1fc5b55b05475de36b3a59 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 5 Dec 2023 22:37:22 -0600 Subject: [PATCH] [nostalgia/core] Cleanup headers, TileSheet versioning --- .../core/include/nostalgia/core/color.hpp | 2 -- .../core/include/nostalgia/core/tilesheet.hpp | 5 ++- .../modules/core/src/keel/keelmodule.cpp | 4 +-- .../modules/core/src/keel/typeconv.cpp | 33 +++++++++---------- .../modules/core/src/keel/typeconv.hpp | 24 +++++++------- 5 files changed, 31 insertions(+), 37 deletions(-) diff --git a/src/nostalgia/modules/core/include/nostalgia/core/color.hpp b/src/nostalgia/modules/core/include/nostalgia/core/color.hpp index 90efbed0..e843b654 100644 --- a/src/nostalgia/modules/core/include/nostalgia/core/color.hpp +++ b/src/nostalgia/modules/core/include/nostalgia/core/color.hpp @@ -7,8 +7,6 @@ #include #include -#include "context.hpp" - namespace nostalgia::core { using Color16 = uint16_t; diff --git a/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp b/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp index 91f22839..fc193b40 100644 --- a/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp +++ b/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp @@ -12,9 +12,6 @@ #include -#include "color.hpp" -#include "context.hpp" -#include "ptidxconv.hpp" #include "palette.hpp" namespace nostalgia::core { @@ -278,6 +275,8 @@ struct TileSheet { }; +using TileSheetV3 = TileSheet; + struct CompactTileSheet { static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.CompactTileSheet"; static constexpr auto TypeVersion = 1; diff --git a/src/nostalgia/modules/core/src/keel/keelmodule.cpp b/src/nostalgia/modules/core/src/keel/keelmodule.cpp index 09919475..96b2d4f1 100644 --- a/src/nostalgia/modules/core/src/keel/keelmodule.cpp +++ b/src/nostalgia/modules/core/src/keel/keelmodule.cpp @@ -17,9 +17,9 @@ namespace nostalgia::core { class KeelModule: public keel::Module { private: NostalgiaPaletteToPaletteConverter m_nostalgiaPaletteToPaletteConverter; - TileSheetV1ToTileSheetConverter m_tileSheetV1ToTileSheetV2Converter; + TileSheetV1ToTileSheetV2Converter m_tileSheetV1ToTileSheetV2Converter; + TileSheetV2ToTileSheetV3Converter m_tileSheetV2ToTileSheetConverter; TileSheetToCompactTileSheetConverter m_tileSheetToCompactTileSheetConverter; - TileSheetV2ToTileSheetConverter m_tileSheetV2ToTileSheetConverter; public: [[nodiscard]] diff --git a/src/nostalgia/modules/core/src/keel/typeconv.cpp b/src/nostalgia/modules/core/src/keel/typeconv.cpp index deab2108..7a3662ea 100644 --- a/src/nostalgia/modules/core/src/keel/typeconv.cpp +++ b/src/nostalgia/modules/core/src/keel/typeconv.cpp @@ -14,10 +14,10 @@ ox::Error NostalgiaPaletteToPaletteConverter::convert( return {}; } -ox::Error TileSheetV1ToTileSheetConverter::convert( +ox::Error TileSheetV1ToTileSheetV2Converter::convert( keel::Context&, TileSheetV1 &src, - TileSheet &dst) const noexcept { + TileSheetV2 &dst) const noexcept { dst.bpp = src.bpp; dst.defaultPalette = std::move(src.defaultPalette); dst.subsheet.name = "Root"; @@ -27,20 +27,9 @@ ox::Error TileSheetV1ToTileSheetConverter::convert( return {}; } -ox::Error TileSheetToCompactTileSheetConverter::convert( - keel::Context&, - TileSheet &src, - CompactTileSheet &dst) const noexcept { - dst.bpp = src.bpp; - dst.defaultPalette = std::move(src.defaultPalette); - dst.pixels = src.pixels(); - return {}; -} - - -void TileSheetV2ToTileSheetConverter::convertSubsheet( +void TileSheetV2ToTileSheetV3Converter::convertSubsheet( TileSheetV2::SubSheet &src, - TileSheet::SubSheet &dst, + TileSheetV3::SubSheet &dst, SubSheetId &idIt) noexcept { dst.id = idIt; dst.name = std::move(src.name); @@ -54,14 +43,24 @@ void TileSheetV2ToTileSheetConverter::convertSubsheet( } } -ox::Error TileSheetV2ToTileSheetConverter::convert( +ox::Error TileSheetV2ToTileSheetV3Converter::convert( keel::Context&, TileSheetV2 &src, - TileSheet &dst) const noexcept { + TileSheetV3 &dst) const noexcept { dst.bpp = src.bpp; dst.defaultPalette = std::move(src.defaultPalette); convertSubsheet(src.subsheet, dst.subsheet, dst.idIt); return {}; } +ox::Error TileSheetToCompactTileSheetConverter::convert( + keel::Context&, + TileSheet &src, + CompactTileSheet &dst) const noexcept { + dst.bpp = src.bpp; + dst.defaultPalette = std::move(src.defaultPalette); + dst.pixels = src.pixels(); + return {}; +} + } diff --git a/src/nostalgia/modules/core/src/keel/typeconv.hpp b/src/nostalgia/modules/core/src/keel/typeconv.hpp index 284242f1..012ff7fe 100644 --- a/src/nostalgia/modules/core/src/keel/typeconv.hpp +++ b/src/nostalgia/modules/core/src/keel/typeconv.hpp @@ -20,22 +20,20 @@ class NostalgiaPaletteToPaletteConverter: public keel::Converter { - ox::Error convert(keel::Context&, TileSheetV1 &src, TileSheet &dst) const noexcept final; +class TileSheetV1ToTileSheetV2Converter: public keel::Converter { + ox::Error convert(keel::Context&, TileSheetV1 &src, TileSheetV2 &dst) const noexcept final; +}; + +class TileSheetV2ToTileSheetV3Converter: public keel::Converter { + static void convertSubsheet( + TileSheetV2::SubSheet &src, + TileSheetV3::SubSheet &dst, + SubSheetId &idIt) noexcept; + ox::Error convert(keel::Context&, TileSheetV2 &src, TileSheetV3 &dst) const noexcept final; }; class TileSheetToCompactTileSheetConverter: public keel::Converter { - ox::Error convert(keel::Context&, TileSheet &src, CompactTileSheet &dst) const noexcept final; -}; - -class TileSheetV2ToTileSheetConverter: public keel::Converter { - static void convertSubsheet( - TileSheetV2::SubSheet &src, - TileSheet::SubSheet &dst, - SubSheetId &idIt) noexcept; - - ox::Error convert(keel::Context&, TileSheetV2 &src, TileSheet &dst) const noexcept final; - + ox::Error convert(keel::Context&, TileSheet &src, CompactTileSheet &dst) const noexcept final; }; }