diff --git a/include/Nazara/Core/AssetCatalog.inl b/include/Nazara/Core/AssetCatalog.inl index eb42851f6..292d6b73b 100644 --- a/include/Nazara/Core/AssetCatalog.inl +++ b/include/Nazara/Core/AssetCatalog.inl @@ -4,6 +4,12 @@ namespace Nz { + template + concept IsStreamingResource = requires(TResource) + { + { TResource::OpenFromFile({}) } -> std::same_as>; + }; + template Asset AssetCatalog::LoadFromFile(const std::filesystem::path& path) { @@ -20,11 +26,27 @@ namespace Nz 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(std::string_view(filepath), asset.m_descriptor.parameters); + 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 - asset.m_resource = TResource::LoadFromFile(asset.m_descriptor.path, asset.m_descriptor.parameters); + { + 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; }