From 55061216855af89f21eee1174fa81d927bc94991 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Mon, 10 Jul 2023 22:23:32 -0500 Subject: VideoCommon: add support to graphics mod manager to load in assets and pass it to graphics actions --- .../Runtime/Actions/CustomPipelineAction.h | 5 +-- .../Runtime/GraphicsModActionFactory.cpp | 4 +-- .../Runtime/GraphicsModActionFactory.h | 3 +- .../Runtime/GraphicsModManager.cpp | 38 ++++++++++++++++++---- 4 files changed, 39 insertions(+), 11 deletions(-) (limited to 'Source/Core/VideoCommon/GraphicsModSystem/Runtime') diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/CustomPipelineAction.h b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/CustomPipelineAction.h index 6de0af8afe..4760da3124 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/CustomPipelineAction.h +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/CustomPipelineAction.h @@ -26,8 +26,9 @@ public: std::string m_pixel_material_asset; }; - static std::unique_ptr Create(const picojson::value& json_data, - std::string_view path); + static std::unique_ptr + Create(const picojson::value& json_data, + std::shared_ptr library); CustomPipelineAction(std::shared_ptr library, std::vector pass_descriptions); ~CustomPipelineAction(); diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionFactory.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionFactory.cpp index 4055265e5a..6ff64aa038 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionFactory.cpp +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionFactory.cpp @@ -12,7 +12,7 @@ namespace GraphicsModActionFactory { std::unique_ptr Create(std::string_view name, const picojson::value& json_data, - std::string_view path) + std::shared_ptr library) { if (name == "print") { @@ -32,7 +32,7 @@ std::unique_ptr Create(std::string_view name, const picojson: } else if (name == "custom_pipeline") { - return CustomPipelineAction::Create(json_data, path); + return CustomPipelineAction::Create(json_data, std::move(library)); } return nullptr; diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionFactory.h b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionFactory.h index 7709d75617..069533d6d1 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionFactory.h +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionFactory.h @@ -8,10 +8,11 @@ #include +#include "VideoCommon/Assets/CustomAssetLibrary.h" #include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModAction.h" namespace GraphicsModActionFactory { std::unique_ptr Create(std::string_view name, const picojson::value& json_data, - std::string_view path); + std::shared_ptr library); } diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.cpp index 3e4cd6e4e6..0d2f0fe347 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.cpp +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.cpp @@ -13,7 +13,9 @@ #include "Core/ConfigManager.h" +#include "VideoCommon/Assets/DirectFilesystemAssetLibrary.h" #include "VideoCommon/GraphicsModSystem/Config/GraphicsMod.h" +#include "VideoCommon/GraphicsModSystem/Config/GraphicsModAsset.h" #include "VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.h" #include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionFactory.h" #include "VideoCommon/TextureInfo.h" @@ -187,6 +189,8 @@ void GraphicsModManager::Load(const GraphicsModGroupConfig& config) const auto& mods = config.GetMods(); + auto filesystem_library = std::make_shared(); + std::map> group_to_targets; for (const auto& mod : mods) { @@ -208,6 +212,29 @@ void GraphicsModManager::Load(const GraphicsModGroupConfig& config) group_to_targets[internal_group].push_back(target); } } + + std::string base_path; + SplitPath(mod.GetAbsolutePath(), &base_path, nullptr, nullptr); + for (const GraphicsModAssetConfig& asset : mod.m_assets) + { + auto asset_map = asset.m_map; + for (auto& [k, v] : asset_map) + { + if (v.is_absolute()) + { + WARN_LOG_FMT(VIDEO, + "Specified graphics mod asset '{}' for mod '{}' has an absolute path, you " + "shouldn't release this to users.", + asset.m_name, mod.m_title); + } + else + { + v = std::filesystem::path{base_path} / v; + } + } + + filesystem_library->SetAssetIDMapData(asset.m_name, std::move(asset_map)); + } } for (const auto& mod : mods) @@ -215,12 +242,11 @@ void GraphicsModManager::Load(const GraphicsModGroupConfig& config) for (const GraphicsModFeatureConfig& feature : mod.m_features) { const auto create_action = - [](const std::string_view& action_name, const picojson::value& json_data, - GraphicsModConfig mod_config) -> std::unique_ptr { - std::string base_path; - SplitPath(mod_config.GetAbsolutePath(), &base_path, nullptr, nullptr); - - auto action = GraphicsModActionFactory::Create(action_name, json_data, base_path); + [filesystem_library](const std::string_view& action_name, + const picojson::value& json_data, + GraphicsModConfig mod_config) -> std::unique_ptr { + auto action = + GraphicsModActionFactory::Create(action_name, json_data, std::move(filesystem_library)); if (action == nullptr) { return nullptr; -- cgit v1.2.3