diff --git a/Assets/Scripts/GUI/DownloadPopupWindow.cs b/Assets/Scripts/GUI/DownloadPopupWindow.cs index e3ee8a721b..9effb33834 100644 --- a/Assets/Scripts/GUI/DownloadPopupWindow.cs +++ b/Assets/Scripts/GUI/DownloadPopupWindow.cs @@ -26,12 +26,12 @@ public class DownloadPopupWindow : PopUpWindow override public void SetPopupCommandParameters(int commandParam, int commandParam2) { - if (commandParam2 != (int)SketchSetType.Drive) + var sketchSet = SketchCatalog.m_Instance.GetSet(commandParam2); + if (sketchSet.SketchSetType != GoogleDriveSketchSet.TypeName) { return; } m_SketchIndex = commandParam; - var sketchSet = SketchCatalog.m_Instance.GetSet(SketchSetType.Drive) as GoogleDriveSketchSet; m_SceneFileInfo = sketchSet.GetSketchSceneFileInfo(commandParam) as GoogleDriveSketchSet.GoogleDriveFileInfo; diff --git a/Assets/Scripts/GUI/InspectSketchButton.cs b/Assets/Scripts/GUI/InspectSketchButton.cs index e337067e52..62a0cb1bcf 100644 --- a/Assets/Scripts/GUI/InspectSketchButton.cs +++ b/Assets/Scripts/GUI/InspectSketchButton.cs @@ -18,19 +18,20 @@ namespace TiltBrush public class InspectSketchButton : BaseButton { private int m_SketchIndex; - private SketchSetType m_SketchSetType; + private string m_SketchSetId; - public void SetSketchDetails(int index, SketchSetType type) + public void SetSketchDetails(int index, string type) { m_SketchIndex = index; - m_SketchSetType = type; + m_SketchSetId = type; } override protected void OnButtonPressed() { BasePanel panel = m_Manager.GetPanelForPopUps(); + int index = SketchCatalog.m_Instance.GetSetIndexById(m_SketchSetId); panel.CreatePopUp(SketchControlsScript.GlobalCommands.SketchbookMenu, - m_SketchIndex, (int)m_SketchSetType); + m_SketchIndex, index); // Position popup next to button. panel.PositionPopUp(transform.position); diff --git a/Assets/Scripts/GUI/LoadSketchButton.cs b/Assets/Scripts/GUI/LoadSketchButton.cs index eb1b92f30b..70d42ac366 100644 --- a/Assets/Scripts/GUI/LoadSketchButton.cs +++ b/Assets/Scripts/GUI/LoadSketchButton.cs @@ -86,10 +86,10 @@ public bool WarningVisible void RefreshDetails() { - m_MenuButton.SetSketchDetails(m_SketchIndex, SketchSet.Type); + m_MenuButton.SetSketchDetails(m_SketchIndex, SketchSet.SketchSetId); m_SizeOk = true; - if (m_SketchSet.Type == SketchSetType.Liked) + if (m_SketchSet.SketchSetType == PolySketchSet.TypeName && m_SketchSet.SketchSetInstance == "Liked") { if (m_SketchSet.IsSketchIndexValid(m_SketchIndex)) { @@ -151,7 +151,7 @@ override public void SetColor(Color color) override protected void OnButtonPressed() { if (!m_SketchSet.GetSketchSceneFileInfo(m_SketchIndex).Available && - m_SketchSet.Type != SketchSetType.Drive) + m_SketchSet.SketchSetType != GoogleDriveSketchSet.TypeName) { return; } @@ -160,7 +160,7 @@ override protected void OnButtonPressed() // LoadConfirmUnsaved -> LoadWaitOnDownload -> LoadConfirmComplex -> LoadComplexHigh -> Load SketchControlsScript.m_Instance.IssueGlobalCommand( SketchControlsScript.GlobalCommands.LoadConfirmUnsaved, - m_SketchIndex, (int)m_SketchSet.Type); + m_SketchIndex, SketchCatalog.m_Instance.GetSetIndex(m_SketchSet)); ResetState(); } @@ -196,7 +196,7 @@ override public void GainFocus() { base.GainFocus(); m_DynamicUvTransitionValue = 0.0f; - m_MenuButton.gameObject.SetActive(m_SketchSet.Type == SketchSetType.User); + m_MenuButton.gameObject.SetActive(m_SketchSet.SketchSetType == FileSketchSet.TypeName); if (!m_SizeOk) { SetDescriptionVisualsAvailable(false); diff --git a/Assets/Scripts/GUI/NewSketchButton.cs b/Assets/Scripts/GUI/NewSketchButton.cs index 42e85558f4..0b1f05350a 100644 --- a/Assets/Scripts/GUI/NewSketchButton.cs +++ b/Assets/Scripts/GUI/NewSketchButton.cs @@ -49,7 +49,7 @@ protected override void OnButtonPressed() // Change the shown sketchset by simulating a press on the corresponding gallery button. SketchbookPanel panel = m_Manager.GetComponent(); - if (SketchCatalog.m_Instance.GetSet(SketchSetType.User).NumSketches == 0) + if (SketchCatalog.m_Instance.GetFirstSetOrDefault(FileSketchSet.TypeName).NumSketches == 0) { panel.ButtonPressed(GalleryButton.Type.Showcase); } diff --git a/Assets/Scripts/GUI/SketchbookPanel.cs b/Assets/Scripts/GUI/SketchbookPanel.cs index bda4b1dabe..d478c211d5 100644 --- a/Assets/Scripts/GUI/SketchbookPanel.cs +++ b/Assets/Scripts/GUI/SketchbookPanel.cs @@ -72,7 +72,7 @@ public class SketchbookPanel : ModalPanel private bool m_AllIconTexturesAssigned; private bool m_AllSketchesAreAvailable; - private SketchSetType m_CurrentSketchSet; + //private string m_CurrentSketchSet; private ISketchSet m_SketchSet; private OptionButton m_NewSketchButtonScript; private OptionButton m_PaintButtonScript; @@ -114,11 +114,13 @@ protected override List Icons public override bool IsInButtonMode(ModeButton button) { GalleryButton galleryButton = button as GalleryButton; + int index = SketchCatalog.m_Instance.GetSetIndex(m_SketchSet); + // TODO: There's gotta be a better way of doing this! return galleryButton && - ((galleryButton.m_ButtonType == GalleryButton.Type.Liked && m_CurrentSketchSet == SketchSetType.Liked) || - (galleryButton.m_ButtonType == GalleryButton.Type.Local && m_CurrentSketchSet == SketchSetType.User) || - (galleryButton.m_ButtonType == GalleryButton.Type.Showcase && m_CurrentSketchSet == SketchSetType.Curated) || - (galleryButton.m_ButtonType == GalleryButton.Type.Drive && m_CurrentSketchSet == SketchSetType.Drive)); + ((galleryButton.m_ButtonType == GalleryButton.Type.Liked && index == 2) || + (galleryButton.m_ButtonType == GalleryButton.Type.Local && index == 0) || + (galleryButton.m_ButtonType == GalleryButton.Type.Showcase && index == 1) || + (galleryButton.m_ButtonType == GalleryButton.Type.Drive && index == 3)); } override public void InitPanel() @@ -160,12 +162,15 @@ protected override void OnStart() m_NotLoggedInMessage.SetActive(false); m_NotLoggedInDriveMessage.SetActive(false); + m_SketchSet = SketchCatalog.m_Instance.GetSet(2); // Poly sketches + + // Dynamically position the gallery buttons. OnDriveSetHasSketchesChanged(); // Set the sketch set var to Liked, then function set to force state. - m_CurrentSketchSet = SketchSetType.Liked; - SetVisibleSketchSet(SketchSetType.User); + SetVisibleSketchSet(SketchCatalog.m_Instance.GetSet(0)); + RefreshPage(); Action refresh = () => { @@ -178,9 +183,11 @@ protected override void OnStart() RefreshPage(); } }; - SketchCatalog.m_Instance.GetSet(SketchSetType.Liked).OnSketchRefreshingChanged += refresh; - SketchCatalog.m_Instance.GetSet(SketchSetType.Curated).OnSketchRefreshingChanged += refresh; - SketchCatalog.m_Instance.GetSet(SketchSetType.Drive).OnSketchRefreshingChanged += refresh; + + // TODO: We probably should just do a refresh when we enter a sketchset + SketchCatalog.m_Instance.GetSet(1).OnSketchRefreshingChanged += refresh; + SketchCatalog.m_Instance.GetSet(2).OnSketchRefreshingChanged += refresh; + SketchCatalog.m_Instance.GetSet(3).OnSketchRefreshingChanged += refresh; App.GoogleIdentity.OnLogout += refresh; } @@ -201,9 +208,9 @@ override protected void OnEnablePanel() } } - void SetVisibleSketchSet(SketchSetType type) + void SetVisibleSketchSet(ISketchSet newSketchSet) { - if (m_CurrentSketchSet != type) + if (newSketchSet != m_SketchSet) { // Clean up our old sketch set. if (m_SketchSet != null) @@ -212,7 +219,7 @@ void SetVisibleSketchSet(SketchSetType type) } // Cache new set. - m_SketchSet = SketchCatalog.m_Instance.GetSet(type); + m_SketchSet = newSketchSet; m_SketchSet.OnChanged += OnSketchSetDirty; m_SketchSet.RequestRefresh(); @@ -227,12 +234,12 @@ void SetVisibleSketchSet(SketchSetType type) ComputeNumPages(); ResetPageIndex(); - m_CurrentSketchSet = type; RefreshPage(); - switch (m_CurrentSketchSet) + + switch (newSketchSet.SketchSetType) { - case SketchSetType.User: + case FileSketchSet.TypeName: if (m_PanelText) { m_PanelText.text = m_PanelTextStandard; @@ -242,7 +249,7 @@ void SetVisibleSketchSet(SketchSetType type) m_PanelTextPro.text = m_PanelTextStandard; } break; - case SketchSetType.Curated: + case ResourceCollectionSketchSet.TypeName: if (m_PanelText) { m_PanelText.text = m_PanelTextShowcase; @@ -252,7 +259,7 @@ void SetVisibleSketchSet(SketchSetType type) m_PanelTextPro.text = m_PanelTextShowcase; } break; - case SketchSetType.Liked: + case PolySketchSet.TypeName: if (m_PanelText) { m_PanelText.text = m_PanelTextLiked; @@ -262,7 +269,7 @@ void SetVisibleSketchSet(SketchSetType type) m_PanelTextPro.text = m_PanelTextLiked; } break; - case SketchSetType.Drive: + case GoogleDriveSketchSet.TypeName: if (m_PanelText) { m_PanelText.text = m_PanelTextDrive; @@ -322,7 +329,7 @@ protected override void RefreshPage() // Base Refresh updates the modal parts of the panel, and we always want those refreshed. base.RefreshPage(); - bool requiresPoly = m_CurrentSketchSet == SketchSetType.Liked; + bool requiresPoly = m_SketchSet.SketchSetType == PolySketchSet.TypeName; bool polyDown = VrAssetService.m_Instance.NoConnection && requiresPoly; m_NoPolyConnectionMessage.SetActive(polyDown); @@ -344,37 +351,35 @@ protected override void RefreshPage() bool refreshIcons = m_SketchSet.NumSketches > 0; // Show no sketches if we don't have sketches. - m_NoSketchesMessage.SetActive( - (m_CurrentSketchSet == SketchSetType.User) && (m_SketchSet.NumSketches <= 0)); - m_NoDriveSketchesMessage.SetActive( - (m_CurrentSketchSet == SketchSetType.Drive) && (m_SketchSet.NumSketches <= 0)); + bool isUser = m_SketchSet.SketchSetType == FileSketchSet.TypeName; + bool isLiked = m_SketchSet.SketchSetType == PolySketchSet.TypeName; + bool isCurated = m_SketchSet.SketchSetType == ResourceCollectionSketchSet.TypeName; + bool isDrive = m_SketchSet.SketchSetType == GoogleDriveSketchSet.TypeName; + m_NoSketchesMessage.SetActive(isUser && (m_SketchSet.NumSketches <= 0)); + m_NoDriveSketchesMessage.SetActive(isDrive && (m_SketchSet.NumSketches <= 0)); // Show sign in popup if signed out for liked or drive sketchsets - bool showNotLoggedIn = !App.GoogleIdentity.LoggedIn && - (m_CurrentSketchSet == SketchSetType.Liked || - m_CurrentSketchSet == SketchSetType.Drive); + bool showNotLoggedIn = !App.GoogleIdentity.LoggedIn && (isLiked || isDrive); refreshIcons = refreshIcons && !showNotLoggedIn; - m_NotLoggedInMessage.SetActive(showNotLoggedIn && m_CurrentSketchSet == SketchSetType.Liked); - m_NotLoggedInDriveMessage.SetActive(showNotLoggedIn && - m_CurrentSketchSet == SketchSetType.Drive); + m_NotLoggedInMessage.SetActive(showNotLoggedIn && isLiked); + m_NotLoggedInDriveMessage.SetActive(showNotLoggedIn && isDrive); // Show no likes text & gallery button if we don't have liked sketches. m_NoLikesMessage.SetActive( - (m_CurrentSketchSet == SketchSetType.Liked) && + isLiked && (m_SketchSet.NumSketches <= 0) && !m_SketchSet.IsActivelyRefreshingSketches && App.GoogleIdentity.LoggedIn); // Show Contacting Server if we're talking to Poly. m_ContactingServerMessage.SetActive( - (requiresPoly || - m_CurrentSketchSet == SketchSetType.Drive) && + (requiresPoly || isDrive) && (m_SketchSet.NumSketches <= 0) && (m_SketchSet.IsActivelyRefreshingSketches && App.GoogleIdentity.LoggedIn)); // Show Showcase error if we're in Showcase and don't have sketches. m_NoShowcaseMessage.SetActive( - (m_CurrentSketchSet == SketchSetType.Curated) && + isCurated && (m_SketchSet.NumSketches <= 0) && !m_SketchSet.IsActivelyRefreshingSketches); @@ -462,9 +467,9 @@ void Update() icon.UpdateUvOffsetAndScale(offset, m_SketchIconUvScale); } - switch (m_CurrentSketchSet) + switch (m_SketchSet.SketchSetType) { - case SketchSetType.Curated: + case ResourceCollectionSketchSet.TypeName: m_LoadingGallery.SetActive(m_SketchSet.IsActivelyRefreshingSketches); m_DriveSyncProgress.SetActive(false); m_SyncingDriveIcon.SetActive(false); @@ -472,7 +477,7 @@ void Update() m_DriveDisabledIcon.SetActive(false); m_DriveFullIcon.SetActive(false); break; - case SketchSetType.Liked: + case PolySketchSet.TypeName: m_LoadingGallery.SetActive(false); m_DriveSyncProgress.SetActive(false); m_SyncingDriveIcon.SetActive(false); @@ -480,9 +485,9 @@ void Update() m_DriveDisabledIcon.SetActive(false); m_DriveFullIcon.SetActive(false); break; - case SketchSetType.User: - case SketchSetType.Drive: - bool sketchSetRefreshing = m_CurrentSketchSet == SketchSetType.Drive && + case FileSketchSet.TypeName: + case GoogleDriveSketchSet.TypeName: + bool sketchSetRefreshing = m_SketchSet.SketchSetType == GoogleDriveSketchSet.TypeName && m_SketchSet.IsActivelyRefreshingSketches; bool driveSyncing = App.DriveSync.Syncing; bool syncEnabled = App.DriveSync.SyncEnabled; @@ -499,7 +504,7 @@ void Update() // Check to see if whether "drive set has sketches" has changed. bool driveSetHasSketches = - SketchCatalog.m_Instance.GetSet(SketchSetType.Drive).NumSketches != 0; + SketchCatalog.m_Instance.GetFirstSetOrDefault(GoogleDriveSketchSet.TypeName).NumSketches != 0; if (m_DriveSetHasSketches != driveSetHasSketches) { m_DriveSetHasSketches = driveSetHasSketches; @@ -524,7 +529,7 @@ private void OnDriveSetHasSketchesChanged() m_GalleryButtons[m_ElementNumberGalleryButtonDrive].gameObject.SetActive(false); galleryButtonN = galleryButtonAvailable - 1; - if (m_CurrentSketchSet == SketchSetType.Drive) + if (m_SketchSet.SketchSetType == GoogleDriveSketchSet.TypeName) { // We were on the Drive tab but it's gone away so switch to the local tab by simulating // the user pressing the local tab button. @@ -755,6 +760,7 @@ override public bool RaycastAgainstMeshCollider(Ray rRay, out RaycastHit rHitInf // Works specifically with GalleryButtons. public void ButtonPressed(GalleryButton.Type rType, BaseButton button = null) { + // TODO: Just do this whole damn thing differently. switch (rType) { case GalleryButton.Type.Exit: @@ -762,16 +768,16 @@ public void ButtonPressed(GalleryButton.Type rType, BaseButton button = null) PointerManager.m_Instance.EatLineEnabledInput(); break; case GalleryButton.Type.Showcase: - SetVisibleSketchSet(SketchSetType.Curated); + SetVisibleSketchSet(SketchCatalog.m_Instance.GetSet(1)); break; case GalleryButton.Type.Local: - SetVisibleSketchSet(SketchSetType.User); + SetVisibleSketchSet(SketchCatalog.m_Instance.GetSet(0)); break; case GalleryButton.Type.Liked: - SetVisibleSketchSet(SketchSetType.Liked); + SetVisibleSketchSet(SketchCatalog.m_Instance.GetSet(2)); break; case GalleryButton.Type.Drive: - SetVisibleSketchSet(SketchSetType.Drive); + SetVisibleSketchSet(SketchCatalog.m_Instance.GetSet(3)); if (!m_ReadOnlyShown) { CreatePopUp(SketchControlsScript.GlobalCommands.ReadOnlyNotice, diff --git a/Assets/Scripts/ResourceSystem/FilesystemSketchCollection.cs b/Assets/Scripts/ResourceSystem/FilesystemSketchCollection.cs index e4d9962ef8..d8ac220802 100644 --- a/Assets/Scripts/ResourceSystem/FilesystemSketchCollection.cs +++ b/Assets/Scripts/ResourceSystem/FilesystemSketchCollection.cs @@ -16,6 +16,9 @@ public FilesystemSketchCollection(string path, string name) Name = name; } + public string CollectionType => "LocalFolderCollection"; + public string CollectionInstance => m_Path; + public string Name { get; private set; } public Uri Uri { get; private set; } diff --git a/Assets/Scripts/ResourceSystem/IResourceCollection.cs b/Assets/Scripts/ResourceSystem/IResourceCollection.cs index 6e58e363c6..92b0351fd5 100644 --- a/Assets/Scripts/ResourceSystem/IResourceCollection.cs +++ b/Assets/Scripts/ResourceSystem/IResourceCollection.cs @@ -5,5 +5,8 @@ namespace TiltBrush public interface IResourceCollection : IResource { IAsyncEnumerable ContentsAsync(); + + string CollectionType { get; } + string CollectionInstance { get; } } } diff --git a/Assets/Scripts/ResourceSystem/IcosaSketchCollection.cs b/Assets/Scripts/ResourceSystem/IcosaSketchCollection.cs index 257af623f0..f43a7b57a6 100644 --- a/Assets/Scripts/ResourceSystem/IcosaSketchCollection.cs +++ b/Assets/Scripts/ResourceSystem/IcosaSketchCollection.cs @@ -54,6 +54,9 @@ public IcosaSketchCollection(HttpClient httpClient, string user = null) m_httpClient = httpClient; } + public string CollectionType => "Icosa"; + public string CollectionInstance => m_User ?? ""; + public string Name { get; private set; } public Uri Uri { get; } public Uri PreviewUri { get; } diff --git a/Assets/Scripts/ResourceSystem/ResourceCollectionSketchSet.cs b/Assets/Scripts/ResourceSystem/ResourceCollectionSketchSet.cs index b098498b8f..3b4f63590d 100644 --- a/Assets/Scripts/ResourceSystem/ResourceCollectionSketchSet.cs +++ b/Assets/Scripts/ResourceSystem/ResourceCollectionSketchSet.cs @@ -28,7 +28,10 @@ public ResourceCollectionSketchSet(IResourceCollection collection) m_Collection = collection; m_ResourceEnumerator = m_Collection.ContentsAsync().GetAsyncEnumerator(); } - public SketchSetType Type => SketchSetType.Curated; + + public const string TypeName = "ResourceCollection"; + public string SketchSetType => m_Collection.CollectionType; + public string SketchSetInstance => m_Collection.CollectionInstance; public bool IsReadyForAccess => m_Init is { IsCompleted: true }; diff --git a/Assets/Scripts/ResourceSystem/RssSketchCollection.cs b/Assets/Scripts/ResourceSystem/RssSketchCollection.cs index 4e978fdfda..113f69939d 100644 --- a/Assets/Scripts/ResourceSystem/RssSketchCollection.cs +++ b/Assets/Scripts/ResourceSystem/RssSketchCollection.cs @@ -21,6 +21,9 @@ public RssSketchCollection(HttpClient httpClient, Uri uri) m_HttpClient = httpClient; } + public string CollectionType => "Rss"; + public string CollectionInstance => m_Uri.OriginalString; + public string Name => "RSS Feed"; public Uri Uri { get; } public Uri PreviewUri { get; } diff --git a/Assets/Scripts/Save/FileSketchSet.cs b/Assets/Scripts/Save/FileSketchSet.cs index 929c3a48e2..5343d4f60d 100644 --- a/Assets/Scripts/Save/FileSketchSet.cs +++ b/Assets/Scripts/Save/FileSketchSet.cs @@ -196,7 +196,6 @@ public int CompareTo(FileSketch rCompareSketch) } } - protected SketchSetType m_Type; protected bool m_ReadyForAccess; private List m_Sketches; private Stack m_RequestedLoads; @@ -209,10 +208,11 @@ public int CompareTo(FileSketch rCompareSketch) private bool m_ReadOnly; private string m_SketchesPath; - public SketchSetType Type - { - get { return m_Type; } - } + public const string TypeName = "LocalFolder"; + + public string SketchSetType => TypeName; + + public string SketchSetInstance => $"{m_SketchesPath}?readonly={m_ReadOnly}"; public bool IsReadyForAccess { @@ -236,7 +236,6 @@ public int NumSketches public FileSketchSet() { - m_Type = SketchSetType.User; m_ReadyForAccess = false; m_RequestedLoads = new Stack(); m_Sketches = new List(); @@ -248,7 +247,6 @@ public FileSketchSet() public FileSketchSet(string path) { - m_Type = SketchSetType.Curated; m_ReadyForAccess = false; m_RequestedLoads = new Stack(); m_Sketches = new List(); @@ -333,7 +331,7 @@ public virtual void DeleteSketch(int toDelete) m_FileWatcher.NotifyDelete(m_Sketches[toDelete].SceneFileInfo.FullPath); // Notify the drive sketchset as the deleted file may now be visible there. - var driveSet = SketchCatalog.m_Instance.GetSet(SketchSetType.Drive); + var driveSet = SketchCatalog.m_Instance.GetFirstSetOrDefault(GoogleDriveSketchSet.TypeName); if (driveSet != null) { driveSet.NotifySketchChanged(m_Sketches[toDelete].SceneFileInfo.FullPath); diff --git a/Assets/Scripts/Save/ISketchSet.cs b/Assets/Scripts/Save/ISketchSet.cs index 2a615c0b72..d4e273571c 100644 --- a/Assets/Scripts/Save/ISketchSet.cs +++ b/Assets/Scripts/Save/ISketchSet.cs @@ -33,7 +33,21 @@ public interface ISketch /// SceneFileInfo. public interface ISketchSet { - SketchSetType Type { get; } + // Each Sketch Set should have a type - e.g. 'Poly', 'Icosa', 'LocalFolder', 'Rss', + // which should be the same for all instances of that type. + string SketchSetType { get; } + // Each Sketch Set should have an instance, that is enough to create a sketch set with. + // This could be something like an URL or a path, or a type. + string SketchSetInstance { get; } + + string SketchSetId => $"{SketchSetType}:{SketchSetInstance}"; + (string type, string instance) TypeAndInstanceFromId(string id) + { + int colonPos = id.IndexOf(":"); + string type = id.Substring(0, colonPos); + string instance = id.Substring(colonPos + 1); + return (type, instance); + } /// True if the sketch set can be accessed, but does not imply that all the data (like icons, etc) /// have been read yet. diff --git a/Assets/Scripts/Save/SketchCatalog.cs b/Assets/Scripts/Save/SketchCatalog.cs index c21b6f8ad1..11b06dce32 100644 --- a/Assets/Scripts/Save/SketchCatalog.cs +++ b/Assets/Scripts/Save/SketchCatalog.cs @@ -13,21 +13,13 @@ // limitations under the License. using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using UnityEngine; namespace TiltBrush { - - public enum SketchSetType - { - User, - Curated, - Liked, - Drive, - Async, - } - // SketchCatalog.Awake must come after App.Awake public class SketchCatalog : MonoBehaviour { @@ -40,9 +32,48 @@ public class SketchCatalog : MonoBehaviour private ISketchSet[] m_Sets; - public ISketchSet GetSet(SketchSetType eType) + public ISketchSet GetSet(int i) + { + return m_Sets[i]; + } + + public ISketchSet GetSet(string type, string instance) { - return m_Sets[(int)eType]; + return m_Sets.FirstOrDefault(x => x.SketchSetType == type && x.SketchSetInstance == instance); + } + + public ISketchSet GetFirstSetOrDefault(string type) + { + return m_Sets.FirstOrDefault(x => x.SketchSetType == type); + } + + public ISketchSet GetSetById(string id) + { + return m_Sets.FirstOrDefault(x => x.SketchSetId == id); + } + + public int GetSetIndexById(string id) + { + for (int i = 0; i < m_Sets.Length; i++) + { + if (m_Sets[i].SketchSetId == id) + { + return i; + } + } + return -1; + } + + public int GetSetIndex(ISketchSet sketchSet) + { + for (int i = 0; i < m_Sets.Length; i++) + { + if (m_Sets[i] == sketchSet) + { + return i; + } + } + return -1; } void Awake() @@ -72,7 +103,7 @@ void Awake() //new AsyncWrapperSketchSet(new RssSketchSetAsync(new Uri("https://heavenly-upbeat-scorpion.glitch.me/sketches.rss"))), //new ResourceCollectionSketchSet(icosaCollection), new ResourceCollectionSketchSet(rssCollection), - new PolySketchSet(this, SketchSetType.Liked, maxTriangles, needsLogin: true), + new PolySketchSet(this, PolySketchSet.SketchType.Liked, maxTriangles, needsLogin: true), new GoogleDriveSketchSet(), }; } @@ -118,12 +149,16 @@ void Update() public void NotifyUserFileCreated(string fullpath) { - m_Sets[(int)SketchSetType.User].NotifySketchCreated(fullpath); + // TODO: This won't work with more tha one filesketchset. + var userSketches = GetFirstSetOrDefault(FileSketchSet.TypeName); + userSketches.NotifySketchCreated(fullpath); } public void NotifyUserFileChanged(string fullpath) { - m_Sets[(int)SketchSetType.User].NotifySketchChanged(fullpath); + // TODO: This won't work with more tha one filesketchset. + var userSketches = GetFirstSetOrDefault(FileSketchSet.TypeName); + userSketches.NotifySketchChanged(fullpath); } } diff --git a/Assets/Scripts/Sharing/DriveSync.cs b/Assets/Scripts/Sharing/DriveSync.cs index 592d62cfbf..e42430173a 100644 --- a/Assets/Scripts/Sharing/DriveSync.cs +++ b/Assets/Scripts/Sharing/DriveSync.cs @@ -970,7 +970,7 @@ private async Task UploadItemAsync(Transfer transfer, CancellationToken token) } if (Path.GetExtension(path) == ".tilt") { - var driveSet = SketchCatalog.m_Instance.GetSet(SketchSetType.Drive); + var driveSet = SketchCatalog.m_Instance.GetFirstSetOrDefault(GoogleDriveSketchSet.TypeName); if (item.FileId == null) { driveSet.NotifySketchCreated(path); diff --git a/Assets/Scripts/Sharing/DriveSyncDebugWindow.cs b/Assets/Scripts/Sharing/DriveSyncDebugWindow.cs index e0ce79e925..0541b957a7 100644 --- a/Assets/Scripts/Sharing/DriveSyncDebugWindow.cs +++ b/Assets/Scripts/Sharing/DriveSyncDebugWindow.cs @@ -83,7 +83,7 @@ private void OnGUI() EditorGUILayout.Toggle("DriveSync.Initializing", App.DriveSync.Initializing); EditorGUILayout.Toggle("DriveSync.Initialized", App.DriveSync.Initialized); EditorGUILayout.Toggle("DriveSync.Syncing", App.DriveSync.Syncing); - var sketchset = SketchCatalog.m_Instance.GetSet(SketchSetType.Drive); + var sketchset = SketchCatalog.m_Instance.GetFirstSetOrDefault(GoogleDriveSketchSet.TypeName); if (sketchset != null) { EditorGUILayout.Toggle("SketchSet.IsReadyForAccess", sketchset.IsReadyForAccess); diff --git a/Assets/Scripts/Sharing/GoogleDriveSketchSet.cs b/Assets/Scripts/Sharing/GoogleDriveSketchSet.cs index 8f8e4c335c..4184ad7373 100644 --- a/Assets/Scripts/Sharing/GoogleDriveSketchSet.cs +++ b/Assets/Scripts/Sharing/GoogleDriveSketchSet.cs @@ -179,7 +179,10 @@ public async Task DownloadAsync(CancellationToken token) private Coroutine m_ThumbnailLoadingCoroutine; private bool m_Changed; - public SketchSetType Type => SketchSetType.Drive; + public const string TypeName = "GoogleDrive"; + public string SketchSetType => TypeName; + public string SketchSetInstance => ""; + public bool IsReadyForAccess => m_Sketches != null; diff --git a/Assets/Scripts/Sharing/PolySketchSet.cs b/Assets/Scripts/Sharing/PolySketchSet.cs index e6ba415075..b8b1934353 100644 --- a/Assets/Scripts/Sharing/PolySketchSet.cs +++ b/Assets/Scripts/Sharing/PolySketchSet.cs @@ -29,6 +29,12 @@ namespace TiltBrush public class PolySketchSet : ISketchSet { + public enum SketchType + { + Curated, + Liked, + } + const int kDownloadBufferSize = 1024 * 1024; // 1MB // Downloading is handled by PolySketchSet which will set the local paths @@ -101,21 +107,25 @@ public PolySceneFileInfo PolySceneFileInfo private bool m_ActivelyRefreshingSketches; private int m_MaximumSceneTriangles; - private SketchSetType m_Type; + private SketchType m_Type; private string m_CacheDir; private Coroutine m_RefreshCoroutine; private float m_CooldownTimer; private List m_RequestedIcons = new List(); private Coroutine m_TextureLoaderCoroutine; - public SketchSetType Type { get { return m_Type; } } + + + public const string TypeName = "Poly"; + public string SketchSetType => TypeName; + public string SketchSetInstance => m_Type == SketchType.Curated ? "Curated" : "Liked"; public VrAssetService VrAssetService { set { m_AssetService = value; } } - public PolySketchSet(MonoBehaviour parent, SketchSetType type, int maxSceneTriangles, + public PolySketchSet(MonoBehaviour parent, SketchType type, int maxSceneTriangles, bool needsLogin = false) { m_Parent = parent; @@ -288,7 +298,7 @@ private IEnumerator PeriodicRefreshCoroutine() m_RefreshRequested = false; // Don't poll the showcase - if (Type == SketchSetType.Curated) + if (m_Type == SketchType.Curated) { yield break; } @@ -326,7 +336,7 @@ private IEnumerator Refresh() if (m_CacheDir == null) { - m_CacheDir = CacheDir(Type); + m_CacheDir = CacheDir(m_Type); try { Directory.CreateDirectory(m_CacheDir); @@ -370,7 +380,7 @@ private IEnumerator PopulateSketchesCoroutine() // If we don't have a connection to Poly and we're querying the Showcase, use // the json metadatas stored in resources, instead of trying to get them from Poly. - if (VrAssetService.m_Instance.NoConnection && m_Type == SketchSetType.Curated) + if (VrAssetService.m_Instance.NoConnection && m_Type == SketchType.Curated) { TextAsset[] textAssets = Resources.LoadAll(SketchCatalog.kDefaultShowcaseSketchesFolder); @@ -382,7 +392,7 @@ private IEnumerator PopulateSketchesCoroutine() } else { - lister = m_AssetService.ListAssets(Type); + lister = m_AssetService.ListAssets(m_Type); } bool changed = false; @@ -429,11 +439,11 @@ private IEnumerator PopulateSketchesCoroutine() } // Only cull the curated sketches. If a user likes a sketch that's very high poly count, // there's no feedback to tell them why it didn't show up in their list. b/123649719 - if (m_Type == SketchSetType.Curated) + if (m_Type == SketchType.Curated) { infos = infos.Where(x => x.GltfTriangleCount < m_MaximumSceneTriangles).ToList(); } - if (m_Type == SketchSetType.Curated && !assetIds.Keys.Contains(kIntroSketchAssetId)) + if (m_Type == SketchType.Curated && !assetIds.Keys.Contains(kIntroSketchAssetId)) { yield return VrAssetService.m_Instance.InsertSketchInfo( kIntroSketchAssetId, kIntroSketchIndex, infos); @@ -472,7 +482,7 @@ private IEnumerator PopulateSketchesCoroutine() // Which results in a bad user experience. if ((++pagesFetched & 1) == 0 || lister == null || !lister.HasMore) { - if (Type == SketchSetType.Curated) + if (m_Type == SketchType.Curated) { sketches.Sort(CompareSketchesByTriangleCountAndDownloadIndex); } @@ -698,18 +708,18 @@ private IEnumerator TextureLoaderCoroutine() } } - private static string CacheDir(SketchSetType type) + private static string CacheDir(SketchType type) { switch (type) { - case SketchSetType.Liked: + case SketchType.Liked: { // Ids are in the format "people/123456" so just pull out the numeric part string id = App.GoogleIdentity.Profile.id; id = id.Substring(id.LastIndexOf('/') + 1); return Path.Combine(Application.persistentDataPath, String.Format("users/{0}/liked", id)); } - case SketchSetType.Curated: + case SketchType.Curated: return Path.Combine(Application.persistentDataPath, "Curated Sketches"); default: return null; diff --git a/Assets/Scripts/Sharing/VrAssetService.cs b/Assets/Scripts/Sharing/VrAssetService.cs index 006640c0c6..e405018227 100644 --- a/Assets/Scripts/Sharing/VrAssetService.cs +++ b/Assets/Scripts/Sharing/VrAssetService.cs @@ -759,13 +759,13 @@ public AssetGetter GetAsset(string assetId, VrAssetFormat type, string reason) return new AssetGetter(uri, assetId, type, reason); } - public AssetLister ListAssets(SketchSetType type) + public AssetLister ListAssets(PolySketchSet.SketchType type) { string filter = null; string errorMessage = null; switch (type) { - case SketchSetType.Liked: + case PolySketchSet.SketchType.Liked: if (!App.GoogleIdentity.LoggedIn) { return null; @@ -773,7 +773,7 @@ public AssetLister ListAssets(SketchSetType type) filter = $"{kUserLikesUri}?format=TILT&orderBy=LIKED_TIME&key={kPolyApiKey}"; errorMessage = "Failed to access your liked sketches."; break; - case SketchSetType.Curated: + case PolySketchSet.SketchType.Curated: if (string.IsNullOrEmpty(kPolyApiKey)) { return null; diff --git a/Assets/Scripts/SketchControlsScript.cs b/Assets/Scripts/SketchControlsScript.cs index 282e7d8791..b5ab58c072 100644 --- a/Assets/Scripts/SketchControlsScript.cs +++ b/Assets/Scripts/SketchControlsScript.cs @@ -3861,8 +3861,8 @@ IEnumerator LoadAndExportList(List filenames) // This coroutine must be run to completion or disposed. IEnumerator LoadAndExportAll() { - ISketchSet sketchSet = SketchCatalog.m_Instance.GetSet(SketchSetType.User); - for (int i = 0; i < SketchCatalog.m_Instance.GetSet(SketchSetType.User).NumSketches; ++i) + ISketchSet sketchSet = SketchCatalog.m_Instance.GetFirstSetOrDefault(FileSketchSet.TypeName); + for (int i = 0; i < sketchSet.NumSketches; ++i) { SceneFileInfo rInfo = sketchSet.GetSketchSceneFileInfo(i); using (var coroutine = LoadAndExport(rInfo.FullPath)) @@ -4237,8 +4237,9 @@ public void IssueGlobalCommand(GlobalCommands rEnum, int iParam1 = -1, { // TODO Refactor with Load below var index = iParam1; - var sketchSetType = (SketchSetType)iParam2; - ISketchSet sketchSet = SketchCatalog.m_Instance.GetSet(sketchSetType); + ISketchSet sketchSet = sParam != null + ? SketchCatalog.m_Instance.GetSetById(sParam) + : SketchCatalog.m_Instance.GetSet(iParam2); SceneFileInfo rInfo = sketchSet.GetSketchSceneFileInfo(index); if (rInfo != null) { @@ -4253,8 +4254,9 @@ public void IssueGlobalCommand(GlobalCommands rEnum, int iParam1 = -1, case GlobalCommands.Load: { var index = iParam1; - var sketchSetType = (SketchSetType)iParam2; - ISketchSet sketchSet = SketchCatalog.m_Instance.GetSet(sketchSetType); + ISketchSet sketchSet = sParam != null + ? SketchCatalog.m_Instance.GetSetById(sParam) + : SketchCatalog.m_Instance.GetSet(iParam2); SceneFileInfo rInfo = sketchSet.GetSketchSceneFileInfo(index); if (rInfo != null) { @@ -4462,8 +4464,9 @@ public void IssueGlobalCommand(GlobalCommands rEnum, int iParam1 = -1, case GlobalCommands.ShowSketchFolder: { var index = iParam1; - var sketchSetType = (SketchSetType)iParam2; - ISketchSet sketchSet = SketchCatalog.m_Instance.GetSet(sketchSetType); + ISketchSet sketchSet = sParam != null + ? SketchCatalog.m_Instance.GetSetById(sParam) + : SketchCatalog.m_Instance.GetSet(iParam2); SceneFileInfo rInfo = sketchSet.GetSketchSceneFileInfo(index); EatGazeObjectInput(); //launch external window and tell the user we did so @@ -4530,8 +4533,9 @@ public void IssueGlobalCommand(GlobalCommands rEnum, int iParam1 = -1, break; case GlobalCommands.DeleteSketch: { - var sketchSetType = (SketchSetType)iParam2; - ISketchSet sketchSet = SketchCatalog.m_Instance.GetSet(sketchSetType); + ISketchSet sketchSet = sParam != null + ? SketchCatalog.m_Instance.GetSetById(sParam) + : SketchCatalog.m_Instance.GetSet(iParam2); sketchSet.DeleteSketch(iParam1); DismissPopupOnCurrentGazeObject(false); break; @@ -4746,7 +4750,6 @@ public void IssueGlobalCommand(GlobalCommands rEnum, int iParam1 = -1, case GlobalCommands.LoadConfirmComplex: { var index = iParam1; - var sketchSetType = (SketchSetType)iParam2; bool loadSketch = true; // If the sketchbook is active, we may want to show a popup instead of load. @@ -4756,7 +4759,9 @@ public void IssueGlobalCommand(GlobalCommands rEnum, int iParam1 = -1, if (sketchBook != null) { // Get triangle count from cloud scene file info. - ISketchSet sketchSet = SketchCatalog.m_Instance.GetSet(sketchSetType); + ISketchSet sketchSet = sParam != null + ? SketchCatalog.m_Instance.GetSetById(sParam) + : SketchCatalog.m_Instance.GetSet(iParam2); SceneFileInfo sfi = sketchSet.GetSketchSceneFileInfo(index); int tris = sfi.TriangleCount ?? -1; @@ -4798,14 +4803,16 @@ public void IssueGlobalCommand(GlobalCommands rEnum, int iParam1 = -1, case GlobalCommands.LoadWaitOnDownload: { bool download = false; - if (iParam2 == (int)SketchSetType.Drive) + ISketchSet sketchSet = sParam != null + ? SketchCatalog.m_Instance.GetSetById(sParam) + : SketchCatalog.m_Instance.GetSet(iParam2); + if (sketchSet.SketchSetType == GoogleDriveSketchSet.TypeName) { BasePanel sketchBook = m_PanelManager.GetSketchBookPanel(); - var googleSketchSet = SketchCatalog.m_Instance.GetSet(SketchSetType.Drive); if (sketchBook != null - && googleSketchSet != null - && googleSketchSet.IsSketchIndexValid(iParam1) - && !googleSketchSet.GetSketchSceneFileInfo(iParam1).Available) + && sketchSet != null + && sketchSet.IsSketchIndexValid(iParam1) + && !sketchSet.GetSketchSceneFileInfo(iParam1).Available) { sketchBook.CreatePopUp(GlobalCommands.LoadConfirmComplex, iParam1, iParam2, null); download = true;