1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 06:12:55 +08:00

Rework played filter to a boolean value

This commit is contained in:
Dan Balasescu 2024-08-29 15:32:35 +09:00
parent 97adac2e0a
commit fde790c014
No known key found for this signature in database

View File

@ -62,10 +62,31 @@ namespace osu.Game.Screens.Select
case "length":
return tryUpdateLengthRange(criteria, op, value);
case "played":
case "lastplayed":
return tryUpdateDateAgoRange(ref criteria.LastPlayed, op, value);
case "played":
if (!tryParseBool(value, out bool played))
return false;
// Unplayed beatmaps are filtered on DateTimeOffset.MinValue.
if (played)
{
criteria.LastPlayed.Min = DateTimeOffset.MinValue;
criteria.LastPlayed.Max = DateTimeOffset.MaxValue;
criteria.LastPlayed.IsLowerInclusive = false;
}
else
{
criteria.LastPlayed.Min = DateTimeOffset.MinValue;
criteria.LastPlayed.Max = DateTimeOffset.MinValue;
criteria.LastPlayed.IsLowerInclusive = true;
criteria.LastPlayed.IsUpperInclusive = true;
}
return true;
case "divisor":
return TryUpdateCriteriaRange(ref criteria.BeatDivisor, op, value, tryParseInt);
@ -133,6 +154,23 @@ namespace osu.Game.Screens.Select
private static bool tryParseInt(string value, out int result) =>
int.TryParse(value, NumberStyles.None, CultureInfo.InvariantCulture, out result);
private static bool tryParseBool(string value, out bool result)
{
switch (value)
{
case "1":
result = true;
return true;
case "0":
result = false;
return true;
default:
return bool.TryParse(value, out result);
}
}
private static bool tryParseEnum<TEnum>(string value, out TEnum result) where TEnum : struct
{
// First try an exact match.