1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 05:27:23 +08:00

Merge pull request #14577 from Henry-YSLin/status-criteria-parsing

Parse partially typed status names in song select filter query
This commit is contained in:
Dan Balasescu 2021-08-30 19:59:41 +09:00 committed by GitHub
commit c1f77cfa1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,8 +3,8 @@
using System;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using osu.Game.Beatmaps;
using osu.Game.Screens.Select.Filter;
namespace osu.Game.Screens.Select
@ -64,8 +64,7 @@ namespace osu.Game.Screens.Select
return TryUpdateCriteriaRange(ref criteria.BeatDivisor, op, value, tryParseInt);
case "status":
return TryUpdateCriteriaRange(ref criteria.OnlineStatus, op, value,
(string s, out BeatmapSetOnlineStatus val) => Enum.TryParse(value, true, out val));
return TryUpdateCriteriaRange(ref criteria.OnlineStatus, op, value, tryParseEnum);
case "creator":
return TryUpdateCriteriaText(ref criteria.Creator, op, value);
@ -120,6 +119,14 @@ 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 tryParseEnum<TEnum>(string value, out TEnum result) where TEnum : struct
{
if (Enum.TryParse(value, true, out result)) return true;
value = Enum.GetNames(typeof(TEnum)).FirstOrDefault(name => name.StartsWith(value, true, CultureInfo.InvariantCulture));
return Enum.TryParse(value, true, out result);
}
/// <summary>
/// Attempts to parse a keyword filter with the specified <paramref name="op"/> and textual <paramref name="value"/>.
/// If the value indicates a valid textual filter, the function returns <c>true</c> and the resulting data is stored into