diff --git a/src/ObjCommon/Material/MaterialCommon.cpp b/src/ObjCommon/Material/MaterialCommon.cpp new file mode 100644 index 00000000..895ef526 --- /dev/null +++ b/src/ObjCommon/Material/MaterialCommon.cpp @@ -0,0 +1,22 @@ +#include "MaterialCommon.h" + +#include +#include + +namespace material +{ + std::string GetFileNameForAssetName(const std::string& assetName) + { + std::string sanitizedFileName(assetName); + if (sanitizedFileName[0] == '*') + { + std::ranges::replace(sanitizedFileName, '*', '_'); + const auto parenthesisPos = sanitizedFileName.find('('); + if (parenthesisPos != std::string::npos) + sanitizedFileName.erase(parenthesisPos); + sanitizedFileName = std::format("generated/{}", sanitizedFileName); + } + + return std::format("materials/{}.json", sanitizedFileName); + } +} // namespace material diff --git a/src/ObjCommon/Material/MaterialCommon.h b/src/ObjCommon/Material/MaterialCommon.h new file mode 100644 index 00000000..f087b484 --- /dev/null +++ b/src/ObjCommon/Material/MaterialCommon.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace material +{ + std::string GetFileNameForAssetName(const std::string& assetName); +} diff --git a/src/ObjLoading/Game/IW5/Material/LoaderMaterialIW5.cpp b/src/ObjLoading/Game/IW5/Material/LoaderMaterialIW5.cpp index e954d0cd..189e368f 100644 --- a/src/ObjLoading/Game/IW5/Material/LoaderMaterialIW5.cpp +++ b/src/ObjLoading/Game/IW5/Material/LoaderMaterialIW5.cpp @@ -2,9 +2,8 @@ #include "Game/IW5/IW5.h" #include "Game/IW5/Material/JsonMaterialLoaderIW5.h" +#include "Material/MaterialCommon.h" -#include -#include #include #include @@ -23,7 +22,7 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { - const auto file = m_search_path.Open(GetFileNameForAsset(assetName)); + const auto file = m_search_path.Open(material::GetFileNameForAssetName(assetName)); if (!file.IsOpen()) return AssetCreationResult::NoAction(); @@ -41,21 +40,6 @@ namespace } private: - std::string GetFileNameForAsset(const std::string& assetName) - { - std::string sanitizedFileName(assetName); - if (sanitizedFileName[0] == '*') - { - std::ranges::replace(sanitizedFileName, '*', '_'); - const auto parenthesisPos = sanitizedFileName.find('('); - if (parenthesisPos != std::string::npos) - sanitizedFileName.erase(parenthesisPos); - sanitizedFileName = std::format("generated/{}", sanitizedFileName); - } - - return std::format("materials/{}.json", sanitizedFileName); - } - MemoryManager& m_memory; ISearchPath& m_search_path; }; diff --git a/src/ObjLoading/Game/T6/Material/LoaderMaterialT6.cpp b/src/ObjLoading/Game/T6/Material/LoaderMaterialT6.cpp index 3d68e485..5458b96e 100644 --- a/src/ObjLoading/Game/T6/Material/LoaderMaterialT6.cpp +++ b/src/ObjLoading/Game/T6/Material/LoaderMaterialT6.cpp @@ -2,9 +2,8 @@ #include "Game/T6/Material/JsonMaterialLoaderT6.h" #include "Game/T6/T6.h" +#include "Material/MaterialCommon.h" -#include -#include #include #include @@ -23,7 +22,7 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { - const auto file = m_search_path.Open(GetFileNameForAsset(assetName)); + const auto file = m_search_path.Open(material::GetFileNameForAssetName(assetName)); if (!file.IsOpen()) return AssetCreationResult::NoAction(); @@ -41,21 +40,6 @@ namespace } private: - static std::string GetFileNameForAsset(const std::string& assetName) - { - std::string sanitizedFileName(assetName); - if (sanitizedFileName[0] == '*') - { - std::ranges::replace(sanitizedFileName, '*', '_'); - const auto parenthesisPos = sanitizedFileName.find('('); - if (parenthesisPos != std::string::npos) - sanitizedFileName.erase(parenthesisPos); - sanitizedFileName = "generated/" + sanitizedFileName; - } - - return std::format("materials/{}.json", sanitizedFileName); - } - MemoryManager& m_memory; ISearchPath& m_search_path; };