Added line to write asset meta into file when saving

Does check for data write before saving
This commit is contained in:
Xiao Qi 2022-10-29 14:50:44 +08:00
parent 0182c90a21
commit 270205b0ba
2 changed files with 16 additions and 5 deletions

View File

@ -180,7 +180,7 @@ namespace SHADE
return id;
}
void SHAssetManager::SaveAsset(AssetID id) noexcept
bool SHAssetManager::SaveAsset(AssetID id) noexcept
{
for (auto const& asset : assetCollection)
{
@ -192,14 +192,25 @@ namespace SHADE
asset.type == AssetType::MATERIAL
)
{
auto const data = assetData[id];
loaders[static_cast<size_t>(asset.type)]->Write(data, asset.path);
return;
if (assetData.contains(id))
{
auto const data = assetData.at(id);
loaders[static_cast<size_t>(asset.type)]->Write(data, asset.path);
SHAssetMetaHandler::WriteMetaData(asset);
return true;
}
SHLOG_ERROR("Asset data has not been written into, cannot be saved: {}",
asset.path.filename().string());
return false;
}
}
}
SHLOG_WARNING("Asset id: {} not an internal asset type, save cannot be triggered", id);
return false;
}
//AssetID SHAssetManager::CreateAsset(AssetName name, AssetType type) noexcept

View File

@ -60,7 +60,7 @@ namespace SHADE
* \return resource id generated for new asset
****************************************************************************/
static AssetID CreateNewAsset(AssetType type, AssetName name) noexcept;
static void SaveAsset(AssetID id) noexcept;
static bool SaveAsset(AssetID id) noexcept;
/****************************************************************************
* \brief Import new resource from outside editor window.