/// <summary>
        /// Sorting by BeatSaver heat stat.
        /// </summary>
        /// <param name="levelIds"></param>
        /// <returns></returns>
        private List <IPreviewBeatmapLevel> SortBeatSaverHeat(List <IPreviewBeatmapLevel> levelIds)
        {
            Logger.Info("Sorting song list by BeatSaver Heat!");

            // Do not always have data when trying to sort by heat
            if (!SongDataCore.Plugin.Songs.IsDataAvailable())
            {
                SortWasMissingData = true;
                return(levelIds);
            }

            return(levelIds
                   .OrderByDescending(x => {
                var hash = SongBrowserModel.GetSongHash(x.levelID);
                if (SongDataCore.Plugin.Songs.Data.Songs.ContainsKey(hash))
                {
                    return SongDataCore.Plugin.Songs.Data.Songs[hash].heat;
                }
                else
                {
                    return int.MinValue;
                }
            })
                   .ToList());
        }
        /// <summary>
        /// Sorting by PP.
        /// </summary>
        /// <param name="levels"></param>
        /// <returns></returns>
        private List <IPreviewBeatmapLevel> SortPerformancePoints(List <IPreviewBeatmapLevel> levels)
        {
            Logger.Info("Sorting song list by performance points...");

            if (!SongDataCore.Plugin.Songs.IsDataAvailable())
            {
                SortWasMissingData = true;
                return(levels);
            }

            return(levels
                   .OrderByDescending(x =>
            {
                var hash = SongBrowserModel.GetSongHash(x.levelID);
                if (SongDataCore.Plugin.Songs.Data.Songs.ContainsKey(hash))
                {
                    return SongDataCore.Plugin.Songs.Data.Songs[hash].diffs.Max(y => y.pp);
                }
                else
                {
                    return 0;
                }
            })
                   .ToList());
        }
Example #3
0
        /// <summary>
        /// Sorting by star rating.
        /// </summary>
        /// <param name="levels"></param>
        /// <returns></returns>
        private List <IPreviewBeatmapLevel> SortStars(List <IPreviewBeatmapLevel> levels)
        {
            Logger.Info("Sorting song list by star points...");

            if (!SongDataCore.Plugin.Songs.IsDataAvailable())
            {
                SortWasMissingData = true;
                return(levels);
            }

            return(levels
                   .OrderByDescending(x =>
            {
                var hash = SongBrowserModel.GetSongHash(x.levelID);
                var stars = 0.0;
                if (SongDataCore.Plugin.Songs.Data.Songs.ContainsKey(hash))
                {
                    var diffs = SongDataCore.Plugin.Songs.Data.Songs[hash].diffs;
                    stars = diffs.Max(y => (PluginConfig.Instance.InvertSortResults)
                            ? -y.star
                            : y.star);
                }

                //Logger.Debug("Stars={0}", stars);
                if (stars != 0)
                {
                    return stars;
                }

                return double.MinValue;
            })
                   .ToList());
        }
        /// <summary>
        /// Filter for a search query.
        /// </summary>
        /// <param name="levels"></param>
        /// <returns></returns>
        private List <IPreviewBeatmapLevel> FilterSearch(List <IPreviewBeatmapLevel> levels)
        {
            // Make sure we can actually search.
            if (this._settings.searchTerms.Count <= 0)
            {
                Logger.Error("Tried to search for a song with no valid search terms...");
                SortSongName(levels);
                return(levels);
            }
            string searchTerm = this._settings.searchTerms[0];

            if (String.IsNullOrEmpty(searchTerm))
            {
                Logger.Error("Empty search term entered.");
                SortSongName(levels);
                return(levels);
            }

            Logger.Info("Filtering song list by search term: {0}", searchTerm);

            var terms = searchTerm.Split(' ');

            foreach (var term in terms)
            {
                levels = levels.Intersect(
                    levels
                    .Where(x => {
                    var hash    = SongBrowserModel.GetSongHash(x.levelID);
                    var songKey = "";
                    if (SongDataCore.Plugin.Songs.Data.Songs.ContainsKey(hash))
                    {
                        songKey = SongDataCore.Plugin.Songs.Data.Songs[hash].key;
                    }
                    return($"{songKey} {x.songName} {x.songSubName} {x.songAuthorName} {x.levelAuthorName}".ToLower().Contains(term.ToLower()));
                })
                    .ToList(
                        )
                    ).ToList();
            }

            return(levels);
        }
        /// <summary>
        /// Filter songs based on ranked or unranked status.
        /// </summary>
        /// <param name="levels"></param>
        /// <param name="includeRanked"></param>
        /// <param name="includeUnranked"></param>
        /// <returns></returns>
        private List <IPreviewBeatmapLevel> FilterRanked(List <IPreviewBeatmapLevel> levels, bool includeRanked, bool includeUnranked)
        {
            return(levels.Where(x =>
            {
                var hash = SongBrowserModel.GetSongHash(x.levelID);
                double maxPP = 0.0;
                if (SongDataCore.Plugin.Songs.Data.Songs.ContainsKey(hash))
                {
                    maxPP = SongDataCore.Plugin.Songs.Data.Songs[hash].diffs.Max(y => y.pp);
                }

                if (maxPP > 0f)
                {
                    return includeRanked;
                }
                else
                {
                    return includeUnranked;
                }
            }).ToList());
        }
Example #6
0
        /// <summary>
        /// Filter songs based on ranked or unranked status.
        /// </summary>
        /// <param name="levels"></param>
        /// <param name="includeRanked"></param>
        /// <param name="includeUnranked"></param>
        /// <returns></returns>
        private List <IPreviewBeatmapLevel> FilterRanked(List <IPreviewBeatmapLevel> levels, bool includeRanked, bool includeUnranked)
        {
            var filteredLevels = levels.Where(x =>
            {
                if (!SongDataCore.Plugin.Songs.IsDataAvailable())
                {
                    return(false);
                }

                if (x == null)
                {
                    return(false);
                }

                var hash     = SongBrowserModel.GetSongHash(x.levelID);
                double maxPP = 0.0;
                if (SongDataCore.Plugin.Songs.Data.Songs.ContainsKey(hash))
                {
                    maxPP = SongDataCore.Plugin.Songs.Data.Songs[hash].diffs.Max(y => y.pp);
                }

                if (maxPP > 0f)
                {
                    return(includeRanked);
                }
                else
                {
                    return(includeUnranked);
                }
            }).ToList();

            if (filteredLevels.Count == 0)
            {
                Plugin.Log.Info("No ranked songs found after filtering.");
            }

            return(filteredLevels);
        }