[nostalgia,olympic] Make performPackTransforms update type id when needed

This commit is contained in:
Gary Talent 2024-05-10 19:50:48 -05:00
parent 17f28d43d1
commit c4f6ee0026
4 changed files with 20 additions and 13 deletions

View File

@ -58,23 +58,25 @@ static class: public keel::Module {
ox::Vector<keel::PackTransform> packTransforms() const noexcept final { ox::Vector<keel::PackTransform> packTransforms() const noexcept final {
return { return {
// convert tilesheets to CompactTileSheets // convert tilesheets to CompactTileSheets
[](keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) -> ox::Error { [](keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) -> ox::Result<bool> {
if (typeId == ox::ModelTypeId_v<TileSheetV1> || if (typeId == ox::ModelTypeId_v<TileSheetV1> ||
typeId == ox::ModelTypeId_v<TileSheetV2> || typeId == ox::ModelTypeId_v<TileSheetV2> ||
typeId == ox::ModelTypeId_v<TileSheetV3> || typeId == ox::ModelTypeId_v<TileSheetV3> ||
typeId == ox::ModelTypeId_v<TileSheetV4>) { typeId == ox::ModelTypeId_v<TileSheetV4>) {
return keel::convertBuffToBuff<CompactTileSheet>( oxReturnError(keel::convertBuffToBuff<CompactTileSheet>(
ctx, buff, ox::ClawFormat::Metal).moveTo(buff); ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
return true;
} }
return {}; return false;
}, },
[](keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) -> ox::Error { [](keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) -> ox::Result<bool> {
if (typeId == ox::ModelTypeId_v<NostalgiaPalette> || if (typeId == ox::ModelTypeId_v<NostalgiaPalette> ||
typeId == ox::ModelTypeId_v<PaletteV1>) { typeId == ox::ModelTypeId_v<PaletteV1>) {
return keel::convertBuffToBuff<Palette>( oxReturnError(keel::convertBuffToBuff<Palette>(
ctx, buff, ox::ClawFormat::Metal).moveTo(buff); ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
return true;
} }
return {}; return false;
}, },
}; };
} }

View File

@ -12,7 +12,7 @@
namespace keel { namespace keel {
class Context; class Context;
using PackTransform = ox::Error(*)(Context&, ox::Buffer &clawData, ox::StringView); using PackTransform = ox::Result<bool>(*)(Context&, ox::Buffer &clawData, ox::StringView);
class Context { class Context {
public: public:

View File

@ -162,11 +162,12 @@ ox::Result<ox::Buffer> convertBuffToBuff(
} }
template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal> template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal>
auto transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) noexcept -> ox::Error { ox::Result<bool> transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) noexcept {
if (typeId == ox::ModelTypeId_v<From>) { if (typeId == ox::ModelTypeId_v<From>) {
oxReturnError(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff)); oxReturnError(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff));
return true;
} }
return {}; return false;
}; };

View File

@ -102,9 +102,13 @@ ox::Result<ox::String> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept {
} }
ox::Error performPackTransforms(Context &ctx, ox::Buffer &clawData) noexcept { ox::Error performPackTransforms(Context &ctx, ox::Buffer &clawData) noexcept {
oxRequire(typeId, readAssetTypeId(clawData).to<ox::String>()); oxRequireM(typeId, readAssetTypeId(clawData));
for (auto const tr : packTransforms(ctx)) { for (auto const tr : packTransforms(ctx)) {
oxReturnError(tr(ctx, clawData, typeId)); bool changed{};
oxReturnError(tr(ctx, clawData, typeId).moveTo(changed));
if (changed) {
oxReturnError(readAssetTypeId(clawData).moveTo(typeId));
}
} }
return {}; return {};
} }