2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-08-30 21:53:15 +00:00

refactor: use IAssetDumper interface on implementations directly

This commit is contained in:
Jan Laupetin
2025-07-27 23:13:26 +01:00
parent ce1f0d23c9
commit dbec702075
12 changed files with 103 additions and 83 deletions

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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<FontIcon>* asset)
{
return true;
}
void AssetDumperFontIcon::DumpAsset(AssetDumpingContext& context, XAssetInfo<FontIcon>* asset)
{
#ifdef DUMP_FONT_ICON_AS_CSV
DumpFontIconAsCsv(context, *asset->Asset());
#else
DumpFontIconAsJson(context, *asset->Asset());
#endif
}

View File

@@ -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<FontIcon>* asset)
{
const auto assetFile = context.OpenAssetFile(fontIcon.name);
return true;
}
void CsvDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<FontIcon>* 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

View File

@@ -3,12 +3,12 @@
#include "Dumping/AbstractAssetDumper.h"
#include "Game/T6/T6.h"
namespace T6
namespace T6::font_icon
{
class AssetDumperFontIcon final : public AbstractAssetDumper<FontIcon>
class CsvDumper final : public AbstractAssetDumper<FontIcon>
{
protected:
bool ShouldDump(XAssetInfo<FontIcon>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<FontIcon>* asset) override;
};
} // namespace T6
} // namespace T6::font_icon

View File

@@ -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<IAssetDumper<FontIcon>> CreateDumper()
{
#ifdef DUMP_FONT_ICON_AS_CSV
return std::make_unique<CsvDumper>();
#else
return std::make_unique<JsonDumper>();
#endif
}
} // namespace T6::font_icon

View File

@@ -0,0 +1,9 @@
#pragma once
#include "Dumping/AbstractAssetDumper.h"
#include "Game/T6/T6.h"
namespace T6::font_icon
{
std::unique_ptr<IAssetDumper<FontIcon>> CreateDumper();
} // namespace T6::font_icon

View File

@@ -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<FontIcon>* asset)
{
const auto assetFile = context.OpenAssetFile(font_icon::GetJsonFileNameForAssetName(fontIcon.name));
return true;
}
void JsonDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<FontIcon>* 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

View File

@@ -0,0 +1,14 @@
#pragma once
#include "Dumping/AbstractAssetDumper.h"
#include "Game/T6/T6.h"
namespace T6::font_icon
{
class JsonDumper final : public AbstractAssetDumper<FontIcon>
{
protected:
bool ShouldDump(XAssetInfo<FontIcon>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<FontIcon>* asset) override;
};
} // namespace T6::font_icon

View File

@@ -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<GameAssetPoolT6*>(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)

View File

@@ -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<FontIcon>& pool, MemoryManager& memory)
{
fontIcon.name = memory.Dup(name.c_str());
auto* fontIcon = memory.Alloc<FontIcon>();
fontIcon->name = memory.Dup(name.c_str());
fontIcon.numEntries = 3;
fontIcon.fontIconEntry = memory.Alloc<FontIconEntry>(fontIcon.numEntries);
fontIcon->numEntries = 3;
fontIcon->fontIconEntry = memory.Alloc<FontIconEntry>(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<FontIconAlias>(fontIcon.numAliasEntries);
fontIcon->numAliasEntries = 6;
fontIcon->fontIconAlias = memory.Alloc<FontIconAlias>(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<int>(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<XAssetInfo<FontIcon>>(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<Material> materialPool(0);
AssetPoolDynamic<FontIcon> 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);

View File

@@ -470,7 +470,6 @@ namespace
AssetDumpingContext context(zone, "", mockOutput, mockObjPath);
AssetPoolDynamic<Material> materialPool(0);
GivenMaterial("wpc/metal_ac_duct", materialPool, memory);
AssetDumperMaterial dumper;