Jelajahi Sumber

Fix Newest sorting when user has songs in .cache directory. This fixes
issues with BeatSaverDownloader.
Clean up some of the DebugInput code.

Stephen Damm 6 tahun lalu
induk
melakukan
8188114e03
2 mengubah file dengan 25 tambahan dan 18 penghapusan
  1. 4 3
      SongBrowserPlugin/SongBrowserModel.cs
  2. 21 15
      SongBrowserPlugin/UI/SongBrowserUI.cs

+ 4 - 3
SongBrowserPlugin/SongBrowserModel.cs

@@ -73,8 +73,9 @@ namespace SongBrowserPlugin
         public void UpdateSongLists(GameplayMode gameplayMode)
         {
             String customSongsPath = Path.Combine(Environment.CurrentDirectory, "CustomSongs");
+            String cachedSongsPath = Path.Combine(customSongsPath, ".cache");
             DateTime currentLastWriteTIme = File.GetLastWriteTimeUtc(customSongsPath);
-            string[] directories = Directory.GetDirectories(customSongsPath);
+            IEnumerable<string> directories = Directory.EnumerateDirectories(customSongsPath, "*.*", SearchOption.AllDirectories);
 
             // Get LastWriteTimes
             var Epoch = new DateTime(1970, 1, 1);
@@ -118,7 +119,7 @@ namespace SongBrowserPlugin
 
             // Weights used for keeping the original songs in order
             // Invert the weights from the game so we can order by descending and make LINQ work with us...
-            /*  Level4, Level2, Level9, Level5, Level10, Level6, Level7, Level1, Level3, Level8, */
+            /*  Level4, Level2, Level9, Level5, Level10, Level6, Level7, Level1, Level3, Level8, Level11 */
             Dictionary<string, int> weights = new Dictionary<string, int>
             {
                 ["Level4"] = 11,
@@ -139,7 +140,7 @@ namespace SongBrowserPlugin
             {
                 if (_levelIdToCustomLevel.ContainsKey(level.levelID))
                 {
-                    _log.Debug("HAS KEY: {0}", level.levelID);
+                    _log.Debug("HAS KEY {0}: {1}", _levelIdToCustomLevel[level.levelID].customSongInfo.path, level.levelID);
                 }
                 else
                 {

+ 21 - 15
SongBrowserPlugin/UI/SongBrowserUI.cs

@@ -26,6 +26,7 @@ namespace SongBrowserPlugin.UI
         StandardLevelDetailViewController _levelDetailViewController;
         StandardLevelDifficultyViewController _levelDifficultyViewController;
         StandardLevelSelectionNavigationController _levelSelectionNavigationController;
+        StandardLevelListTableView _levelListTableView;
 
         // New UI Elements
         private List<SongSortButton> _sortButtonGroup;
@@ -88,6 +89,11 @@ namespace SongBrowserPlugin.UI
                     _levelDifficultyViewController = _levelSelectionFlowCoordinator.GetPrivateField<StandardLevelDifficultyViewController>("_levelDifficultyViewController");
                 }
 
+                if (_levelListTableView == null)
+                {
+                    _levelListTableView = this._levelListViewController.GetComponentInChildren<StandardLevelListTableView>();
+                }
+
                 _simpleDialogPromptViewControllerPrefab = Resources.FindObjectsOfTypeAll<SimpleDialogPromptViewController>().First();
 
                 this._deleteDialog = UnityEngine.Object.Instantiate<SimpleDialogPromptViewController>(this._simpleDialogPromptViewControllerPrefab);
@@ -189,7 +195,7 @@ namespace SongBrowserPlugin.UI
         /// </summary>
         private void OnDidSelectLevelEvent(StandardLevelListViewController view, IStandardLevel level)
         {
-            _log.Trace("OnDidSelectLevelEvent({0}", level.levelID);
+            _log.Trace("OnDidSelectLevelEvent()");
             if (level == null)
             {
                 _log.Debug("No level selected?");
@@ -373,12 +379,17 @@ namespace SongBrowserPlugin.UI
             }
         }
 
+        /// <summary>
+        /// Scroll TableView to proper row, fire events.
+        /// </summary>
+        /// <param name="table"></param>
+        /// <param name="levelID"></param>
         private void SelectAndScrollToLevel(StandardLevelListTableView table, string levelID)
         {
             int row = table.RowNumberForLevelID(levelID);
-            TableView _tableView = table.GetComponentInChildren<TableView>();
-            _tableView.SelectRow(row, true);
-            _tableView.ScrollToRow(row, true);
+            TableView tableView = table.GetComponentInChildren<TableView>();
+            tableView.SelectRow(row, true);
+            tableView.ScrollToRow(row, true);
         }
 
         /// <summary>
@@ -409,7 +420,7 @@ namespace SongBrowserPlugin.UI
         private void CheckDebugUserInput()
         {
             try
-            {
+            {                
                 // back
                 if (Input.GetKeyDown(KeyCode.Escape))
                 {
@@ -432,14 +443,11 @@ namespace SongBrowserPlugin.UI
                     }
                     _deleteButton.onClick.Invoke();
                 }
-
-                StandardLevelListTableView levelListTableView = this._levelListViewController.GetComponentInChildren<StandardLevelListTableView>();
-
-                // z,x,c,v can be used to get into a song, b will hit continue button after song ends
+                
+                // c,v can be used to get into a song
                 if (Input.GetKeyDown(KeyCode.C))
                 {
-                    levelListTableView.SelectAndScrollToLevel(_model.SortedSongList[0].levelID);
-                    this._levelListViewController.HandleLevelListTableViewDidSelectRow(levelListTableView, 0);                    
+                    this.SelectAndScrollToLevel(_levelListTableView, _model.SortedSongList[0].levelID);                 
                     this._levelDifficultyViewController.HandleDifficultyTableViewDidSelectRow(null, 0);
                     this._levelSelectionFlowCoordinator.HandleDifficultyViewControllerDidSelectDifficulty(_levelDifficultyViewController, _model.SortedSongList[0].GetDifficultyLevel(LevelDifficulty.Easy));
                 }
@@ -454,16 +462,14 @@ namespace SongBrowserPlugin.UI
                 {
                     _lastRow = (_lastRow - 1) != -1 ? (_lastRow - 1) % this._model.SortedSongList.Count : 0;
 
-                    levelListTableView.SelectAndScrollToLevel(_model.SortedSongList[_lastRow].levelID);
-                    this._levelListViewController.HandleLevelListTableViewDidSelectRow(levelListTableView, _lastRow);
+                    this.SelectAndScrollToLevel(_levelListTableView, _model.SortedSongList[_lastRow].levelID);
                 }
 
                 if (Input.GetKeyDown(KeyCode.M))
                 {
                     _lastRow = (_lastRow + 1) % this._model.SortedSongList.Count;
 
-                    levelListTableView.SelectAndScrollToLevel(_model.SortedSongList[_lastRow].levelID);
-                    this._levelListViewController.HandleLevelListTableViewDidSelectRow(levelListTableView, _lastRow);
+                    this.SelectAndScrollToLevel(_levelListTableView, _model.SortedSongList[_lastRow].levelID);
                 }
 
                 // add to favorites