Fix carousel including filtered difficulties in sort comparisons

This commit is contained in:
Dean Herbert 2019-10-07 15:16:26 +09:00
parent 46d6c5ec3b
commit f15953d65c
2 changed files with 21 additions and 4 deletions

View File

@ -49,16 +49,33 @@ public override int CompareTo(FilterCriteria criteria, CarouselItem other)
return otherSet.BeatmapSet.DateAdded.CompareTo(BeatmapSet.DateAdded);
case SortMode.BPM:
return BeatmapSet.MaxBPM.CompareTo(otherSet.BeatmapSet.MaxBPM);
return compareUsingAggregateMax(otherSet, b => b.BPM);
case SortMode.Length:
return BeatmapSet.MaxLength.CompareTo(otherSet.BeatmapSet.MaxLength);
return compareUsingAggregateMax(otherSet, b => b.Length);
case SortMode.Difficulty:
return BeatmapSet.MaxStarDifficulty.CompareTo(otherSet.BeatmapSet.MaxStarDifficulty);
return compareUsingAggregateMax(otherSet, b => b.StarDifficulty);
}
}
/// <summary>
/// All beatmaps which are not filtered and valid for display.
/// </summary>
protected IEnumerable<BeatmapInfo> ValidBeatmaps => Beatmaps.Where(b => !b.Filtered.Value).Select(b => b.Beatmap);
private int compareUsingAggregateMax(CarouselBeatmapSet other, Func<BeatmapInfo, double> func)
{
var ourBeatmaps = ValidBeatmaps.Any();
var otherBeatmaps = other.ValidBeatmaps.Any();
if (!ourBeatmaps && !otherBeatmaps) return 0;
if (!ourBeatmaps) return -1;
if (!otherBeatmaps) return 1;
return ValidBeatmaps.Max(func).CompareTo(other.ValidBeatmaps.Max(func));
}
public override void Filter(FilterCriteria criteria)
{
base.Filter(criteria);

View File

@ -83,8 +83,8 @@ public override void Filter(FilterCriteria criteria)
var children = new List<CarouselItem>(InternalChildren);
children.Sort((x, y) => x.CompareTo(criteria, y));
children.ForEach(c => c.Filter(criteria));
children.Sort((x, y) => x.CompareTo(criteria, y));
InternalChildren = children;
}