mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 00:53:56 +09:00
Make OptionalRange generic
This commit is contained in:
@ -196,19 +196,19 @@ namespace osu.Game.Screens.Select
|
|||||||
|
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case "stars" when double.TryParse(value, out var stars):
|
case "stars" when float.TryParse(value, out var stars):
|
||||||
updateCriteriaRange(ref criteria.StarDifficulty, op, stars);
|
updateCriteriaRange(ref criteria.StarDifficulty, op, stars);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "ar" when double.TryParse(value, out var ar):
|
case "ar" when float.TryParse(value, out var ar):
|
||||||
updateCriteriaRange(ref criteria.ApproachRate, op, ar);
|
updateCriteriaRange(ref criteria.ApproachRate, op, ar);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "dr" when double.TryParse(value, out var dr):
|
case "dr" when float.TryParse(value, out var dr):
|
||||||
updateCriteriaRange(ref criteria.DrainRate, op, dr);
|
updateCriteriaRange(ref criteria.DrainRate, op, dr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "cs" when double.TryParse(value, out var cs):
|
case "cs" when float.TryParse(value, out var cs):
|
||||||
updateCriteriaRange(ref criteria.CircleSize, op, cs);
|
updateCriteriaRange(ref criteria.CircleSize, op, cs);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -239,7 +239,8 @@ namespace osu.Game.Screens.Select
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCriteriaRange(ref FilterCriteria.OptionalRange range, string op, double value, double tolerance = 0.05)
|
private void updateCriteriaRange<T>(ref FilterCriteria.OptionalRange<T> range, string op, T value, double tolerance = 0.05f)
|
||||||
|
where T : struct, IComparable<T>
|
||||||
{
|
{
|
||||||
switch (op)
|
switch (op)
|
||||||
{
|
{
|
||||||
@ -249,8 +250,20 @@ namespace osu.Game.Screens.Select
|
|||||||
case "=":
|
case "=":
|
||||||
case ":":
|
case ":":
|
||||||
range.IsInclusive = true;
|
range.IsInclusive = true;
|
||||||
range.Min = value - tolerance;
|
|
||||||
range.Max = value + tolerance;
|
switch (value)
|
||||||
|
{
|
||||||
|
case float _:
|
||||||
|
range.Min = (T)(object)((float)(object)value - tolerance);
|
||||||
|
range.Max = (T)(object)((float)(object)value + tolerance);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case double _:
|
||||||
|
range.Min = (T)(object)((double)(object)value - tolerance);
|
||||||
|
range.Max = (T)(object)((double)(object)value + tolerance);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ">":
|
case ">":
|
||||||
|
@ -14,12 +14,12 @@ namespace osu.Game.Screens.Select
|
|||||||
public GroupMode Group;
|
public GroupMode Group;
|
||||||
public SortMode Sort;
|
public SortMode Sort;
|
||||||
|
|
||||||
public OptionalRange StarDifficulty;
|
public OptionalRange<double> StarDifficulty;
|
||||||
public OptionalRange ApproachRate;
|
public OptionalRange<float> ApproachRate;
|
||||||
public OptionalRange DrainRate;
|
public OptionalRange<float> DrainRate;
|
||||||
public OptionalRange CircleSize;
|
public OptionalRange<float> CircleSize;
|
||||||
public OptionalRange Length;
|
public OptionalRange<double> Length;
|
||||||
public OptionalRange BPM;
|
public OptionalRange<double> BPM;
|
||||||
|
|
||||||
public int? BeatDivisor;
|
public int? BeatDivisor;
|
||||||
|
|
||||||
@ -42,23 +42,44 @@ namespace osu.Game.Screens.Select
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct OptionalRange : IEquatable<OptionalRange>
|
public struct OptionalRange<T> : IEquatable<OptionalRange<T>>
|
||||||
|
where T : struct, IComparable<T>
|
||||||
{
|
{
|
||||||
public bool IsInRange(double value)
|
public bool IsInRange(T value)
|
||||||
{
|
{
|
||||||
if (Min.HasValue && (IsInclusive ? value < Min.Value : value <= Min.Value))
|
if (Min.HasValue)
|
||||||
return false;
|
{
|
||||||
if (Max.HasValue && (IsInclusive ? value > Max.Value : value >= Max.Value))
|
int comparison = value.CompareTo(Min.Value);
|
||||||
return false;
|
|
||||||
|
if (comparison < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!IsInclusive && comparison == 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Max.HasValue)
|
||||||
|
{
|
||||||
|
int comparison = value.CompareTo(Max.Value);
|
||||||
|
|
||||||
|
if (comparison > 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!IsInclusive && comparison == 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double? Min;
|
public T? Min;
|
||||||
public double? Max;
|
public T? Max;
|
||||||
public bool IsInclusive;
|
public bool IsInclusive;
|
||||||
|
|
||||||
public bool Equals(OptionalRange range) => Min == range.Min && Max == range.Max;
|
public bool Equals(OptionalRange<T> other)
|
||||||
|
=> Min.Equals(other.Min)
|
||||||
|
&& Max.Equals(other.Max)
|
||||||
|
&& IsInclusive.Equals(other.IsInclusive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user