mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-07-01 00:57:56 -05:00
refactor: extract material name into common source file
This commit is contained in:
22
src/ObjCommon/Material/MaterialCommon.cpp
Normal file
22
src/ObjCommon/Material/MaterialCommon.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include "MaterialCommon.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
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
|
8
src/ObjCommon/Material/MaterialCommon.h
Normal file
8
src/ObjCommon/Material/MaterialCommon.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace material
|
||||||
|
{
|
||||||
|
std::string GetFileNameForAssetName(const std::string& assetName);
|
||||||
|
}
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
#include "Game/IW5/IW5.h"
|
#include "Game/IW5/IW5.h"
|
||||||
#include "Game/IW5/Material/JsonMaterialLoaderIW5.h"
|
#include "Game/IW5/Material/JsonMaterialLoaderIW5.h"
|
||||||
|
#include "Material/MaterialCommon.h"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstring>
|
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ namespace
|
|||||||
|
|
||||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
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())
|
if (!file.IsOpen())
|
||||||
return AssetCreationResult::NoAction();
|
return AssetCreationResult::NoAction();
|
||||||
|
|
||||||
@ -41,21 +40,6 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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;
|
MemoryManager& m_memory;
|
||||||
ISearchPath& m_search_path;
|
ISearchPath& m_search_path;
|
||||||
};
|
};
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
#include "Game/T6/Material/JsonMaterialLoaderT6.h"
|
#include "Game/T6/Material/JsonMaterialLoaderT6.h"
|
||||||
#include "Game/T6/T6.h"
|
#include "Game/T6/T6.h"
|
||||||
|
#include "Material/MaterialCommon.h"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstring>
|
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ namespace
|
|||||||
|
|
||||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
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())
|
if (!file.IsOpen())
|
||||||
return AssetCreationResult::NoAction();
|
return AssetCreationResult::NoAction();
|
||||||
|
|
||||||
@ -41,21 +40,6 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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;
|
MemoryManager& m_memory;
|
||||||
ISearchPath& m_search_path;
|
ISearchPath& m_search_path;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user