예제 #1
0
        public override object Default(string name = null)
        {
            if (_kouContext.Set <PluginArcaeaSong>().IsNullOrEmptySet())
            {
                return("曲库为空");                                                       //BUG 更新后无法进行判断是否为空
            }
            if (SystemExpand.All(string.IsNullOrWhiteSpace, name, ChartConstant,
                                 SongName, SongArtist, ChartDesigner, RatingClass, Rating, NotesCount, JacketDesigner, SongLength,
                                 SongBPM))
            {
                return("嗯?");
            }
            if (SongName.IsNullOrWhiteSpace())
            {
                SongName = name;
            }

            List <PluginArcaeaSong> satisfiedSongs = GetSatisfiedSong();

            if (satisfiedSongs.IsNullOrEmptySet())
            {
                return("找不到符合条件的歌曲");
            }

            return(satisfiedSongs.ToAutoPageSetString());
            //else if (satisfiedSongs.Count == 1)
            //{
            //    return satisfiedSongs.First().ToString(FormatType.Detail);
            //}
            //else
            //{
            //    if (Count == -1) Count = 10;
            //    Count = Count.LimitInRange(1, 20);
            //    string result = "";
            //    if (All)
            //    {
            //        Count = Count.LimitInRange(7);
            //        for (int i = 0; i < Count && i < satisfiedSongs.Count; i++)
            //        {
            //            result += $"-------{AutoFormatSong(satisfiedSongs[i])}\n";
            //        }
            //    }
            //    else
            //    {
            //        for (int i = 0; i < Count && i < satisfiedSongs.Count; i++)
            //        {
            //            result += $"{satisfiedSongs[i].ToString(FormatType.Brief)}\n";
            //        }
            //    }
            //    result += satisfiedSongs.Count - Count > 0 ? $"还有{satisfiedSongs.Count - Count}个结果..." : null;
            //    return result.Trim();
            //}
        }
예제 #2
0
        /// <summary>
        /// 获取满足当前条件的歌曲
        /// </summary>
        /// <param name="ratingList"></param>
        /// <param name="ratingClass"></param>
        /// <returns></returns>
        public List <PluginArcaeaSong> GetSatisfiedSong(List <string> ratingList = null, PluginArcaeaSong.RatingClass ratingClass = PluginArcaeaSong.RatingClass.Random)
        {
            if (_kouContext.Set <PluginArcaeaSong>().IsNullOrEmptySet())
            {
                return(null);
            }
            //处理限定难度信息
            if (ratingList.IsNullOrEmptySet())
            {
                MultiSelectionHelper.TryGetMultiSelections(Rating, out ratingList, @"^(11|10|[1-9])\+?$");
            }
            //处理限定难度类型信息
            Regex regex = new Regex("(,|,)?(ftr|pst|prs|byd|byn|future|past|present|beyond|all)(,|,)?", RegexOptions.IgnoreCase | RegexOptions.RightToLeft);

            if (!SongName.IsNullOrEmpty() && regex.IsMatch(SongName)) //若是歌名上包含难度信息则取出来
            {
                RatingClass = SongName.Match("(ftr|pst|prs|byd|byn|future|past|present|beyond|all)", RegexOptions.IgnoreCase | RegexOptions.RightToLeft);
                SongName    = regex.Replace(SongName, "", 1).Trim();
            }
            if (!RatingClass.IsNullOrEmpty())//RatingClass属性优先级比该函数中的ratingClss优先级大
            {
                if (!Enum.TryParse(RatingClass, out ratingClass))
                {
                    if (PluginArcaeaSong.RatingClassNameList.ContainsKey(RatingClass.ToLower()))
                    {
                        ratingClass = PluginArcaeaSong.RatingClassNameList[RatingClass.ToLower()];
                    }
                }
            }
            //设定难度类型默认值为FTR
            if (ratingList.IsNullOrEmptySet() && RatingClass.IsNullOrWhiteSpace() && NotesCount.IsNullOrWhiteSpace() && ChartConstant.IsNullOrWhiteSpace() && Rating.IsNullOrWhiteSpace()) //不指定难度类型则默认是future难度,后面是不默认ftr
            {
                ratingClass = PluginArcaeaSong.RatingClass.Future;
            }
            //处理歌名信息
            if (!SongName.IsNullOrWhiteSpace())
            {
                SongName = SongName.Trim().ToLower();
                string songEnID = _kouContext.Set <PluginArcaeaSongAnotherName>().FirstOrDefault(s => s.AnotherName == SongName)?.SongEnId;
                if (songEnID != null)
                {
                    SongEnID = songEnID;
                    SongName = null;
                }
            }


            //将需要用到的过滤器放到过滤容器里
            FilterContainer <PluginArcaeaSong> filterContainer = new FilterContainer <PluginArcaeaSong>();

            //使用默认ModelFilter
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.SongTitle), SongName, FilterType.Default, SortType.Ascending);//增加Song_title字段的默认filter
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.SongEnId), SongEnID, FilterType.Exact);
            if (ratingClass != PluginArcaeaSong.RatingClass.Random)
            {
                filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.ChartRatingClass), ratingClass, FilterType.SupportValueDefault);
            }
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.SongArtist), SongArtist, FilterType.Default, SortType.Ascending);
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.ChartDesigner), ChartDesigner, FilterType.Default, SortType.Ascending);
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.JacketDesigner), JacketDesigner, FilterType.Default, SortType.Ascending);
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.ChartAllNotes), NotesCount, FilterType.Default, SortType.StringAuto);
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.ChartConstant), ChartConstant, FilterType.Default, SortType.StringAuto);
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.SongLength), SongLength, FilterType.Default, SortType.StringAuto);
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.SongBpm), SongBPM, FilterType.Interval, SortType.StringAuto);
            filterContainer.ActivateAutoModelFilter();
            //加入自定义的filter
            if (!ratingList.IsNullOrEmptySet())
            {
                filterContainer.Add(FilterContainer <PluginArcaeaSong> .Convert(PluginArcaeaSong.RatingNumFilter), ratingList);
            }


            //开始筛选
            var selectedList = _kouContext.Set <PluginArcaeaSong>().ToList();

            selectedList = selectedList.Where(song => filterContainer.StartFilter(song)).ToList();
            var sorter = filterContainer.GetModelSorter();//若有sorter则排序

            if (sorter != null)
            {
                selectedList.Sort(sorter);
            }
            return(selectedList);
        }