diff --git a/Assets/Scripts/ResourceSystem/ResourceCollectionSketchSet.cs b/Assets/Scripts/ResourceSystem/ResourceCollectionSketchSet.cs index 5ed41da0e1..d1a16b8907 100644 --- a/Assets/Scripts/ResourceSystem/ResourceCollectionSketchSet.cs +++ b/Assets/Scripts/ResourceSystem/ResourceCollectionSketchSet.cs @@ -53,7 +53,7 @@ private async Task InitAsync() public bool IsSketchIndexValid(int index) { - return index < NumSketches; + return index < NumSketches && index >= 0; } public void RequestOnlyLoadedMetadata(List requests) diff --git a/Assets/Scripts/ResourceSystem/RssSketchCollection.cs b/Assets/Scripts/ResourceSystem/RssSketchCollection.cs new file mode 100644 index 0000000000..4e978fdfda --- /dev/null +++ b/Assets/Scripts/ResourceSystem/RssSketchCollection.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using System.Xml; +using System.ServiceModel.Syndication; +using UnityEngine; + +namespace TiltBrush +{ + public class RssSketchCollection : IResourceCollection + { + private Uri m_Uri; + private HttpClient m_HttpClient; + + public RssSketchCollection(HttpClient httpClient, Uri uri) + { + m_Uri = uri; + m_HttpClient = httpClient; + } + + public string Name => "RSS Feed"; + public Uri Uri { get; } + public Uri PreviewUri { get; } + public string Description { get; } + public Author[] Authors { get; } + public ResourceLicense License { get; } + public async Task InitAsync() + { + // might as well do all the work when getting the page + return; + } + public async Task LoadPreviewAsync() + { + throw new NotImplementedException(); + } + public async Task GetStreamAsync() + { + throw new NotImplementedException(); + } + public async IAsyncEnumerable ContentsAsync() + { + SyndicationFeed feed; + try + { + Debug.Log($"Fetching rss stream {m_Uri.AbsoluteUri}"); + var stream = await m_HttpClient.GetStreamAsync(m_Uri); + Debug.Log("Got stream"); + using var xmlReader = XmlReader.Create(stream); + Debug.Log("Loading feed"); + feed = SyndicationFeed.Load(xmlReader); + } + catch (Exception e) + { + Debug.LogException(e); + yield break; + } + foreach (var item in feed.Items) + { + var remoteSketch = new RemoteSketchResource( + name: item.Title.Text, + uri: item.Links[0].Uri, + previewUri: null, + description: item.Summary.Text, + authors: item.Authors.Select(x => new TiltBrush.Author { Name = x.Name, Url = x.Uri, Email = x.Email }).ToArray() + ); + yield return remoteSketch; + } + } + } +} diff --git a/Assets/Scripts/ResourceSystem/RssSketchCollection.cs.meta b/Assets/Scripts/ResourceSystem/RssSketchCollection.cs.meta new file mode 100644 index 0000000000..797f05c730 --- /dev/null +++ b/Assets/Scripts/ResourceSystem/RssSketchCollection.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9e40a8a9d9ec80644a66760d2dafa6d1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Save/SketchCatalog.cs b/Assets/Scripts/Save/SketchCatalog.cs index 04bd20a668..68f054cb15 100644 --- a/Assets/Scripts/Save/SketchCatalog.cs +++ b/Assets/Scripts/Save/SketchCatalog.cs @@ -62,14 +62,16 @@ void Awake() InitFeaturedSketchesPath(); - var icosaCollection = new IcosaSketchCollection(App.HttpClient); + //var icosaCollection = new IcosaSketchCollection(App.HttpClient); + var rssCollection = new RssSketchCollection(App.HttpClient, new Uri("https://timaidley.github.io/open-brush-feed/sketches.rss")); m_Sets = new SketchSet[] { new FileSketchSet(), //new FileSketchSet(App.FeaturedSketchesPath()), //new AsyncWrapperSketchSet(new RssSketchSetAsync(new Uri("https://heavenly-upbeat-scorpion.glitch.me/sketches.rss"))), - new ResourceCollectionSketchSet(icosaCollection), + //new ResourceCollectionSketchSet(icosaCollection), + new ResourceCollectionSketchSet(rssCollection), new PolySketchSet(this, SketchSetType.Liked, maxTriangles, needsLogin: true), new GoogleDriveSketchSet(), };