#include #include #include namespace Nz { template concept IsStreamingResource = requires(TResource) { { TResource::OpenFromFile({}) } -> std::same_as>; }; template Asset AssetCatalog::LoadFromFile(const std::filesystem::path& path) { Asset asset; FilesystemAppComponent* fs = ApplicationBase::Instance()->TryGetComponent(); if (fs) // first try using a FileSystem component to load the asset { auto json = fs->Load(std::string_view(path.string())); if (!Unserialize(*json, "", &asset.m_descriptor)) return {}; std::string filepath = asset.m_descriptor.path.string(); if constexpr (IsStreamingResource) { asset.m_resource = fs->Open(std::string_view(filepath), asset.m_descriptor.parameters); } else { asset.m_resource = fs->Load(std::string_view(filepath), asset.m_descriptor.parameters); } } 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) { asset.m_resource = TResource::OpenFromFile(asset.m_descriptor.path, asset.m_descriptor.parameters); } else { asset.m_resource = TResource::LoadFromFile(asset.m_descriptor.path, asset.m_descriptor.parameters); } } return asset; } }