mirror of
https://github.com/ppy/osu.git
synced 2025-02-14 04:52:55 +08: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 op = match.Groups["op"].Value;
|
||||||
var value = match.Groups["value"].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)
|
switch (key)
|
||||||
{
|
{
|
||||||
case "stars" when parseFloatWithPoint(value, out var stars):
|
case "stars" when parseFloatWithPoint(value, out var stars):
|
||||||
@ -45,12 +55,7 @@ namespace osu.Game.Screens.Select
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "length" when parseDoubleWithPoint(value.TrimEnd('m', 's', 'h'), out var length):
|
case "length" when parseDoubleWithPoint(value.TrimEnd('m', 's', 'h'), out var length):
|
||||||
var scale =
|
var scale = getLengthScale(value);
|
||||||
value.EndsWith("ms") ? 1 :
|
|
||||||
value.EndsWith("s") ? 1000 :
|
|
||||||
value.EndsWith("m") ? 60000 :
|
|
||||||
value.EndsWith("h") ? 3600000 : 1000;
|
|
||||||
|
|
||||||
updateCriteriaRange(ref criteria.Length, op, length * scale, scale / 2.0);
|
updateCriteriaRange(ref criteria.Length, op, length * scale, scale / 2.0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -70,12 +75,13 @@ namespace osu.Game.Screens.Select
|
|||||||
updateCriteriaText(ref criteria.Artist, op, value);
|
updateCriteriaText(ref criteria.Artist, op, value);
|
||||||
break;
|
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) =>
|
private static bool parseFloatWithPoint(string value, out float result) =>
|
||||||
float.TryParse(value, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out result);
|
float.TryParse(value, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out result);
|
||||||
|
Loading…
Reference in New Issue
Block a user