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

refactor: merge leaderboard dumpers into a single file

This commit is contained in:
Jan Laupetin
2025-07-25 22:33:40 +01:00
parent 39fe9965d1
commit ce1f0d23c9
9 changed files with 61 additions and 69 deletions

View File

@@ -0,0 +1,11 @@
#include "LeaderboardCommon.h"
#include <format>
namespace leaderboard
{
std::string GetJsonFileNameForAsset(const std::string& assetName)
{
return std::format("leaderboards/{}.json", assetName);
}
} // namespace leaderboard

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace leaderboard
{
std::string GetJsonFileNameForAsset(const std::string& assetName);
}

View File

@@ -2,6 +2,7 @@
#include "Game/IW4/IW4.h"
#include "JsonLeaderboardDefLoader.h"
#include "Leaderboard/LeaderboardCommon.h"
#include <cstring>
#include <format>
@@ -22,7 +23,7 @@ namespace
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto file = m_search_path.Open(std::format("leaderboards/{}.json", assetName));
const auto file = m_search_path.Open(leaderboard::GetJsonFileNameForAsset(assetName));
if (!file.IsOpen())
return AssetCreationResult::NoAction();

View File

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

View File

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

View File

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

View File

@@ -1,28 +1,32 @@
#include "JsonLeaderboardDefWriter.h"
#include "LeaderboardJsonDumperT6.h"
#include "Game/T6/CommonT6.h"
#include "Game/T6/Leaderboard/JsonLeaderboardDef.h"
#include "Leaderboard/LeaderboardCommon.h"
#include <format>
#include <iomanip>
#include <nlohmann/json.hpp>
#include <ranges>
using namespace nlohmann;
using namespace T6;
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;
@@ -94,11 +98,21 @@ namespace
};
} // namespace
namespace T6
namespace T6::leaderboard
{
void DumpLeaderboardDefAsJson(std::ostream& stream, const LeaderboardDef* leaderboardDef)
bool JsonDumper::ShouldDump(XAssetInfo<LeaderboardDef>* asset)
{
JsonDumper dumper(stream);
dumper.Dump(leaderboardDef);
return true;
}
} // namespace T6
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 T6::leaderboard

View File

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

View File

@@ -4,7 +4,7 @@
#include "Game/T6/GameAssetPoolT6.h"
#include "Game/T6/XModel/XModelDumperT6.h"
#include "Image/AssetDumperGfxImage.h"
#include "Leaderboard/AssetDumperLeaderboardDef.h"
#include "Leaderboard/LeaderboardJsonDumperT6.h"
#include "Localize/AssetDumperLocalizeEntry.h"
#include "Maps/AssetDumperMapEnts.h"
#include "Material/DumperMaterialT6.h"
@@ -27,7 +27,6 @@
#include "Weapon/AssetDumperWeaponCamo.h"
#include "ZBarrier/AssetDumperZBarrier.h"
using namespace T6;
bool ObjWriter::DumpZone(AssetDumpingContext& context) const
@@ -72,7 +71,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(AssetDumperXGlobals, m_xglobals, ASSET_TYPE_XGLOBALS)
// DUMP_ASSET_POOL(AssetDumperDDLRoot, m_ddl, ASSET_TYPE_DDL)
// DUMP_ASSET_POOL(AssetDumperGlasses, m_glasses, ASSET_TYPE_GLASSES)