Пример #1
0
        /// <summary>
        ///     使用游戏模式来搜索谱面,可指定包括或不包括
        /// </summary>
        /// <param name="mode"></param>
        /// <param name="option"></param>
        /// <returns></returns>
        public OsuBeatmapCollection Find(OsuGameMode mode,
                                         BeatmapCollection.BeatmapFindOption option = BeatmapCollection.BeatmapFindOption.Contains)
        {
            var bc = new OsuBeatmapCollection();

            foreach (var b in _beatmaps)
            {
                if (option == BeatmapCollection.BeatmapFindOption.Contains)
                {
                    if (b.Mode == mode)
                    {
                        if (!bc.Contains(b))
                        {
                            bc.Add(b);
                        }
                    }
                }
                if (option == BeatmapCollection.BeatmapFindOption.NotContains)
                {
                    if (b.Mode != mode)
                    {
                        if (!bc.Contains(b))
                        {
                            bc.Add(b);
                        }
                    }
                }
            }

            return(bc);
        }
Пример #2
0
        /// <summary>
        ///     使用关键词搜索,可指定包含或不包含
        /// </summary>
        /// <param name="keyWord">关键词</param>
        /// <param name="option">是否包含关键词</param>
        /// <returns>包含搜索结果的谱面集合</returns>
        public OsuBeatmapCollection Find(string keyWord,
                                         BeatmapCollection.BeatmapFindOption option = BeatmapCollection.BeatmapFindOption.Contains)
        {
            var b       = new OsuBeatmapCollection();
            var keyword = keyWord.ToUpper();

            foreach (var beatmap in Beatmaps)
            {
                var allinfo = beatmap.ToString().ToUpper() + " " + beatmap.Source.ToUpper() + " " +
                              beatmap.Tags.ToUpper() + " " + beatmap.Creator.ToUpper();
                if (option == BeatmapCollection.BeatmapFindOption.Contains)
                {
                    if (keyword.StartsWith("${") && keyword.EndsWith("}"))
                    {
                        var newkeyw = keyword.Trim('$', '}', '{');
                        if (beatmap.Title.ToUpper() == newkeyw || beatmap.TitleUnicode.ToUpper() == newkeyw ||
                            beatmap.Artist.ToUpper() == newkeyw || beatmap.ArtistUnicode.ToUpper() == newkeyw ||
                            beatmap.Creator.ToUpper() == newkeyw || beatmap.Tags.ToUpper() == newkeyw ||
                            beatmap.Source.ToUpper() == newkeyw ||
                            beatmap.Difficulty.ToUpper() == newkeyw)
                        {
                            if (!b.Contains(beatmap))
                            {
                                b.Add(beatmap);
                            }
                        }
                    }
                    else if (allinfo.Contains(keyword))
                    {
                        b.Add(beatmap);
                    }
                }

                if (option == BeatmapCollection.BeatmapFindOption.NotContains)
                {
                    if (keyword.StartsWith("${") && keyword.EndsWith("}"))
                    {
                        var newkeyw = keyword.Trim('$', '}', '{');
                        if (beatmap.Title.ToUpper() != newkeyw && beatmap.TitleUnicode.ToUpper() != newkeyw &&
                            beatmap.Artist.ToUpper() != newkeyw && beatmap.ArtistUnicode.ToUpper() != newkeyw &&
                            beatmap.Creator.ToUpper() != newkeyw && beatmap.Tags.ToUpper() != newkeyw &&
                            beatmap.Source.ToUpper() != newkeyw &&
                            beatmap.Difficulty.ToUpper() != newkeyw)
                        {
                            if (!b.Contains(beatmap))
                            {
                                b.Add(beatmap);
                            }
                        }
                    }
                    else if (!allinfo.Contains(keyword))
                    {
                        b.Add(beatmap);
                    }
                }
            }

            if (b.Count == 0)
            {
                throw new BeatmapNotFoundException("找不到指定的谱面");
            }
            return(b);
        }