diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index e6dd8e4f..b66b670c 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -167,6 +167,17 @@ namespace SHADE 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 * ASSETS CREATED BY THE ENGINE. @@ -383,7 +394,7 @@ namespace SHADE 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)) { @@ -438,14 +449,19 @@ namespace SHADE return; } + AssetID target{ 0 }; if (genMeta) { - GenerateNewMeta(newPath); + auto result = GenerateNewMeta(newPath); + target = result.has_value() ? result.value() : 0; } else { - //send event here + target = GetAssetIDFromPath(path); } + + //TODO SEND EVENT HERE + } FolderPointer SHAssetManager::GetRootFolder() noexcept diff --git a/SHADE_Engine/src/Assets/SHAssetManager.h b/SHADE_Engine/src/Assets/SHAssetManager.h index 29bfe329..c0ea9a1e 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.h +++ b/SHADE_Engine/src/Assets/SHAssetManager.h @@ -50,7 +50,7 @@ namespace SHADE * \return const& to unordered_map ****************************************************************************/ static std::vector GetAllAssets() noexcept; - static std::optional GetAsset(AssetID id) noexcept; + static std::optional GetAsset(AssetID id) noexcept; static AssetType GetType(AssetID id) noexcept; @@ -90,13 +90,14 @@ namespace SHADE static std::vector GetAllDataOfType(AssetType type) noexcept; static std::vector 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 void RefreshDirectory() noexcept; private: + static AssetID GetAssetIDFromPath(AssetPath const& path) noexcept; static void InitLoaders() noexcept; static void LoadAllData() noexcept; static SHAssetData* LoadData(SHAsset const& asset) noexcept; diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp index 9089d478..791396df 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp @@ -233,7 +233,7 @@ namespace SHADE { if(ImGui::Selectable("Compile")) { - SHAssetManager::CompileAsset(file.path, !file.compiled, file.assetMeta ? file.assetMeta->id : 0); + SHAssetManager::CompileAsset(file.path, !file.compiled); QueueRefresh(); } ImGui::EndPopup();