mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-01-11 11:11:50 +00:00
chore: generalize IAssetDumper interface
This commit is contained in:
@@ -62,7 +62,8 @@ namespace
|
||||
|
||||
namespace image
|
||||
{
|
||||
DumperIW3::DumperIW3()
|
||||
DumperIW3::DumperIW3(const AssetPool<AssetImage::Type>& pool)
|
||||
: AbstractAssetDumper(pool)
|
||||
{
|
||||
switch (ObjWriting::Configuration.ImageOutputFormat)
|
||||
{
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
|
||||
namespace image
|
||||
{
|
||||
class DumperIW3 final : public AbstractAssetDumper<IW3::GfxImage>
|
||||
class DumperIW3 final : public AbstractAssetDumper<IW3::AssetImage>
|
||||
{
|
||||
public:
|
||||
DumperIW3();
|
||||
explicit DumperIW3(const AssetPool<IW3::AssetImage::Type>& pool);
|
||||
|
||||
protected:
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW3::GfxImage>& asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW3::AssetImage::Type>& asset) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IImageWriter> m_writer;
|
||||
|
||||
@@ -11,14 +11,19 @@ using namespace IW3;
|
||||
|
||||
namespace localize
|
||||
{
|
||||
size_t DumperIW3::GetProgressTotalCount(const AssetPool<IW3::LocalizeEntry>& pool) const
|
||||
DumperIW3::DumperIW3(const AssetPool<IW3::AssetLocalize::Type>& pool)
|
||||
: AbstractSingleProgressAssetDumper(pool)
|
||||
{
|
||||
return pool.m_asset_lookup.empty() ? 0uz : 1uz;
|
||||
}
|
||||
|
||||
void DumperIW3::DumpPool(AssetDumpingContext& context, const AssetPool<LocalizeEntry>& pool)
|
||||
size_t DumperIW3::GetProgressTotalCount() const
|
||||
{
|
||||
if (pool.m_asset_lookup.empty())
|
||||
return m_pool.m_asset_lookup.empty() ? 0uz : 1uz;
|
||||
}
|
||||
|
||||
void DumperIW3::Dump(AssetDumpingContext& context)
|
||||
{
|
||||
if (m_pool.m_asset_lookup.empty())
|
||||
return;
|
||||
|
||||
const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone.m_language);
|
||||
@@ -35,7 +40,7 @@ namespace localize
|
||||
|
||||
stringFileDumper.SetNotes("");
|
||||
|
||||
for (const auto* localizeEntry : pool)
|
||||
for (const auto* localizeEntry : m_pool)
|
||||
{
|
||||
stringFileDumper.WriteLocalizeEntry(localizeEntry->m_name, localizeEntry->Asset()->value);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,16 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Pool/AssetPool.h"
|
||||
|
||||
namespace localize
|
||||
{
|
||||
class DumperIW3 final : public IAssetDumper<IW3::LocalizeEntry>
|
||||
class DumperIW3 final : public AbstractSingleProgressAssetDumper<IW3::AssetLocalize>
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] size_t GetProgressTotalCount(const AssetPool<IW3::LocalizeEntry>& pool) const override;
|
||||
void DumpPool(AssetDumpingContext& context, const AssetPool<IW3::LocalizeEntry>& pool) override;
|
||||
explicit DumperIW3(const AssetPool<IW3::AssetLocalize::Type>& pool);
|
||||
|
||||
[[nodiscard]] size_t GetProgressTotalCount() const override;
|
||||
void Dump(AssetDumpingContext& context) override;
|
||||
};
|
||||
} // namespace localize
|
||||
|
||||
@@ -4,6 +4,11 @@ using namespace IW3;
|
||||
|
||||
namespace map_ents
|
||||
{
|
||||
DumperIW3::DumperIW3(const AssetPool<IW3::AssetMapEnts::Type>& pool)
|
||||
: AbstractAssetDumper(pool)
|
||||
{
|
||||
}
|
||||
|
||||
void DumperIW3::DumpAsset(AssetDumpingContext& context, const XAssetInfo<MapEnts>& asset)
|
||||
{
|
||||
const auto* mapEnts = asset.Asset();
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
|
||||
namespace map_ents
|
||||
{
|
||||
class DumperIW3 final : public AbstractAssetDumper<IW3::MapEnts>
|
||||
class DumperIW3 final : public AbstractAssetDumper<IW3::AssetMapEnts>
|
||||
{
|
||||
public:
|
||||
explicit DumperIW3(const AssetPool<IW3::AssetMapEnts::Type>& pool);
|
||||
|
||||
protected:
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW3::MapEnts>& asset) override;
|
||||
};
|
||||
|
||||
@@ -15,56 +15,55 @@ using namespace IW3;
|
||||
|
||||
bool ObjWriter::DumpZone(AssetDumpingContext& context) const
|
||||
{
|
||||
#define DUMP_ASSET_POOL(dumperType, poolName, assetType) \
|
||||
if (assetPools->poolName && ObjWriting::ShouldHandleAssetType(assetType)) \
|
||||
#define REGISTER_DUMPER(dumperType, poolName) \
|
||||
if (assetPools->poolName && ObjWriting::ShouldHandleAssetType(dumperType::AssetType_t::EnumEntry)) \
|
||||
{ \
|
||||
dumperType dumper; \
|
||||
totalProgress += dumper.GetProgressTotalCount(*assetPools->poolName); \
|
||||
dumpingFunctions.emplace_back( \
|
||||
[](AssetDumpingContext& funcContext, const GameAssetPoolIW3* funcPools) \
|
||||
{ \
|
||||
dumperType dumper; \
|
||||
dumper.DumpPool(funcContext, *funcPools->poolName); \
|
||||
}); \
|
||||
dumpers.emplace_back(std::make_unique<dumperType>(*assetPools->poolName)); \
|
||||
}
|
||||
|
||||
const auto* assetPools = dynamic_cast<GameAssetPoolIW3*>(context.m_zone.m_pools.get());
|
||||
std::vector<std::unique_ptr<IAssetDumper>> dumpers;
|
||||
|
||||
size_t totalProgress = 0uz;
|
||||
std::vector<std::function<void(AssetDumpingContext & context, const GameAssetPoolIW3*)>> dumpingFunctions;
|
||||
// REGISTER_DUMPER(AssetDumperPhysPreset, m_phys_preset)
|
||||
// REGISTER_DUMPER(AssetDumperXAnimParts, m_xanim_parts)
|
||||
REGISTER_DUMPER(xmodel::DumperIW3, m_xmodel)
|
||||
REGISTER_DUMPER(material::JsonDumperIW3, m_material)
|
||||
// REGISTER_DUMPER(AssetDumperMaterialTechniqueSet, m_technique_set)
|
||||
REGISTER_DUMPER(image::DumperIW3, m_image)
|
||||
// REGISTER_DUMPER(AssetDumpersnd_alias_list_t, m_sound)
|
||||
// REGISTER_DUMPER(AssetDumperSndCurve, m_sound_curve)
|
||||
REGISTER_DUMPER(sound::LoadedSoundDumperIW3, m_loaded_sound)
|
||||
// REGISTER_DUMPER(AssetDumperClipMap, m_clip_map)
|
||||
// REGISTER_DUMPER(AssetDumperComWorld, m_com_world)
|
||||
// REGISTER_DUMPER(AssetDumperGameWorldSp, m_game_world_sp)
|
||||
// REGISTER_DUMPER(AssetDumperGameWorldMp, m_game_world_mp)
|
||||
REGISTER_DUMPER(map_ents::DumperIW3, m_map_ents)
|
||||
// REGISTER_DUMPER(AssetDumperGfxWorld, m_gfx_world)
|
||||
// REGISTER_DUMPER(AssetDumperGfxLightDef, m_gfx_light_def)
|
||||
// REGISTER_DUMPER(AssetDumperFont_s, m_font)
|
||||
// REGISTER_DUMPER(AssetDumperMenuList, m_menu_list)
|
||||
// REGISTER_DUMPER(AssetDumpermenuDef_t, m_menu_def)
|
||||
REGISTER_DUMPER(localize::DumperIW3, m_localize)
|
||||
// REGISTER_DUMPER(AssetDumperWeapon, m_weapon)
|
||||
// REGISTER_DUMPER(AssetDumperSndDriverGlobals, m_snd_driver_globals)
|
||||
// REGISTER_DUMPER(AssetDumperFxEffectDef, m_fx)
|
||||
// REGISTER_DUMPER(AssetDumperFxImpactTable, m_fx_impact_table)
|
||||
REGISTER_DUMPER(raw_file::DumperIW3, m_raw_file)
|
||||
REGISTER_DUMPER(string_table::DumperIW3, m_string_table)
|
||||
|
||||
// DUMP_ASSET_POOL(AssetDumperPhysPreset, m_phys_preset, ASSET_TYPE_PHYSPRESET)
|
||||
// DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS)
|
||||
DUMP_ASSET_POOL(xmodel::DumperIW3, m_xmodel, ASSET_TYPE_XMODEL)
|
||||
DUMP_ASSET_POOL(material::JsonDumperIW3, m_material, ASSET_TYPE_MATERIAL)
|
||||
// DUMP_ASSET_POOL(AssetDumperMaterialTechniqueSet, m_technique_set, ASSET_TYPE_TECHNIQUE_SET)
|
||||
DUMP_ASSET_POOL(image::DumperIW3, m_image, ASSET_TYPE_IMAGE)
|
||||
// DUMP_ASSET_POOL(AssetDumpersnd_alias_list_t, m_sound, ASSET_TYPE_SOUND)
|
||||
// DUMP_ASSET_POOL(AssetDumperSndCurve, m_sound_curve, ASSET_TYPE_SOUND_CURVE)
|
||||
DUMP_ASSET_POOL(sound::LoadedSoundDumperIW3, m_loaded_sound, ASSET_TYPE_LOADED_SOUND)
|
||||
// DUMP_ASSET_POOL(AssetDumperClipMap, m_clip_map, ASSET_TYPE_CLIPMAP_PVS)
|
||||
// DUMP_ASSET_POOL(AssetDumperComWorld, m_com_world, ASSET_TYPE_COMWORLD)
|
||||
// DUMP_ASSET_POOL(AssetDumperGameWorldSp, m_game_world_sp, ASSET_TYPE_GAMEWORLD_SP)
|
||||
// DUMP_ASSET_POOL(AssetDumperGameWorldMp, m_game_world_mp, ASSET_TYPE_GAMEWORLD_MP)
|
||||
DUMP_ASSET_POOL(map_ents::DumperIW3, m_map_ents, ASSET_TYPE_MAP_ENTS)
|
||||
// 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_s, m_font, ASSET_TYPE_FONT)
|
||||
// DUMP_ASSET_POOL(AssetDumperMenuList, m_menu_list, ASSET_TYPE_MENULIST)
|
||||
// DUMP_ASSET_POOL(AssetDumpermenuDef_t, m_menu_def, ASSET_TYPE_MENU)
|
||||
DUMP_ASSET_POOL(localize::DumperIW3, m_localize, ASSET_TYPE_LOCALIZE_ENTRY)
|
||||
// DUMP_ASSET_POOL(AssetDumperWeapon, m_weapon, ASSET_TYPE_WEAPON)
|
||||
// DUMP_ASSET_POOL(AssetDumperSndDriverGlobals, m_snd_driver_globals, ASSET_TYPE_SNDDRIVER_GLOBALS)
|
||||
// DUMP_ASSET_POOL(AssetDumperFxEffectDef, m_fx, ASSET_TYPE_FX)
|
||||
// DUMP_ASSET_POOL(AssetDumperFxImpactTable, m_fx_impact_table, ASSET_TYPE_IMPACT_FX)
|
||||
DUMP_ASSET_POOL(raw_file::DumperIW3, m_raw_file, ASSET_TYPE_RAWFILE)
|
||||
DUMP_ASSET_POOL(string_table::DumperIW3, m_string_table, ASSET_TYPE_STRINGTABLE)
|
||||
if (context.ShouldTrackProgress())
|
||||
{
|
||||
size_t totalProgress = 0uz;
|
||||
for (const auto& dumper : dumpers)
|
||||
totalProgress += dumper->GetProgressTotalCount();
|
||||
|
||||
context.SetTotalProgress(totalProgress);
|
||||
for (const auto& func : dumpingFunctions)
|
||||
func(context, assetPools);
|
||||
context.SetTotalProgress(totalProgress);
|
||||
}
|
||||
|
||||
for (const auto& dumper : dumpers)
|
||||
dumper->Dump(context);
|
||||
|
||||
return true;
|
||||
|
||||
#undef DUMP_ASSET_POOL
|
||||
#undef REGISTER_DUMPER
|
||||
}
|
||||
|
||||
@@ -4,6 +4,11 @@ using namespace IW3;
|
||||
|
||||
namespace raw_file
|
||||
{
|
||||
DumperIW3::DumperIW3(const AssetPool<AssetRawFile::Type>& pool)
|
||||
: AbstractAssetDumper(pool)
|
||||
{
|
||||
}
|
||||
|
||||
void DumperIW3::DumpAsset(AssetDumpingContext& context, const XAssetInfo<RawFile>& asset)
|
||||
{
|
||||
const auto* rawFile = asset.Asset();
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
|
||||
namespace raw_file
|
||||
{
|
||||
class DumperIW3 final : public AbstractAssetDumper<IW3::RawFile>
|
||||
class DumperIW3 final : public AbstractAssetDumper<IW3::AssetRawFile>
|
||||
{
|
||||
public:
|
||||
explicit DumperIW3(const AssetPool<IW3::AssetRawFile::Type>& pool);
|
||||
|
||||
protected:
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW3::RawFile>& asset) override;
|
||||
};
|
||||
|
||||
@@ -25,6 +25,11 @@ namespace
|
||||
|
||||
namespace sound
|
||||
{
|
||||
LoadedSoundDumperIW3::LoadedSoundDumperIW3(const AssetPool<AssetLoadedSound::Type>& pool)
|
||||
: AbstractAssetDumper(pool)
|
||||
{
|
||||
}
|
||||
|
||||
void LoadedSoundDumperIW3::DumpAsset(AssetDumpingContext& context, const XAssetInfo<LoadedSound>& asset)
|
||||
{
|
||||
const auto* loadedSound = asset.Asset();
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
|
||||
namespace sound
|
||||
{
|
||||
class LoadedSoundDumperIW3 final : public AbstractAssetDumper<IW3::LoadedSound>
|
||||
class LoadedSoundDumperIW3 final : public AbstractAssetDumper<IW3::AssetLoadedSound>
|
||||
{
|
||||
public:
|
||||
explicit LoadedSoundDumperIW3(const AssetPool<IW3::AssetLoadedSound::Type>& pool);
|
||||
|
||||
protected:
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW3::LoadedSound>& asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW3::AssetLoadedSound::Type>& asset) override;
|
||||
};
|
||||
} // namespace sound
|
||||
|
||||
@@ -6,6 +6,11 @@ using namespace IW3;
|
||||
|
||||
namespace string_table
|
||||
{
|
||||
DumperIW3::DumperIW3(const AssetPool<AssetStringTable::Type>& pool)
|
||||
: AbstractAssetDumper(pool)
|
||||
{
|
||||
}
|
||||
|
||||
void DumperIW3::DumpAsset(AssetDumpingContext& context, const XAssetInfo<StringTable>& asset)
|
||||
{
|
||||
const auto* stringTable = asset.Asset();
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
|
||||
namespace string_table
|
||||
{
|
||||
class DumperIW3 final : public AbstractAssetDumper<IW3::StringTable>
|
||||
class DumperIW3 final : public AbstractAssetDumper<IW3::AssetStringTable>
|
||||
{
|
||||
public:
|
||||
explicit DumperIW3(const AssetPool<IW3::AssetStringTable::Type>& pool);
|
||||
|
||||
protected:
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW3::StringTable>& asset) override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user