Merge pull request #191 from SHADE-DP/SP3-13-Assets-Manager

Filesystem directory features and bugfix
Fixed type from extension bug that results in null meta

Added compiled check for SHFiles
This commit is contained in:
XiaoQiDigipen 2022-11-11 10:56:44 +08:00 committed by GitHub
commit 34dcc98a41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 5 deletions

View File

@ -102,6 +102,8 @@ constexpr std::string_view EXTENSIONS[] = {
AUDIO_WAV_EXTENSION, AUDIO_WAV_EXTENSION,
}; };
constexpr size_t EXTENSIONS_COUNT{ 11 };
// EXTERNAL EXTENSIONS // EXTERNAL EXTENSIONS
constexpr std::string_view GLSL_EXTENSION{ ".glsl" }; constexpr std::string_view GLSL_EXTENSION{ ".glsl" };
constexpr std::string_view DDS_EXTENSION{ ".dds" }; constexpr std::string_view DDS_EXTENSION{ ".dds" };

View File

@ -38,7 +38,7 @@ namespace SHADE
****************************************************************************/ ****************************************************************************/
AssetType SHAssetMetaHandler::GetTypeFromExtension(AssetExtension ext) noexcept AssetType SHAssetMetaHandler::GetTypeFromExtension(AssetExtension ext) noexcept
{ {
for (int i{0}; i < EXTENSIONS->size(); ++i) for (auto i{0}; i < EXTENSIONS_COUNT; ++i)
{ {
if (strcmp(ext.c_str(), EXTENSIONS[i].data()) == 0) if (strcmp(ext.c_str(), EXTENSIONS[i].data()) == 0)
{ {

View File

@ -38,6 +38,41 @@ namespace SHADE
return false; return false;
} }
bool SHFileSystem::MatchExtention(FileExt raw, FileExt compiled) noexcept
{
if (raw == GLSL_EXTENSION)
{
if (compiled == SHADER_EXTENSION ||
compiled == SHADER_BUILT_IN_EXTENSION)
{
return true;
}
}
else if (raw == DDS_EXTENSION)
{
if (compiled == TEXTURE_EXTENSION)
{
return true;
}
}
else if (raw == FBX_EXTENSION)
{
if (compiled == MODEL_EXTENSION)
{
return true;
}
}
else if (raw == GLTF_EXTENSION)
{
if (compiled == MODEL_EXTENSION)
{
return true;
}
}
return false;
}
void SHFileSystem::BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map<AssetID, SHAsset>& assetCollection) noexcept void SHFileSystem::BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map<AssetID, SHAsset>& assetCollection) noexcept
{ {
std::stack<FolderPointer> folderStack; std::stack<FolderPointer> folderStack;
@ -52,6 +87,7 @@ namespace SHADE
std::vector<SHAsset> assets; std::vector<SHAsset> assets;
// Get all subfolders/files in this current folder
for (auto& dirEntry : std::filesystem::directory_iterator(folder->path)) for (auto& dirEntry : std::filesystem::directory_iterator(folder->path))
{ {
auto path = dirEntry.path(); auto path = dirEntry.path();
@ -60,8 +96,6 @@ namespace SHADE
{ {
if (path.extension().string() == META_EXTENSION) if (path.extension().string() == META_EXTENSION)
{ {
//auto asset = SHAssetMetaHandler::RetrieveMetaData(path);
//assetCollection.insert({ asset.id, asset });
assets.push_back(SHAssetMetaHandler::RetrieveMetaData(path)); assets.push_back(SHAssetMetaHandler::RetrieveMetaData(path));
} }
else else
@ -71,12 +105,14 @@ namespace SHADE
path.string(), path.string(),
path.extension().string(), path.extension().string(),
nullptr, nullptr,
IsCompilable(path.extension().string()) IsCompilable(path.extension().string()),
false
); );
} }
continue; continue;
} }
// If item is folder
auto newFolder{ folder->CreateSubFolderHere(path.stem().string()) }; auto newFolder{ folder->CreateSubFolderHere(path.stem().string()) };
folderStack.push(newFolder); folderStack.push(newFolder);
} }
@ -97,6 +133,30 @@ namespace SHADE
} }
} }
} }
for (auto i {0}; i < folder->files.size(); ++i)
{
auto& file = folder->files[i];
if (file.compilable)
{
for (auto j{ 0 }; j < folder->files.size(); ++j)
{
auto& check = folder->files[j];
if (i == j || check.compilable)
{
continue;
}
if (file.name == check.name)
{
if (MatchExtention(file.ext, check.ext))
{
file.compiled = true;
}
}
}
}
}
} }
} }

View File

@ -24,5 +24,6 @@ namespace SHADE
private: private:
static bool DeleteFolder(FolderPointer location) noexcept; static bool DeleteFolder(FolderPointer location) noexcept;
static bool IsCompilable(std::string ext) noexcept; static bool IsCompilable(std::string ext) noexcept;
static bool MatchExtention(FileExt raw, FileExt compiled) noexcept;
}; };
} }

View File

@ -34,6 +34,7 @@ namespace SHADE
FileExt ext; FileExt ext;
SHAsset const* assetMeta; SHAsset const* assetMeta;
bool compilable; bool compilable;
bool compiled;
}; };
class SHFolder class SHFolder