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

chore: fix loading and writing code for IW5

This commit is contained in:
Jan
2024-12-28 21:12:24 +01:00
parent 9ae5aaa1db
commit a36581b06e
128 changed files with 1554 additions and 2535 deletions

View File

@@ -122,9 +122,9 @@ namespace
namespace IW5
{
bool LoadLeaderboardAsJson(std::istream& stream, LeaderboardDef& leaderboard, MemoryManager* memory)
bool LoadLeaderboardAsJson(std::istream& stream, LeaderboardDef& leaderboard, MemoryManager& memory)
{
const JsonLoader loader(stream, *memory);
const JsonLoader loader(stream, memory);
return loader.Load(leaderboard);
}

View File

@@ -7,5 +7,5 @@
namespace IW5
{
bool LoadLeaderboardAsJson(std::istream& stream, LeaderboardDef& leaderboard, MemoryManager* memory);
bool LoadLeaderboardAsJson(std::istream& stream, LeaderboardDef& leaderboard, MemoryManager& memory);
} // namespace IW5

View File

@@ -0,0 +1,53 @@
#include "LoaderLeaderboardIW5.h"
#include "Game/IW5/IW5.h"
#include "JsonLeaderboardDefLoader.h"
#include <cstring>
#include <format>
#include <iostream>
using namespace IW5;
namespace
{
class LeaderboardLoader final : public AssetCreator<AssetLeaderboard>
{
public:
LeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath)
: m_memory(memory),
m_search_path(searchPath)
{
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto file = m_search_path.Open(std::format("leaderboards/{}.json", assetName));
if (!file.IsOpen())
return AssetCreationResult::NoAction();
auto* leaderboardDef = m_memory.Alloc<LeaderboardDef>();
leaderboardDef->name = m_memory.Dup(assetName.c_str());
if (!LoadLeaderboardAsJson(*file.m_stream, *leaderboardDef, m_memory))
{
std::cerr << std::format("Failed to load leaderboard \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
return AssetCreationResult::Success(context.AddAsset<AssetLeaderboard>(assetName, leaderboardDef));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace IW5
{
std::unique_ptr<AssetCreator<AssetLeaderboard>> CreateLeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<LeaderboardLoader>(memory, searchPath);
}
} // namespace IW5

View File

@@ -0,0 +1,13 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/IW5/IW5.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace IW5
{
std::unique_ptr<AssetCreator<AssetLeaderboard>> CreateLeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW5