2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-10-28 17:16:56 +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