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:
@@ -52,39 +52,50 @@ namespace
|
|||||||
class JsonLoader
|
class JsonLoader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JsonLoader(MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetMaterial>& registration)
|
JsonLoader(std::istream& stream, MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetMaterial>& registration)
|
||||||
: m_memory(memory),
|
: m_stream(stream),
|
||||||
|
m_memory(memory),
|
||||||
m_context(context),
|
m_context(context),
|
||||||
m_registration(registration)
|
m_registration(registration)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Load(json& jRoot, Material& material) const
|
bool Load(Material& material) const
|
||||||
{
|
{
|
||||||
std::string type;
|
try
|
||||||
unsigned version;
|
{
|
||||||
|
const auto jRoot = json::parse(m_stream);
|
||||||
jRoot.at("_type").get_to(type);
|
std::string type;
|
||||||
jRoot.at("_version").get_to(version);
|
unsigned version;
|
||||||
|
|
||||||
if (type != "material" || version != 1u)
|
jRoot.at("_type").get_to(type);
|
||||||
{
|
jRoot.at("_version").get_to(version);
|
||||||
con::error("Tried to load material \"{}\" but did not find expected type material of version 1", material.info.name);
|
|
||||||
return false;
|
if (type != "material" || version != 1u)
|
||||||
}
|
{
|
||||||
|
con::error("Tried to load material \"{}\" but did not find expected type material of version 1", material.info.name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef FEATURE_T6 // T6 did not have this check in version 1, so to stay backwards compatible, let it stay that way
|
#ifndef FEATURE_T6 // T6 did not have this check in version 1, so to stay backwards compatible, let it stay that way
|
||||||
std::string game;
|
std::string game;
|
||||||
jRoot.at("_game").get_to(game);
|
jRoot.at("_game").get_to(game);
|
||||||
if (game != GAME_LOWER)
|
if (game != GAME_LOWER)
|
||||||
{
|
{
|
||||||
con::error("Tried to load material \"{}\" but \"_game\" did not find expected type value {}", material.info.name, GAME_LOWER);
|
con::error("Tried to load material \"{}\" but \"_game\" did not find expected type value {}", material.info.name, GAME_LOWER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const auto jMaterial = jRoot.get<JsonMaterial>();
|
const auto jMaterial = jRoot.get<JsonMaterial>();
|
||||||
return CreateMaterialFromJson(jMaterial, material);
|
return CreateMaterialFromJson(jMaterial, material);
|
||||||
|
}
|
||||||
|
catch (const json::exception& e)
|
||||||
|
{
|
||||||
|
con::error("Failed to parse json of material: {}", e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -508,6 +519,7 @@ namespace
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::istream& m_stream;
|
||||||
MemoryManager& m_memory;
|
MemoryManager& m_memory;
|
||||||
AssetCreationContext& m_context;
|
AssetCreationContext& m_context;
|
||||||
AssetRegistration<AssetMaterial>& m_registration;
|
AssetRegistration<AssetMaterial>& m_registration;
|
||||||
@@ -517,28 +529,10 @@ namespace
|
|||||||
namespace GAME
|
namespace GAME
|
||||||
{
|
{
|
||||||
bool LoadMaterialAsJson(
|
bool LoadMaterialAsJson(
|
||||||
std::istream& stream, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetMaterial>& registration)
|
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
|
return loader.Load(material);
|
||||||
{
|
}
|
||||||
auto jRoot = json::parse(stream);
|
} // namespace GAME
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
} // namespace GAME
|
|
||||||
@@ -15,15 +15,9 @@
|
|||||||
#include "Utils/MemoryManager.h"
|
#include "Utils/MemoryManager.h"
|
||||||
|
|
||||||
#include <istream>
|
#include <istream>
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
using namespace nlohmann;
|
|
||||||
|
|
||||||
namespace GAME
|
namespace GAME
|
||||||
{
|
{
|
||||||
bool LoadMaterialAsJson(
|
bool LoadMaterialAsJson(
|
||||||
std::istream& stream, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetMaterial>& registration);
|
std::istream& stream, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetMaterial>& registration);
|
||||||
|
} // namespace GAME
|
||||||
bool LoadMaterialAsJson(
|
|
||||||
json& json, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetMaterial>& registration);
|
|
||||||
} // namespace GAME
|
|
||||||
Reference in New Issue
Block a user