New internal function in asset manager to get asset ID from name of compiled asset

This commit is contained in:
Xiao Qi 2023-02-22 19:48:49 +08:00
parent 8e9854a130
commit ff76704a86
3 changed files with 23 additions and 6 deletions

View File

@ -167,6 +167,17 @@ namespace SHADE
return {}; return {};
} }
AssetID SHAssetManager::GetAssetIDFromPath(AssetPath const& path) noexcept
{
for (auto const& pair : assetCollection)
{
if (pair.second.path.stem() == path.stem())
return pair.first;
}
return 0;
}
/**************************************************************************** /****************************************************************************
* \brief Create record for new asset. CAN ONLY CREATE FOR CUSTOM * \brief Create record for new asset. CAN ONLY CREATE FOR CUSTOM
* ASSETS CREATED BY THE ENGINE. * ASSETS CREATED BY THE ENGINE.
@ -383,7 +394,7 @@ namespace SHADE
return result; return result;
} }
void SHAssetManager::CompileAsset(AssetPath const& path, bool genMeta, AssetID id) noexcept void SHAssetManager::CompileAsset(AssetPath const& path, bool genMeta) noexcept
{ {
if (!std::filesystem::exists(path)) if (!std::filesystem::exists(path))
{ {
@ -438,14 +449,19 @@ namespace SHADE
return; return;
} }
AssetID target{ 0 };
if (genMeta) if (genMeta)
{ {
GenerateNewMeta(newPath); auto result = GenerateNewMeta(newPath);
target = result.has_value() ? result.value() : 0;
} }
else else
{ {
//send event here target = GetAssetIDFromPath(path);
} }
//TODO SEND EVENT HERE
} }
FolderPointer SHAssetManager::GetRootFolder() noexcept FolderPointer SHAssetManager::GetRootFolder() noexcept

View File

@ -90,13 +90,14 @@ namespace SHADE
static std::vector<SHAssetData const*> GetAllDataOfType(AssetType type) noexcept; static std::vector<SHAssetData const*> GetAllDataOfType(AssetType type) noexcept;
static std::vector<SHAsset> GetAllRecordOfType(AssetType type) noexcept; static std::vector<SHAsset> GetAllRecordOfType(AssetType type) noexcept;
static void CompileAsset(AssetPath const& path, bool genMeta, AssetID id = 0) noexcept; static void CompileAsset(AssetPath const& path, bool genMeta) noexcept;
static FolderPointer GetRootFolder() noexcept; static FolderPointer GetRootFolder() noexcept;
static void RefreshDirectory() noexcept; static void RefreshDirectory() noexcept;
private: private:
static AssetID GetAssetIDFromPath(AssetPath const& path) noexcept;
static void InitLoaders() noexcept; static void InitLoaders() noexcept;
static void LoadAllData() noexcept; static void LoadAllData() noexcept;
static SHAssetData* LoadData(SHAsset const& asset) noexcept; static SHAssetData* LoadData(SHAsset const& asset) noexcept;

View File

@ -233,7 +233,7 @@ namespace SHADE
{ {
if(ImGui::Selectable("Compile")) if(ImGui::Selectable("Compile"))
{ {
SHAssetManager::CompileAsset(file.path, !file.compiled, file.assetMeta ? file.assetMeta->id : 0); SHAssetManager::CompileAsset(file.path, !file.compiled);
QueueRefresh(); QueueRefresh();
} }
ImGui::EndPopup(); ImGui::EndPopup();