浏览代码

Refactoring, organizing.
Updating song info for quick look up while sorting is now also timed.

Stephen Damm 6 年之前
父节点
当前提交
3393440d40

+ 22 - 0
SongBrowserPlugin/DataAccess/FileSystem/Directory.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SongBrowserPlugin.DataAccess.FileSystem
+{
+    class DirectoryNode
+    {
+        public string Key { get; private set; }
+        public Dictionary<String, DirectoryNode> Nodes;
+        public List<StandardLevelSO> Levels;
+
+        public DirectoryNode(String key)
+        {
+            Key = key;
+            Nodes = new Dictionary<string, DirectoryNode>();
+            Levels = new List<StandardLevelSO>();
+        }
+    }
+}

+ 57 - 0
SongBrowserPlugin/DataAccess/FileSystem/Folder.cs

@@ -0,0 +1,57 @@
+using SongLoaderPlugin.OverrideClasses;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using UnityEngine;
+
+namespace SongBrowserPlugin.DataAccess.FileSystem
+{
+    class FolderBeatMapData : BeatmapData
+    {
+        public FolderBeatMapData(BeatmapLineData[] beatmapLinesData, BeatmapEventData[] beatmapEventData) :
+            base(beatmapLinesData, beatmapEventData)
+        {
+        }
+    }
+
+    class FolderBeatMapDataSO : BeatmapDataSO
+    {
+        public FolderBeatMapDataSO()
+        {
+            BeatmapLineData lineData = new BeatmapLineData();
+            lineData.beatmapObjectsData = new BeatmapObjectData[0];
+            this._beatmapData = new FolderBeatMapData(
+                new BeatmapLineData[1]
+                {
+                    lineData
+                },
+                new BeatmapEventData[1]
+                {
+                    new BeatmapEventData(0, BeatmapEventType.Event0, 0)
+                });
+        }
+    }
+
+    class FolderLevel : StandardLevelSO
+    {
+        public void Init(String relativePath, String name, Sprite coverImage)
+        {
+            _songName = name;
+            _songSubName = "";
+            _songAuthorName = "Folder";
+
+            _levelID = $"Folder_{relativePath}";
+
+            var beatmapData = new FolderBeatMapDataSO();
+            var difficultyBeatmaps = new List<CustomLevel.CustomDifficultyBeatmap>();
+            var newDiffBeatmap = new CustomLevel.CustomDifficultyBeatmap(this, LevelDifficulty.Easy, 0, 0, beatmapData);
+            difficultyBeatmaps.Add(newDiffBeatmap);
+
+            var sceneInfo = Resources.Load<SceneInfo>("SceneInfo/" + "DefaultEnvironment" + "SceneInfo");
+            this.InitFull(_levelID, _songName, _songSubName, _songAuthorName, SongLoaderPlugin.SongLoader.TemporaryAudioClip, 1, 1, 1, 1, 1, 1, 1, coverImage, difficultyBeatmaps.ToArray(), sceneInfo);
+            this.InitData();
+        }
+    }
+}

+ 9 - 64
SongBrowserPlugin/DataAccess/SongBrowserModel.cs

@@ -1,4 +1,5 @@
 using SongBrowserPlugin.DataAccess;
+using SongBrowserPlugin.DataAccess.FileSystem;
 using SongBrowserPlugin.UI;
 using SongLoaderPlugin;
 using SongLoaderPlugin.OverrideClasses;
@@ -12,67 +13,6 @@ using UnityEngine;
 
 namespace SongBrowserPlugin
 {
-    class FolderBeatMapData : BeatmapData
-    {
-        public FolderBeatMapData(BeatmapLineData[] beatmapLinesData, BeatmapEventData[] beatmapEventData) :
-            base(beatmapLinesData, beatmapEventData)
-        {
-        }
-    }
-
-    class FolderBeatMapDataSO : BeatmapDataSO
-    {
-        public FolderBeatMapDataSO()
-        {
-            BeatmapLineData lineData = new BeatmapLineData();
-            lineData.beatmapObjectsData = new BeatmapObjectData[0];
-            this._beatmapData = new FolderBeatMapData(
-                new BeatmapLineData[1]
-                {
-                    lineData
-                },
-                new BeatmapEventData[1]
-                {
-                    new BeatmapEventData(0, BeatmapEventType.Event0, 0)
-                });
-        }
-    }
-
-    class FolderLevel : StandardLevelSO
-    {
-        public void Init(String relativePath, String name, Sprite coverImage)
-        {
-            _songName = name;
-            _songSubName = "";
-            _songAuthorName = "Folder";
-
-            _levelID = $"Folder_{relativePath}";
-
-            var beatmapData = new FolderBeatMapDataSO();
-            var difficultyBeatmaps = new List<CustomLevel.CustomDifficultyBeatmap>();
-            var newDiffBeatmap = new CustomLevel.CustomDifficultyBeatmap(this, LevelDifficulty.Easy, 0, 0, beatmapData);
-            difficultyBeatmaps.Add(newDiffBeatmap);
-
-            var sceneInfo = Resources.Load<SceneInfo>("SceneInfo/" + "DefaultEnvironment" + "SceneInfo");
-            this.InitFull(_levelID, _songName, _songSubName, _songAuthorName, SongLoaderPlugin.SongLoader.TemporaryAudioClip, 1, 1, 1, 1, 1, 1, 1, coverImage, difficultyBeatmaps.ToArray(), sceneInfo);
-            this.InitData();
-        }
-    }
-
-    class DirectoryNode
-    {
-        public string Key { get; private set; }
-        public Dictionary<String, DirectoryNode> Nodes;
-        public List<StandardLevelSO> Levels;
-
-        public DirectoryNode(String key)
-        {
-            Key = key;
-            Nodes = new Dictionary<string, DirectoryNode>();
-            Levels = new List<StandardLevelSO>();
-        }
-    }
-
     public class SongBrowserModel
     {
         private const String CUSTOM_SONGS_DIR = "CustomSongs";
@@ -89,7 +29,6 @@ namespace SongBrowserPlugin
         private List<StandardLevelSO> _sortedSongs;
         private List<StandardLevelSO> _originalSongs;
         private Dictionary<String, SongLoaderPlugin.OverrideClasses.CustomLevel> _levelIdToCustomLevel;
-        //private SongLoaderPlugin.OverrideClasses.CustomLevelCollectionSO _gameplayModeCollection;
         private Dictionary<String, double> _cachedLastWriteTimes;
         private Dictionary<string, int> _weights;
         private Dictionary<string, ScoreSaberData> _ppMapping = null;
@@ -273,10 +212,13 @@ namespace SongBrowserPlugin
         /// </summary>
         public void UpdateSongLists(GameplayMode gameplayMode)
         {
-            if (SongLoader.CustomLevels.Count > 0)
+            /*if (SongLoader.CustomLevels.Count > 0)
             {
                 SongBrowserApplication.MainProgressBar.ShowMessage("Processing songs...");
-            }
+            }*/
+
+            Stopwatch timer = new Stopwatch();
+            timer.Start();
 
             _currentGamePlayMode = gameplayMode;
 
@@ -302,6 +244,9 @@ namespace SongBrowserPlugin
             {
                 didFinishProcessingSongs?.Invoke(SongLoader.CustomLevels);
             }
+
+            timer.Stop();
+            _log.Info("Updating songs infos took {0}ms", timer.ElapsedMilliseconds);
         }
 
         /// <summary>

+ 2 - 0
SongBrowserPlugin/SongBrowserPlugin.csproj

@@ -100,6 +100,8 @@
     </Reference>
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="DataAccess\FileSystem\Directory.cs" />
+    <Compile Include="DataAccess\FileSystem\Folder.cs" />
     <Compile Include="DataAccess\Network\CacheableDownloadHandler.cs" />
     <Compile Include="DataAccess\Network\CacheableDownloadHandlerScoreSaberData.cs" />
     <Compile Include="DataAccess\Playlist.cs" />