mirror of
https://github.com/ppy/osu
synced 2025-02-09 14:47:33 +00:00
Factor out methods in FilterQueryParser
Factor FilterQueryParser.ApplyQueries into shorter methods to reduce method complexity.
This commit is contained in:
parent
70842f71f4
commit
96c0c80dc5
@ -22,6 +22,16 @@ namespace osu.Game.Screens.Select
|
||||
var op = match.Groups["op"].Value;
|
||||
var value = match.Groups["value"].Value;
|
||||
|
||||
parseKeywordCriteria(criteria, key, value, op);
|
||||
|
||||
query = query.Replace(match.ToString(), "");
|
||||
}
|
||||
|
||||
criteria.SearchText = query;
|
||||
}
|
||||
|
||||
private static void parseKeywordCriteria(FilterCriteria criteria, string key, string value, string op)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case "stars" when parseFloatWithPoint(value, out var stars):
|
||||
@ -45,12 +55,7 @@ namespace osu.Game.Screens.Select
|
||||
break;
|
||||
|
||||
case "length" when parseDoubleWithPoint(value.TrimEnd('m', 's', 'h'), out var length):
|
||||
var scale =
|
||||
value.EndsWith("ms") ? 1 :
|
||||
value.EndsWith("s") ? 1000 :
|
||||
value.EndsWith("m") ? 60000 :
|
||||
value.EndsWith("h") ? 3600000 : 1000;
|
||||
|
||||
var scale = getLengthScale(value);
|
||||
updateCriteriaRange(ref criteria.Length, op, length * scale, scale / 2.0);
|
||||
break;
|
||||
|
||||
@ -70,12 +75,13 @@ namespace osu.Game.Screens.Select
|
||||
updateCriteriaText(ref criteria.Artist, op, value);
|
||||
break;
|
||||
}
|
||||
|
||||
query = query.Replace(match.ToString(), "");
|
||||
}
|
||||
|
||||
criteria.SearchText = query;
|
||||
}
|
||||
private static int getLengthScale(string value) =>
|
||||
value.EndsWith("ms") ? 1 :
|
||||
value.EndsWith("s") ? 1000 :
|
||||
value.EndsWith("m") ? 60000 :
|
||||
value.EndsWith("h") ? 3600000 : 1000;
|
||||
|
||||
private static bool parseFloatWithPoint(string value, out float result) =>
|
||||
float.TryParse(value, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out result);
|
||||
|
Loading…
Reference in New Issue
Block a user