mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-12-08 12:17:48 +00:00
chore: fix loading and writing code for T6
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
#include "JsonLeaderboardDefLoader.h"
|
||||
|
||||
#include "Game/T6/CommonT6.h"
|
||||
@@ -129,9 +128,9 @@ namespace
|
||||
|
||||
namespace T6
|
||||
{
|
||||
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);
|
||||
}
|
||||
} // namespace T6
|
||||
|
||||
@@ -7,5 +7,5 @@
|
||||
|
||||
namespace T6
|
||||
{
|
||||
bool LoadLeaderboardAsJson(std::istream& stream, LeaderboardDef& leaderboard, MemoryManager* memory);
|
||||
bool LoadLeaderboardAsJson(std::istream& stream, LeaderboardDef& leaderboard, MemoryManager& memory);
|
||||
} // namespace T6
|
||||
|
||||
54
src/ObjLoading/Game/T6/Leaderboard/LoaderLeaderboardT6.cpp
Normal file
54
src/ObjLoading/Game/T6/Leaderboard/LoaderLeaderboardT6.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "LoaderLeaderboardT6.h"
|
||||
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "JsonLeaderboardDefLoader.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace T6;
|
||||
|
||||
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 T6
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetLeaderboard>> CreateLeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath)
|
||||
{
|
||||
return std::make_unique<LeaderboardLoader>(memory, searchPath);
|
||||
}
|
||||
} // namespace T6
|
||||
13
src/ObjLoading/Game/T6/Leaderboard/LoaderLeaderboardT6.h
Normal file
13
src/ObjLoading/Game/T6/Leaderboard/LoaderLeaderboardT6.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace T6
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetLeaderboard>> CreateLeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath);
|
||||
} // namespace T6
|
||||
Reference in New Issue
Block a user