[Assets] load Json through filesystem if available

This commit is contained in:
SweetId 2024-03-11 19:08:29 -04:00
parent 8cc1719d1b
commit d304c56898
1 changed files with 13 additions and 7 deletions

View File

@ -15,16 +15,15 @@ namespace Nz
{
Asset<TResource> asset;
JsonSerializationContext json;
if (!json.Load(path))
return {};
if (!Unserialize(json, "", &asset.m_descriptor))
return {};
FilesystemAppComponent* fs = ApplicationBase::Instance()->TryGetComponent<FilesystemAppComponent>();
if (fs) // first try using a FileSystem component to load the asset
{
auto json = fs->Load<JsonSerializationContext>(std::string_view(path.string()));
if (!Unserialize(*json, "", &asset.m_descriptor))
return {};
std::string filepath = asset.m_descriptor.path.string();
if constexpr (IsStreamingResource<TResource>)
{
@ -38,6 +37,13 @@ namespace Nz
if (!asset) // if it fails, use the default loader
{
JsonSerializationContext json;
if (!json.Load(path))
return {};
if (!Unserialize(json, "", &asset.m_descriptor))
return {};
if constexpr (IsStreamingResource<TResource>)
{
asset.m_resource = TResource::OpenFromFile(asset.m_descriptor.path, asset.m_descriptor.parameters);