32 lines
955 B
C++
32 lines
955 B
C++
#include <Nazara/Core/ApplicationBase.hpp>
|
|
#include <Nazara/Core/FilesystemAppComponent.hpp>
|
|
#include <Nazara/Core/JsonSerialization.hpp>
|
|
|
|
namespace Nz
|
|
{
|
|
template <typename TResource>
|
|
Asset<TResource> AssetCatalog::LoadFromFile(const std::filesystem::path& path)
|
|
{
|
|
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
|
|
{
|
|
std::string filepath = asset.m_descriptor.path.string();
|
|
asset.m_resource = fs->Load<TResource>(std::string_view(filepath), asset.m_descriptor.parameters);
|
|
}
|
|
|
|
if (!asset) // if it fails, use the default loader
|
|
asset.m_resource = TResource::LoadFromFile(asset.m_descriptor.path, asset.m_descriptor.parameters);
|
|
|
|
return asset;
|
|
}
|
|
}
|