From b7162d6290ad532f1d20ed830f7016206110cac5 Mon Sep 17 00:00:00 2001 From: LJW-Dev Date: Tue, 4 Nov 2025 14:05:19 +0800 Subject: [PATCH] Undo changes to JsonMaterialLoader as they are no longer needed. --- .../Material/JsonMaterialLoader.cpp.template | 90 +++++++++---------- .../Material/JsonMaterialLoader.h.template | 8 +- 2 files changed, 43 insertions(+), 55 deletions(-) diff --git a/src/ObjLoading/Material/JsonMaterialLoader.cpp.template b/src/ObjLoading/Material/JsonMaterialLoader.cpp.template index cf8a6b49..1be82e99 100644 --- a/src/ObjLoading/Material/JsonMaterialLoader.cpp.template +++ b/src/ObjLoading/Material/JsonMaterialLoader.cpp.template @@ -52,39 +52,50 @@ namespace class JsonLoader { public: - JsonLoader(MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration) - : m_memory(memory), + JsonLoader(std::istream& stream, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& 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 { - std::string type; - unsigned version; - - jRoot.at("_type").get_to(type); - jRoot.at("_version").get_to(version); - - 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; - } + try + { + const auto jRoot = json::parse(m_stream); + std::string type; + unsigned version; + + jRoot.at("_type").get_to(type); + jRoot.at("_version").get_to(version); + + 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 - std::string game; - jRoot.at("_game").get_to(game); - if (game != GAME_LOWER) - { - con::error("Tried to load material \"{}\" but \"_game\" did not find expected type value {}", material.info.name, GAME_LOWER); - return false; - } + std::string game; + jRoot.at("_game").get_to(game); + if (game != GAME_LOWER) + { + con::error("Tried to load material \"{}\" but \"_game\" did not find expected type value {}", material.info.name, GAME_LOWER); + return false; + } #endif - const auto jMaterial = jRoot.get(); - return CreateMaterialFromJson(jMaterial, material); + const auto jMaterial = jRoot.get(); + return CreateMaterialFromJson(jMaterial, material); + } + catch (const json::exception& e) + { + con::error("Failed to parse json of material: {}", e.what()); + } + + return false; } private: @@ -508,6 +519,7 @@ namespace return true; } + std::istream& m_stream; MemoryManager& m_memory; AssetCreationContext& m_context; AssetRegistration& m_registration; @@ -517,28 +529,10 @@ namespace namespace GAME { bool LoadMaterialAsJson( - std::istream& stream, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration) - { - const JsonLoader loader(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& registration) - { - const JsonLoader loader(memory, context, registration); - - return loader.Load(json, material); - } -} // namespace GAME + std::istream& stream, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration) + { + const JsonLoader loader(stream, memory, context, registration); + + return loader.Load(material); + } +} // namespace GAME \ No newline at end of file diff --git a/src/ObjLoading/Material/JsonMaterialLoader.h.template b/src/ObjLoading/Material/JsonMaterialLoader.h.template index 3e3887e7..0de4f692 100644 --- a/src/ObjLoading/Material/JsonMaterialLoader.h.template +++ b/src/ObjLoading/Material/JsonMaterialLoader.h.template @@ -15,15 +15,9 @@ #include "Utils/MemoryManager.h" #include -#include - -using namespace nlohmann; namespace GAME { bool LoadMaterialAsJson( std::istream& stream, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration); - - bool LoadMaterialAsJson( - json& json, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration); -} // namespace GAME +} // namespace GAME \ No newline at end of file