Преглед на файлове

Remove no longer necessary mappings.
Fix converting ancient favorites in the case someone who has not played in a
year+ loads up.
Fully disabled old Difficulty sorting.

Stephen Damm преди 5 години
родител
ревизия
2b4b38113a
променени са 2 файла, в които са добавени 21 реда и са изтрити 43 реда
  1. 7 41
      SongBrowserPlugin/DataAccess/SongBrowserModel.cs
  2. 14 2
      SongBrowserPlugin/DataAccess/SongBrowserSettings.cs

+ 7 - 41
SongBrowserPlugin/DataAccess/SongBrowserModel.cs

@@ -25,10 +25,8 @@ namespace SongBrowser
         private SongBrowserSettings _settings;
 
         // song list management
-        private double _customSongDirLastWriteTime = 0;
-        private Dictionary<String, CustomPreviewBeatmapLevel> _levelIdToCustomLevel;
+        private double _customSongDirLastWriteTime = 0;        
         private Dictionary<String, double> _cachedLastWriteTimes;
-        private Dictionary<string, int> _weights;
         private Dictionary<BeatmapDifficulty, int> _difficultyWeights;
         private Dictionary<string, int> _levelIdToPlayCount;
 
@@ -104,38 +102,11 @@ namespace SongBrowser
         /// </summary>
         public SongBrowserModel()
         {
-            _levelIdToCustomLevel = new Dictionary<string, CustomPreviewBeatmapLevel>();
             _cachedLastWriteTimes = new Dictionary<String, double>();
             _levelIdToPlayCount = new Dictionary<string, int>();
 
             CurrentEditingPlaylistLevelIds = new HashSet<string>();
 
-            // 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, Level11 */
-            _weights = new Dictionary<string, int>
-            {
-                ["OneHopeLevel"] = 12,
-                ["100Bills"] = 11,
-                ["Escape"] = 10,
-                ["Legend"] = 9,
-                ["BeatSaber"] = 8,
-                ["AngelVoices"] = 7,
-                ["CountryRounds"] = 6,
-                ["BalearicPumping"] = 5,
-                ["Breezer"] = 4,
-                ["CommercialPumping"] = 3,
-                ["TurnMeOn"] = 2,
-                ["LvlInsane"] = 1,
-
-                ["100BillsOneSaber"] = 12,
-                ["EscapeOneSaber"] = 11,
-                ["LegendOneSaber"] = 10,
-                ["BeatSaberOneSaber"] = 9,
-                ["CommercialPumpingOneSaber"] = 8,
-                ["TurnMeOnOneSaber"] = 8,
-            };
-
             _difficultyWeights = new Dictionary<BeatmapDifficulty, int>
             {
                 [BeatmapDifficulty.Easy] = 1,
@@ -203,11 +174,6 @@ namespace SongBrowser
                     double lastWriteTime = GetSongUserDate(level.Value);
                     _cachedLastWriteTimes[level.Value.levelID] = lastWriteTime;
                 }
-
-                if (!_levelIdToCustomLevel.ContainsKey(level.Value.levelID))
-                {
-                    _levelIdToCustomLevel.Add(level.Value.levelID, level.Value);
-                }
             }
 
             lastWriteTimer.Stop();
@@ -219,7 +185,7 @@ namespace SongBrowser
             // Check if we need to upgrade settings file favorites
             try
             {
-                this.Settings.ConvertFavoritesToPlaylist(_levelIdToCustomLevel);
+                this.Settings.ConvertFavoritesToPlaylist(SongCore.Loader.CustomLevels);
             }
             catch (Exception e)
             {
@@ -693,8 +659,7 @@ namespace SongBrowser
         {
             Logger.Info("Sorting song list as newest.");
             return levels
-                .OrderBy(x => _weights.ContainsKey(x.levelID) ? _weights[x.levelID] : 0)
-                .ThenByDescending(x => !_levelIdToCustomLevel.ContainsKey(x.levelID) ? (_weights.ContainsKey(x.levelID) ? _weights[x.levelID] : 0) : _cachedLastWriteTimes[x.levelID])
+                .OrderByDescending(x => _cachedLastWriteTimes.ContainsKey(x.levelID) ? _cachedLastWriteTimes[x.levelID] : int.MinValue)
                 .ToList();
         }
 
@@ -806,8 +771,8 @@ namespace SongBrowser
         /// <returns></returns>
         private List<IPreviewBeatmapLevel> SortDifficulty(List<IPreviewBeatmapLevel> levels)
         {
-            Logger.Info("Sorting song list by difficulty...");
-
+            Logger.Info("Sorting song list by difficulty (DISABLED!!!)...");
+            /*
             IEnumerable<BeatmapDifficulty> difficultyIterator = Enum.GetValues(typeof(BeatmapDifficulty)).Cast<BeatmapDifficulty>();
             Dictionary<string, int> levelIdToDifficultyValue = new Dictionary<string, int>();
             foreach (IPreviewBeatmapLevel level in levels)
@@ -841,7 +806,8 @@ namespace SongBrowser
             return levels
                 .OrderBy(x => levelIdToDifficultyValue[x.levelID])
                 .ThenBy(x => x.songName)
-                .ToList();
+                .ToList();*/
+            return levels;
         }
 
         /// <summary>

+ 14 - 2
SongBrowserPlugin/DataAccess/SongBrowserSettings.cs

@@ -255,8 +255,19 @@ namespace SongBrowser.DataAccess
         /// </summary>
         /// <param name="levelIdToCustomLevel"></param>
         /// <param name="levelIdToSongVersion"></param>
-        public void ConvertFavoritesToPlaylist(Dictionary<String, CustomPreviewBeatmapLevel> levelIdToCustomLevel)
+        public void ConvertFavoritesToPlaylist(Dictionary<String, CustomPreviewBeatmapLevel> customSongsMap)
         {
+            // map songs in case we are converting a huge list
+            Dictionary<String, CustomPreviewBeatmapLevel> levelIdToCustomLevel = new Dictionary<string, CustomPreviewBeatmapLevel>(StringComparer.OrdinalIgnoreCase);
+            foreach (var kp in customSongsMap)
+            {
+                if (levelIdToCustomLevel.ContainsKey(kp.Value.levelID))
+                {
+                    continue;
+                }
+                levelIdToCustomLevel.Add(kp.Value.levelID, kp.Value);
+            }
+
             // Check if we have favorites to convert to the playlist
             if (this.Favorites.Count <= 0)
             {
@@ -315,7 +326,8 @@ namespace SongBrowser.DataAccess
                 else
                 {
                     // No easy way to look up original songs... They will still work but have wrong song name in playlist.  
-                    playlistSong.songName = levelId;
+                    playlistSong.levelId = levelId;
+                    playlistSong.hash = CustomHelpers.GetSongHash(levelId);
                     playlistSong.key = "";
                 }