2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-30 16:27:47 +00:00

feat(iw5): load leaderboard definitions from raw

This commit is contained in:
2024-05-26 11:53:07 +02:00
parent d8adda81ec
commit 1d9310fb9c
4 changed files with 183 additions and 0 deletions

View File

@@ -1,10 +1,13 @@
#include "AssetLoaderLeaderboard.h"
#include "Game/IW5/IW5.h"
#include "Game/IW5/Leaderboard/JsonLeaderboardDefLoader.h"
#include "ObjLoading.h"
#include "Pool/GlobalAssetPool.h"
#include <cstring>
#include <format>
#include <iostream>
using namespace IW5;
@@ -15,3 +18,26 @@ void* AssetLoaderLeaderboard::CreateEmptyAsset(const std::string& assetName, Mem
leaderboard->name = memory->Dup(assetName.c_str());
return leaderboard;
}
bool AssetLoaderLeaderboard::CanLoadFromRaw() const
{
return true;
}
bool AssetLoaderLeaderboard::LoadFromRaw(
const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
{
const auto file = searchPath->Open(std::format("leaderboards/{}.json", assetName));
if (!file.IsOpen())
return false;
auto* leaderboardDef = memory->Alloc<LeaderboardDef>();
leaderboardDef->name = memory->Dup(assetName.c_str());
if (LoadLeaderboardAsJson(*file.m_stream, *leaderboardDef, memory))
manager->AddAsset<AssetLeaderboard>(assetName, leaderboardDef);
else
std::cerr << std::format("Failed to load leaderboard \"{}\"\n", assetName);
return true;
}

View File

@@ -10,5 +10,8 @@ namespace IW5
{
public:
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
_NODISCARD bool CanLoadFromRaw() const override;
bool
LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
};
} // namespace IW5