mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-11-23 05:12:05 +00:00
Updated Json Material loader to support passing JSON instead of a stream, and added techset loading code
This commit is contained in:
@@ -43,6 +43,7 @@
|
|||||||
#include "ZBarrier/GdtLoaderZBarrierT6.h"
|
#include "ZBarrier/GdtLoaderZBarrierT6.h"
|
||||||
#include "ZBarrier/RawLoaderZBarrierT6.h"
|
#include "ZBarrier/RawLoaderZBarrierT6.h"
|
||||||
#include "CustomMap/LoaderCustomMapT6.h"
|
#include "CustomMap/LoaderCustomMapT6.h"
|
||||||
|
#include "TechniqueSet/LoaderTechniqueSetT6.h"
|
||||||
|
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -393,7 +394,7 @@ namespace T6
|
|||||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
|
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
|
||||||
collection.AddAssetCreator(xmodel::CreateLoaderT6(memory, searchPath, zone));
|
collection.AddAssetCreator(xmodel::CreateLoaderT6(memory, searchPath, zone));
|
||||||
collection.AddAssetCreator(material::CreateLoaderT6(memory, searchPath));
|
collection.AddAssetCreator(material::CreateLoaderT6(memory, searchPath));
|
||||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory));
|
collection.AddAssetCreator(technique_set::CreateLoaderT6(memory, searchPath));
|
||||||
collection.AddAssetCreator(image::CreateLoaderT6(memory, searchPath));
|
collection.AddAssetCreator(image::CreateLoaderT6(memory, searchPath));
|
||||||
collection.AddAssetCreator(sound::CreateSoundBankLoaderT6(memory, searchPath));
|
collection.AddAssetCreator(sound::CreateSoundBankLoaderT6(memory, searchPath));
|
||||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundPatch>(memory));
|
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundPatch>(memory));
|
||||||
|
|||||||
@@ -175,10 +175,10 @@ namespace
|
|||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace T6
|
namespace technique_set
|
||||||
{
|
{
|
||||||
std::unique_ptr<AssetCreator<AssetTechniqueSet>> CreateTechniqueSetLoader(MemoryManager& memory, ISearchPath& searchPath)
|
std::unique_ptr<AssetCreator<AssetTechniqueSet>> CreateLoaderT6(MemoryManager& memory, ISearchPath& searchPath)
|
||||||
{
|
{
|
||||||
return std::make_unique<TechniqueSetLoader>(memory, searchPath);
|
return std::make_unique<TechniqueSetLoader>(memory, searchPath);
|
||||||
}
|
}
|
||||||
} // namespace T6
|
} // namespace technique_set
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace T6
|
namespace technique_set
|
||||||
{
|
{
|
||||||
std::unique_ptr<AssetCreator<AssetTechniqueSet>> CreateTechniqueSetLoader(MemoryManager& memory, ISearchPath& searchPath);
|
std::unique_ptr<AssetCreator<T6::AssetTechniqueSet>> CreateLoaderT6(MemoryManager& memory, ISearchPath& searchPath);
|
||||||
} // namespace T6
|
} // namespace technique_set
|
||||||
|
|||||||
@@ -52,19 +52,15 @@ namespace
|
|||||||
class JsonLoader
|
class JsonLoader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JsonLoader(std::istream& stream, MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetMaterial>& registration)
|
JsonLoader(MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetMaterial>& registration)
|
||||||
: m_stream(stream),
|
: m_memory(memory),
|
||||||
m_memory(memory),
|
|
||||||
m_context(context),
|
m_context(context),
|
||||||
m_registration(registration)
|
m_registration(registration)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Load(Material& material) const
|
bool Load(json& jRoot, Material& material) const
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
const auto jRoot = json::parse(m_stream);
|
|
||||||
std::string type;
|
std::string type;
|
||||||
unsigned version;
|
unsigned version;
|
||||||
|
|
||||||
@@ -90,13 +86,6 @@ namespace
|
|||||||
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:
|
||||||
static void PrintError(const Material& material, const std::string& message)
|
static void PrintError(const Material& material, const std::string& message)
|
||||||
@@ -519,7 +508,6 @@ 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;
|
||||||
@@ -531,8 +519,26 @@ 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(stream, memory, context, registration);
|
const JsonLoader loader(memory, context, registration);
|
||||||
|
|
||||||
return loader.Load(material);
|
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);
|
||||||
}
|
}
|
||||||
} // namespace GAME
|
} // namespace GAME
|
||||||
|
|||||||
Reference in New Issue
Block a user