From dbec702075b76d97c880dfb895972305f7a50345 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Sun, 27 Jul 2025 23:13:26 +0100 Subject: [PATCH] refactor: use IAssetDumper interface on implementations directly --- .../Game/T6/FontIcon/DumperFontIconCsvT6.h | 9 ---- .../Game/T6/FontIcon/DumperFontIconJsonT6.h | 9 ---- .../Game/T6/FontIcon/DumperFontIconT6.cpp | 22 ---------- ...tIconCsvT6.cpp => FontIconCsvDumperT6.cpp} | 25 ++++++----- ...mperFontIconT6.h => FontIconCsvDumperT6.h} | 6 +-- .../Game/T6/FontIcon/FontIconDumperT6.cpp | 20 +++++++++ .../Game/T6/FontIcon/FontIconDumperT6.h | 9 ++++ ...conJsonT6.cpp => FontIconJsonDumperT6.cpp} | 17 ++++--- .../Game/T6/FontIcon/FontIconJsonDumperT6.h | 14 ++++++ src/ObjWriting/Game/T6/ObjWriterT6.cpp | 10 ++++- ...6Test.cpp => FontIconJsonDumperT6Test.cpp} | 44 ++++++++++--------- .../Game/T6/Material/DumperMaterialT6Test.cpp | 1 - 12 files changed, 103 insertions(+), 83 deletions(-) delete mode 100644 src/ObjWriting/Game/T6/FontIcon/DumperFontIconCsvT6.h delete mode 100644 src/ObjWriting/Game/T6/FontIcon/DumperFontIconJsonT6.h delete mode 100644 src/ObjWriting/Game/T6/FontIcon/DumperFontIconT6.cpp rename src/ObjWriting/Game/T6/FontIcon/{DumperFontIconCsvT6.cpp => FontIconCsvDumperT6.cpp} (88%) rename src/ObjWriting/Game/T6/FontIcon/{DumperFontIconT6.h => FontIconCsvDumperT6.h} (69%) create mode 100644 src/ObjWriting/Game/T6/FontIcon/FontIconDumperT6.cpp create mode 100644 src/ObjWriting/Game/T6/FontIcon/FontIconDumperT6.h rename src/ObjWriting/Game/T6/FontIcon/{DumperFontIconJsonT6.cpp => FontIconJsonDumperT6.cpp} (88%) create mode 100644 src/ObjWriting/Game/T6/FontIcon/FontIconJsonDumperT6.h rename test/ObjWritingTests/Game/T6/FontIcon/{DumperFontIconJsonT6Test.cpp => FontIconJsonDumperT6Test.cpp} (77%) diff --git a/src/ObjWriting/Game/T6/FontIcon/DumperFontIconCsvT6.h b/src/ObjWriting/Game/T6/FontIcon/DumperFontIconCsvT6.h deleted file mode 100644 index bbdc5649..00000000 --- a/src/ObjWriting/Game/T6/FontIcon/DumperFontIconCsvT6.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "Dumping/AbstractAssetDumper.h" -#include "Game/T6/T6.h" - -namespace T6 -{ - void DumpFontIconAsCsv(const AssetDumpingContext& context, const FontIcon& fontIcon); -} diff --git a/src/ObjWriting/Game/T6/FontIcon/DumperFontIconJsonT6.h b/src/ObjWriting/Game/T6/FontIcon/DumperFontIconJsonT6.h deleted file mode 100644 index 7603e35d..00000000 --- a/src/ObjWriting/Game/T6/FontIcon/DumperFontIconJsonT6.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "Dumping/AbstractAssetDumper.h" -#include "Game/T6/T6.h" - -namespace T6 -{ - void DumpFontIconAsJson(const AssetDumpingContext& context, const FontIcon& fontIcon); -} diff --git a/src/ObjWriting/Game/T6/FontIcon/DumperFontIconT6.cpp b/src/ObjWriting/Game/T6/FontIcon/DumperFontIconT6.cpp deleted file mode 100644 index 91dc5946..00000000 --- a/src/ObjWriting/Game/T6/FontIcon/DumperFontIconT6.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "DumperFontIconT6.h" - -#include "DumperFontIconCsvT6.h" -#include "DumperFontIconJsonT6.h" - -using namespace T6; - -// #define DUMP_FONT_ICON_AS_CSV 1 - -bool AssetDumperFontIcon::ShouldDump(XAssetInfo* asset) -{ - return true; -} - -void AssetDumperFontIcon::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) -{ -#ifdef DUMP_FONT_ICON_AS_CSV - DumpFontIconAsCsv(context, *asset->Asset()); -#else - DumpFontIconAsJson(context, *asset->Asset()); -#endif -} diff --git a/src/ObjWriting/Game/T6/FontIcon/DumperFontIconCsvT6.cpp b/src/ObjWriting/Game/T6/FontIcon/FontIconCsvDumperT6.cpp similarity index 88% rename from src/ObjWriting/Game/T6/FontIcon/DumperFontIconCsvT6.cpp rename to src/ObjWriting/Game/T6/FontIcon/FontIconCsvDumperT6.cpp index a6b199ae..c8974ff1 100644 --- a/src/ObjWriting/Game/T6/FontIcon/DumperFontIconCsvT6.cpp +++ b/src/ObjWriting/Game/T6/FontIcon/FontIconCsvDumperT6.cpp @@ -1,4 +1,4 @@ -#include "DumperFontIconCsvT6.h" +#include "FontIconCsvDumperT6.h" #include "Csv/CsvStream.h" #include "Game/T6/CommonT6.h" @@ -52,15 +52,15 @@ namespace } } - class DumperFontIconCsv + class Dumper { public: - explicit DumperFontIconCsv(std::ostream& stream) + explicit Dumper(std::ostream& stream) : m_csv(stream) { } - void DumpFontIcon(const FontIcon& fontIcon) + void Dump(const FontIcon& fontIcon) { WriteFontIconEntries(fontIcon); m_csv.NextRow(); @@ -131,16 +131,21 @@ namespace }; } // namespace -namespace T6 +namespace T6::font_icon { - void DumpFontIconAsCsv(const AssetDumpingContext& context, const FontIcon& fontIcon) + bool CsvDumper::ShouldDump(XAssetInfo* asset) { - const auto assetFile = context.OpenAssetFile(fontIcon.name); + return true; + } + + void CsvDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + const auto assetFile = context.OpenAssetFile(asset->m_name); if (!assetFile) return; - DumperFontIconCsv dumperFontIconCsv(*assetFile); - dumperFontIconCsv.DumpFontIcon(fontIcon); + Dumper dumper(*assetFile); + dumper.Dump(*asset->Asset()); } -} // namespace T6 +} // namespace T6::font_icon diff --git a/src/ObjWriting/Game/T6/FontIcon/DumperFontIconT6.h b/src/ObjWriting/Game/T6/FontIcon/FontIconCsvDumperT6.h similarity index 69% rename from src/ObjWriting/Game/T6/FontIcon/DumperFontIconT6.h rename to src/ObjWriting/Game/T6/FontIcon/FontIconCsvDumperT6.h index 0581829f..7483dddf 100644 --- a/src/ObjWriting/Game/T6/FontIcon/DumperFontIconT6.h +++ b/src/ObjWriting/Game/T6/FontIcon/FontIconCsvDumperT6.h @@ -3,12 +3,12 @@ #include "Dumping/AbstractAssetDumper.h" #include "Game/T6/T6.h" -namespace T6 +namespace T6::font_icon { - class AssetDumperFontIcon final : public AbstractAssetDumper + class CsvDumper final : public AbstractAssetDumper { protected: bool ShouldDump(XAssetInfo* asset) override; void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; -} // namespace T6 +} // namespace T6::font_icon diff --git a/src/ObjWriting/Game/T6/FontIcon/FontIconDumperT6.cpp b/src/ObjWriting/Game/T6/FontIcon/FontIconDumperT6.cpp new file mode 100644 index 00000000..a3ec3322 --- /dev/null +++ b/src/ObjWriting/Game/T6/FontIcon/FontIconDumperT6.cpp @@ -0,0 +1,20 @@ +#include "FontIconDumperT6.h" + +#include "FontIconCsvDumperT6.h" +#include "FontIconJsonDumperT6.h" + +using namespace T6; + +// #define DUMP_FONT_ICON_AS_CSV 1 + +namespace T6::font_icon +{ + std::unique_ptr> CreateDumper() + { +#ifdef DUMP_FONT_ICON_AS_CSV + return std::make_unique(); +#else + return std::make_unique(); +#endif + } +} // namespace T6::font_icon diff --git a/src/ObjWriting/Game/T6/FontIcon/FontIconDumperT6.h b/src/ObjWriting/Game/T6/FontIcon/FontIconDumperT6.h new file mode 100644 index 00000000..a9e06e13 --- /dev/null +++ b/src/ObjWriting/Game/T6/FontIcon/FontIconDumperT6.h @@ -0,0 +1,9 @@ +#pragma once + +#include "Dumping/AbstractAssetDumper.h" +#include "Game/T6/T6.h" + +namespace T6::font_icon +{ + std::unique_ptr> CreateDumper(); +} // namespace T6::font_icon diff --git a/src/ObjWriting/Game/T6/FontIcon/DumperFontIconJsonT6.cpp b/src/ObjWriting/Game/T6/FontIcon/FontIconJsonDumperT6.cpp similarity index 88% rename from src/ObjWriting/Game/T6/FontIcon/DumperFontIconJsonT6.cpp rename to src/ObjWriting/Game/T6/FontIcon/FontIconJsonDumperT6.cpp index f532ebe3..cd3078f5 100644 --- a/src/ObjWriting/Game/T6/FontIcon/DumperFontIconJsonT6.cpp +++ b/src/ObjWriting/Game/T6/FontIcon/FontIconJsonDumperT6.cpp @@ -1,4 +1,4 @@ -#include "DumperFontIconJsonT6.h" +#include "FontIconJsonDumperT6.h" #include "Game/T6/CommonT6.h" #include "Game/T6/FontIcon/FontIconCommonT6.h" @@ -76,15 +76,20 @@ namespace } } // namespace -namespace T6 +namespace T6::font_icon { - void DumpFontIconAsJson(const AssetDumpingContext& context, const FontIcon& fontIcon) + bool JsonDumper::ShouldDump(XAssetInfo* asset) { - const auto assetFile = context.OpenAssetFile(font_icon::GetJsonFileNameForAssetName(fontIcon.name)); + return true; + } + + void JsonDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + const auto assetFile = context.OpenAssetFile(font_icon::GetJsonFileNameForAssetName(asset->m_name)); if (!assetFile) return; - DumpFontIcon(*assetFile, fontIcon); + DumpFontIcon(*assetFile, *asset->Asset()); } -} // namespace T6 +} // namespace T6::font_icon diff --git a/src/ObjWriting/Game/T6/FontIcon/FontIconJsonDumperT6.h b/src/ObjWriting/Game/T6/FontIcon/FontIconJsonDumperT6.h new file mode 100644 index 00000000..ade8bf33 --- /dev/null +++ b/src/ObjWriting/Game/T6/FontIcon/FontIconJsonDumperT6.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Dumping/AbstractAssetDumper.h" +#include "Game/T6/T6.h" + +namespace T6::font_icon +{ + class JsonDumper final : public AbstractAssetDumper + { + protected: + bool ShouldDump(XAssetInfo* asset) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; + }; +} // namespace T6::font_icon diff --git a/src/ObjWriting/Game/T6/ObjWriterT6.cpp b/src/ObjWriting/Game/T6/ObjWriterT6.cpp index 21c45d73..37313290 100644 --- a/src/ObjWriting/Game/T6/ObjWriterT6.cpp +++ b/src/ObjWriting/Game/T6/ObjWriterT6.cpp @@ -1,6 +1,6 @@ #include "ObjWriterT6.h" -#include "FontIcon/DumperFontIconT6.h" +#include "FontIcon/FontIconDumperT6.h" #include "Game/T6/GameAssetPoolT6.h" #include "Game/T6/XModel/XModelDumperT6.h" #include "Image/AssetDumperGfxImage.h" @@ -37,6 +37,12 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const dumperType dumper; \ dumper.DumpPool(context, assetPools->poolName.get()); \ } +#define DUMP_ASSET_POOL_WITH_FACTORY(createDumper, poolName, assetType) \ + if (assetPools->poolName && ObjWriting::ShouldHandleAssetType(assetType)) \ + { \ + const auto dumper = createDumper; \ + dumper->DumpPool(context, assetPools->poolName.get()); \ + } const auto* assetPools = dynamic_cast(context.m_zone.m_pools.get()); @@ -58,7 +64,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const // DUMP_ASSET_POOL(AssetDumperGfxWorld, m_gfx_world, ASSET_TYPE_GFXWORLD) // DUMP_ASSET_POOL(AssetDumperGfxLightDef, m_gfx_light_def, ASSET_TYPE_LIGHT_DEF) // DUMP_ASSET_POOL(AssetDumperFont, m_font, ASSET_TYPE_FONT) - DUMP_ASSET_POOL(AssetDumperFontIcon, m_font_icon, ASSET_TYPE_FONTICON) + DUMP_ASSET_POOL_WITH_FACTORY(font_icon::CreateDumper(), m_font_icon, ASSET_TYPE_FONTICON) // DUMP_ASSET_POOL(AssetDumperMenuList, m_menu_list, ASSET_TYPE_MENULIST) // DUMP_ASSET_POOL(AssetDumperMenuDef, m_menu_def, ASSET_TYPE_MENU) DUMP_ASSET_POOL(AssetDumperLocalizeEntry, m_localize, ASSET_TYPE_LOCALIZE_ENTRY) diff --git a/test/ObjWritingTests/Game/T6/FontIcon/DumperFontIconJsonT6Test.cpp b/test/ObjWritingTests/Game/T6/FontIcon/FontIconJsonDumperT6Test.cpp similarity index 77% rename from test/ObjWritingTests/Game/T6/FontIcon/DumperFontIconJsonT6Test.cpp rename to test/ObjWritingTests/Game/T6/FontIcon/FontIconJsonDumperT6Test.cpp index c8837e7b..04bf8440 100644 --- a/test/ObjWritingTests/Game/T6/FontIcon/DumperFontIconJsonT6Test.cpp +++ b/test/ObjWritingTests/Game/T6/FontIcon/FontIconJsonDumperT6Test.cpp @@ -1,4 +1,4 @@ -#include "Game/T6/FontIcon/DumperFontIconJsonT6.h" +#include "Game/T6/FontIcon/FontIconJsonDumperT6.h" #include "Asset/AssetRegistration.h" #include "Game/T6/CommonT6.h" @@ -27,14 +27,15 @@ namespace return material; } - void GivenFontIcon(const std::string& name, FontIcon& fontIcon, MemoryManager& memory) + void GivenFontIcon(const std::string& name, AssetPool& pool, MemoryManager& memory) { - fontIcon.name = memory.Dup(name.c_str()); + auto* fontIcon = memory.Alloc(); + fontIcon->name = memory.Dup(name.c_str()); - fontIcon.numEntries = 3; - fontIcon.fontIconEntry = memory.Alloc(fontIcon.numEntries); + fontIcon->numEntries = 3; + fontIcon->fontIconEntry = memory.Alloc(fontIcon->numEntries); - auto& entry0 = fontIcon.fontIconEntry[0]; + auto& entry0 = fontIcon->fontIconEntry[0]; entry0.fontIconName.string = "XenonButtondpadAll"; entry0.fontIconName.hash = Common::Com_HashString(entry0.fontIconName.string); entry0.fontIconMaterialHandle = GivenMaterial("xenonbutton_dpad_all", memory); @@ -42,7 +43,7 @@ namespace entry0.xScale = 1.0f; entry0.yScale = 1.0f; - auto& entry1 = fontIcon.fontIconEntry[1]; + auto& entry1 = fontIcon->fontIconEntry[1]; entry1.fontIconName.string = "XenonButtonLStickAnimatedD"; entry1.fontIconName.hash = Common::Com_HashString(entry1.fontIconName.string); entry1.fontIconMaterialHandle = GivenMaterial("ui_button_xenon_lstick_anim_d", memory); @@ -50,7 +51,7 @@ namespace entry1.xScale = 1.5f; entry1.yScale = 1.5f; - auto& entry2 = fontIcon.fontIconEntry[2]; + auto& entry2 = fontIcon->fontIconEntry[2]; entry2.fontIconName.string = "XenonButtonStickAnimatedL"; entry2.fontIconName.hash = Common::Com_HashString(entry2.fontIconName.string); entry2.fontIconMaterialHandle = GivenMaterial("xenonbutton_ls", memory); @@ -58,32 +59,34 @@ namespace entry2.xScale = 1.0f; entry2.yScale = 1.0f; - fontIcon.numAliasEntries = 6; - fontIcon.fontIconAlias = memory.Alloc(fontIcon.numAliasEntries); + fontIcon->numAliasEntries = 6; + fontIcon->fontIconAlias = memory.Alloc(fontIcon->numAliasEntries); - auto& alias0 = fontIcon.fontIconAlias[0]; + auto& alias0 = fontIcon->fontIconAlias[0]; alias0.aliasHash = Common::Com_HashString("BUTTON_LUI_DPAD_ALL"); alias0.buttonHash = entry0.fontIconName.hash; - auto& alias1 = fontIcon.fontIconAlias[1]; + auto& alias1 = fontIcon->fontIconAlias[1]; alias1.aliasHash = static_cast(0xCE7211DA); alias1.buttonHash = entry1.fontIconName.hash; - auto& alias2 = fontIcon.fontIconAlias[2]; + auto& alias2 = fontIcon->fontIconAlias[2]; alias2.aliasHash = Common::Com_HashString("BUTTON_MOVE"); alias2.buttonHash = entry2.fontIconName.hash; - auto& alias3 = fontIcon.fontIconAlias[3]; + auto& alias3 = fontIcon->fontIconAlias[3]; alias3.aliasHash = Common::Com_HashString("BUTTON_EMBLEM_MOVE"); alias3.buttonHash = entry2.fontIconName.hash; - auto& alias4 = fontIcon.fontIconAlias[4]; + auto& alias4 = fontIcon->fontIconAlias[4]; alias4.aliasHash = Common::Com_HashString("BUTTON_LUI_LEFT_STICK_UP"); alias4.buttonHash = entry2.fontIconName.hash; - auto& alias5 = fontIcon.fontIconAlias[5]; + auto& alias5 = fontIcon->fontIconAlias[5]; alias5.aliasHash = Common::Com_HashString("BUTTON_MOVESTICK"); alias5.buttonHash = entry2.fontIconName.hash; + + pool.AddAsset(std::make_unique>(ASSET_TYPE_FONTICON, name, fontIcon)); } TEST_CASE("DumperFontIconJson(T6): Can dump font icon", "[t6][font-icon][assetdumper]") @@ -145,12 +148,11 @@ namespace MockOutputPath mockOutput; AssetDumpingContext context(zone, "", mockOutput, mockObjPath); - AssetPoolDynamic materialPool(0); + AssetPoolDynamic fontIconPool(0); + GivenFontIcon("fonticon/test.csv", fontIconPool, memory); - FontIcon asset; - GivenFontIcon("fonticon/test.csv", asset, memory); - - DumpFontIconAsJson(context, asset); + font_icon::JsonDumper dumper; + dumper.DumpPool(context, &fontIconPool); const auto* file = mockOutput.GetMockedFile("fonticon/test.json"); REQUIRE(file); diff --git a/test/ObjWritingTests/Game/T6/Material/DumperMaterialT6Test.cpp b/test/ObjWritingTests/Game/T6/Material/DumperMaterialT6Test.cpp index 30c83ec1..2586760d 100644 --- a/test/ObjWritingTests/Game/T6/Material/DumperMaterialT6Test.cpp +++ b/test/ObjWritingTests/Game/T6/Material/DumperMaterialT6Test.cpp @@ -470,7 +470,6 @@ namespace AssetDumpingContext context(zone, "", mockOutput, mockObjPath); AssetPoolDynamic materialPool(0); - GivenMaterial("wpc/metal_ac_duct", materialPool, memory); AssetDumperMaterial dumper;