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

refactor: merge leaderboard dumpers for iw4,iw5

This commit is contained in:
Jan Laupetin
2025-07-28 19:48:36 +01:00
parent dbec702075
commit 5fefdef0a6
13 changed files with 77 additions and 123 deletions

View File

@@ -1,24 +0,0 @@
#include "AssetDumperLeaderboardDef.h"
#include "Game/IW4/Leaderboard/JsonLeaderboardDefWriter.h"
#include <format>
#include <ranges>
using namespace IW4;
bool AssetDumperLeaderboardDef::ShouldDump(XAssetInfo<LeaderboardDef>* asset)
{
return true;
}
void AssetDumperLeaderboardDef::DumpAsset(AssetDumpingContext& context, XAssetInfo<LeaderboardDef>* asset)
{
const auto assetName = asset->m_name;
const auto assetFile = context.OpenAssetFile(std::format("leaderboards/{}.json", assetName));
if (!assetFile)
return;
DumpLeaderboardDefAsJson(*assetFile, asset->Asset());
}

View File

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

View File

@@ -1,11 +0,0 @@
#pragma once
#include "Dumping/AssetDumpingContext.h"
#include "Game/IW4/IW4.h"
#include <ostream>
namespace IW4
{
void DumpLeaderboardDefAsJson(std::ostream& stream, const LeaderboardDef* leaderboardDef);
} // namespace IW4

View File

@@ -1,28 +1,30 @@
#include "JsonLeaderboardDefWriter.h"
#include "LeaderboardJsonDumperIW4.h"
#include "Game/IW4/CommonIW4.h"
#include "Game/IW4/Leaderboard/JsonLeaderboardDef.h"
#include "Leaderboard/LeaderboardCommon.h"
#include <iomanip>
#include <nlohmann/json.hpp>
using namespace nlohmann;
using namespace IW4;
using namespace ::leaderboard;
namespace
{
class JsonDumper
class Dumper
{
public:
explicit JsonDumper(std::ostream& stream)
explicit Dumper(std::ostream& stream)
: m_stream(stream)
{
}
void Dump(const LeaderboardDef* leaderboardDef) const
void Dump(const LeaderboardDef& leaderboardDef) const
{
JsonLeaderboardDef jsonLeaderboardDef;
CreateJsonLeaderboardDef(jsonLeaderboardDef, *leaderboardDef);
CreateJsonLeaderboardDef(jsonLeaderboardDef, leaderboardDef);
json jRoot = jsonLeaderboardDef;
@@ -74,11 +76,21 @@ namespace
};
} // namespace
namespace IW4
namespace IW4::leaderboard
{
void DumpLeaderboardDefAsJson(std::ostream& stream, const LeaderboardDef* leaderboardDef)
bool JsonDumper::ShouldDump(XAssetInfo<LeaderboardDef>* asset)
{
JsonDumper dumper(stream);
dumper.Dump(leaderboardDef);
return true;
}
} // namespace IW4
void JsonDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<LeaderboardDef>* asset)
{
const auto assetFile = context.OpenAssetFile(GetJsonFileNameForAsset(asset->m_name));
if (!assetFile)
return;
Dumper dumper(*assetFile);
dumper.Dump(*asset->Asset());
}
} // namespace IW4::leaderboard

View File

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

View File

@@ -3,7 +3,7 @@
#include "Game/IW4/GameAssetPoolIW4.h"
#include "Game/IW4/XModel/XModelDumperIW4.h"
#include "Image/AssetDumperGfxImage.h"
#include "Leaderboard/AssetDumperLeaderboardDef.h"
#include "Leaderboard/LeaderboardJsonDumperIW4.h"
#include "LightDef/AssetDumperGfxLightDef.h"
#include "Localize/AssetDumperLocalizeEntry.h"
#include "Maps/AssetDumperAddonMapEnts.h"
@@ -68,7 +68,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
// DUMP_ASSET_POOL(AssetDumperFxImpactTable, m_fx_impact_table, ASSET_TYPE_IMPACT_FX)
DUMP_ASSET_POOL(AssetDumperRawFile, m_raw_file, ASSET_TYPE_RAWFILE)
DUMP_ASSET_POOL(AssetDumperStringTable, m_string_table, ASSET_TYPE_STRINGTABLE)
DUMP_ASSET_POOL(AssetDumperLeaderboardDef, m_leaderboard, ASSET_TYPE_LEADERBOARD)
DUMP_ASSET_POOL(leaderboard::JsonDumper, m_leaderboard, ASSET_TYPE_LEADERBOARD)
DUMP_ASSET_POOL(AssetDumperStructuredDataDefSet, m_structed_data_def_set, ASSET_TYPE_STRUCTURED_DATA_DEF)
DUMP_ASSET_POOL(AssetDumperTracer, m_tracer, ASSET_TYPE_TRACER)
DUMP_ASSET_POOL(AssetDumperVehicle, m_vehicle, ASSET_TYPE_VEHICLE)

View File

@@ -1,24 +0,0 @@
#include "AssetDumperLeaderboardDef.h"
#include "Game/IW5/Leaderboard/JsonLeaderboardDefWriter.h"
#include <format>
#include <ranges>
using namespace IW5;
bool AssetDumperLeaderboardDef::ShouldDump(XAssetInfo<LeaderboardDef>* asset)
{
return true;
}
void AssetDumperLeaderboardDef::DumpAsset(AssetDumpingContext& context, XAssetInfo<LeaderboardDef>* asset)
{
const auto assetName = asset->m_name;
const auto assetFile = context.OpenAssetFile(std::format("leaderboards/{}.json", assetName));
if (!assetFile)
return;
DumpLeaderboardDefAsJson(*assetFile, asset->Asset());
}

View File

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

View File

@@ -1,11 +0,0 @@
#pragma once
#include "Dumping/AssetDumpingContext.h"
#include "Game/IW5/IW5.h"
#include <ostream>
namespace IW5
{
void DumpLeaderboardDefAsJson(std::ostream& stream, const LeaderboardDef* leaderboardDef);
} // namespace IW5

View File

@@ -1,28 +1,31 @@
#include "JsonLeaderboardDefWriter.h"
#include "LeaderboardJsonDumperIW5.h"
#include "Game/IW5/CommonIW5.h"
#include "Game/IW5/Leaderboard/JsonLeaderboardDef.h"
#include "Leaderboard/LeaderboardCommon.h"
#include <iomanip>
#include <nlohmann/json.hpp>
#include <ranges>
using namespace nlohmann;
using namespace IW5;
using namespace ::leaderboard;
namespace
{
class JsonDumper
class Dumper
{
public:
explicit JsonDumper(std::ostream& stream)
explicit Dumper(std::ostream& stream)
: m_stream(stream)
{
}
void Dump(const LeaderboardDef* leaderboardDef) const
void Dump(const LeaderboardDef& leaderboardDef) const
{
JsonLeaderboardDef jsonLeaderboardDef;
CreateJsonLeaderboardDef(jsonLeaderboardDef, *leaderboardDef);
CreateJsonLeaderboardDef(jsonLeaderboardDef, leaderboardDef);
json jRoot = jsonLeaderboardDef;
@@ -90,11 +93,21 @@ namespace
};
} // namespace
namespace IW5
namespace IW5::leaderboard
{
void DumpLeaderboardDefAsJson(std::ostream& stream, const LeaderboardDef* leaderboardDef)
bool JsonDumper::ShouldDump(XAssetInfo<LeaderboardDef>* asset)
{
JsonDumper dumper(stream);
dumper.Dump(leaderboardDef);
return true;
}
} // namespace IW5
void JsonDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<LeaderboardDef>* asset)
{
const auto assetFile = context.OpenAssetFile(GetJsonFileNameForAsset(asset->m_name));
if (!assetFile)
return;
Dumper dumper(*assetFile);
dumper.Dump(*asset->Asset());
}
} // namespace IW5::leaderboard

View File

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

View File

@@ -3,7 +3,7 @@
#include "Game/IW5/GameAssetPoolIW5.h"
#include "Game/IW5/XModel/XModelDumperIW5.h"
#include "Image/AssetDumperGfxImage.h"
#include "Leaderboard/AssetDumperLeaderboardDef.h"
#include "Leaderboard/LeaderboardJsonDumperIW5.h"
#include "Localize/AssetDumperLocalizeEntry.h"
#include "Maps/AssetDumperAddonMapEnts.h"
#include "Material/DumperMaterialIW5.h"
@@ -64,7 +64,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
DUMP_ASSET_POOL(AssetDumperRawFile, m_raw_file, ASSET_TYPE_RAWFILE)
DUMP_ASSET_POOL(AssetDumperScriptFile, m_script_file, ASSET_TYPE_SCRIPTFILE)
DUMP_ASSET_POOL(AssetDumperStringTable, m_string_table, ASSET_TYPE_STRINGTABLE)
DUMP_ASSET_POOL(AssetDumperLeaderboardDef, m_leaderboard, ASSET_TYPE_LEADERBOARD)
DUMP_ASSET_POOL(leaderboard::JsonDumper, m_leaderboard, ASSET_TYPE_LEADERBOARD)
// DUMP_ASSET_POOL(AssetDumperStructuredDataDefSet, m_structed_data_def_set, ASSET_TYPE_STRUCTURED_DATA_DEF)
// DUMP_ASSET_POOL(AssetDumperTracerDef, m_tracer, ASSET_TYPE_TRACER)
// DUMP_ASSET_POOL(AssetDumperVehicleDef, m_vehicle, ASSET_TYPE_VEHICLE)

View File

@@ -4,7 +4,6 @@
#include "Game/T6/Leaderboard/JsonLeaderboardDef.h"
#include "Leaderboard/LeaderboardCommon.h"
#include <format>
#include <iomanip>
#include <nlohmann/json.hpp>
#include <ranges>