2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-22 21:02:07 +00:00

Undo changes to JsonMaterialLoader as they are no longer needed.

This commit is contained in:
LJW-Dev
2025-11-04 14:05:19 +08:00
parent 8007bb54a0
commit b7162d6290
2 changed files with 43 additions and 55 deletions

View File

@@ -52,15 +52,19 @@ namespace
class JsonLoader
{
public:
JsonLoader(MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetMaterial>& registration)
: m_memory(memory),
JsonLoader(std::istream& stream, MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetMaterial>& registration)
: m_stream(stream),
m_memory(memory),
m_context(context),
m_registration(registration)
{
}
bool Load(json& jRoot, Material& material) const
bool Load(Material& material) const
{
try
{
const auto jRoot = json::parse(m_stream);
std::string type;
unsigned version;
@@ -86,6 +90,13 @@ namespace
const auto jMaterial = jRoot.get<JsonMaterial>();
return CreateMaterialFromJson(jMaterial, material);
}
catch (const json::exception& e)
{
con::error("Failed to parse json of material: {}", e.what());
}
return false;
}
private:
static void PrintError(const Material& material, const std::string& message)
@@ -508,6 +519,7 @@ namespace
return true;
}
std::istream& m_stream;
MemoryManager& m_memory;
AssetCreationContext& m_context;
AssetRegistration<AssetMaterial>& m_registration;
@@ -519,26 +531,8 @@ namespace GAME
bool LoadMaterialAsJson(
std::istream& stream, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetMaterial>& registration)
{
const JsonLoader loader(memory, context, registration);
const JsonLoader loader(stream, memory, context, registration);
try
{
auto jRoot = json::parse(stream);
return loader.Load(jRoot, material);
}
catch (const json::exception& e)
{
con::error("Failed to parse json of material: {}", e.what());
return false;
}
}
bool LoadMaterialAsJson(
json& json, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetMaterial>& registration)
{
const JsonLoader loader(memory, context, registration);
return loader.Load(json, material);
return loader.Load(material);
}
} // namespace GAME

View File

@@ -15,15 +15,9 @@
#include "Utils/MemoryManager.h"
#include <istream>
#include <nlohmann/json.hpp>
using namespace nlohmann;
namespace GAME
{
bool LoadMaterialAsJson(
std::istream& stream, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetMaterial>& registration);
bool LoadMaterialAsJson(
json& json, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetMaterial>& registration);
} // namespace GAME