Changed function to return pointer type instead of std::optional

This commit is contained in:
Xiao Qi 2023-03-09 01:49:43 +08:00
parent 8670fe5fa9
commit 2692db1ed3
5 changed files with 23 additions and 12 deletions

View File

@ -164,14 +164,24 @@ namespace SHADE
return AssetType::INVALID;
}
std::optional<SHADE::SHAsset> SHAssetManager::GetAsset(AssetID id) noexcept
SHAsset* SHAssetManager::GetAsset(AssetID id) noexcept
{
if (assetCollection.contains(id))
{
return assetCollection[id];
return &assetCollection[id];
}
return {};
return nullptr;
}
SHAsset const* SHAssetManager::GetAssetConst(AssetID id) noexcept
{
if (assetCollection.contains(id))
{
return &assetCollection[id];
}
return nullptr;
}
AssetID SHAssetManager::GetAssetIDFromPath(AssetPath const& path) noexcept

View File

@ -50,7 +50,8 @@ namespace SHADE
* \return const& to unordered_map<AssetName, AssetID>
****************************************************************************/
static std::vector<SHAsset> GetAllAssets() noexcept;
static std::optional<SHAsset> GetAsset(AssetID id) noexcept;
static SHAsset* GetAsset(AssetID id) noexcept;
static SHAsset const* GetAssetConst(AssetID id) noexcept;
static AssetType GetType(AssetID id) noexcept;

View File

@ -378,9 +378,9 @@ namespace SHADE
// Attempt to get the asset's data for rendering editor
auto asset = SHAssetManager::GetAsset(value);
std::string assetName;
if (asset.has_value())
if (asset)
{
assetName = asset.value().name;
assetName = asset->name;
}
// Editor
@ -391,9 +391,9 @@ namespace SHADE
{
// Check if type matches
auto draggedAsset = SHAssetManager::GetAsset(*payload);
if (draggedAsset.has_value() && draggedAsset.value().type == type)
if (draggedAsset && draggedAsset->type == type)
{
value = draggedAsset.value().id;
value = draggedAsset->id;
changed = true;
}
SHDragDrop::EndTarget();

View File

@ -127,8 +127,8 @@ namespace SHADE
if (assetId.has_value())
{
const auto ASSET_INFO = SHAssetManager::GetAsset(assetId.value());
if (ASSET_INFO.has_value())
return ASSET_INFO.value().name;
if (ASSET_INFO)
return ASSET_INFO->name;
}
return {};
}

View File

@ -162,8 +162,8 @@ namespace SHADE
if (assetId.has_value())
{
const auto ASSET_INFO = SHAssetManager::GetAsset(assetId.value());
if (ASSET_INFO.has_value())
return ASSET_INFO.value().name;
if (ASSET_INFO)
return ASSET_INFO->name;
}
return {};
}