1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 02:03:22 +08:00

Merge pull request #18589 from peppy/skin-bool-parsin

Change `skin.ini` boolean parsing to match osu!stable
This commit is contained in:
Dan Balasescu 2022-06-07 10:11:07 +09:00 committed by GitHub
commit 86b685f7e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -59,11 +59,13 @@ namespace osu.Game.Tests.Skins
AddAssert("Check float parse lookup", () => requester.GetConfig<string, float>("FloatTest")?.Value == 1.1f);
}
[Test]
public void TestBoolLookup()
[TestCase("0", false)]
[TestCase("1", true)]
[TestCase("2", true)] // https://github.com/ppy/osu/issues/18579
public void TestBoolLookup(string originalValue, bool expectedParsedValue)
{
AddStep("Add config values", () => userSource.Configuration.ConfigDictionary["BoolTest"] = "1");
AddAssert("Check bool parse lookup", () => requester.GetConfig<string, bool>("BoolTest")?.Value == true);
AddStep("Add config values", () => userSource.Configuration.ConfigDictionary["BoolTest"] = originalValue);
AddAssert("Check bool parse lookup", () => requester.GetConfig<string, bool>("BoolTest")?.Value == expectedParsedValue);
}
[Test]

View File

@ -303,8 +303,13 @@ namespace osu.Game.Skinning
if (Configuration.ConfigDictionary.TryGetValue(lookup.ToString(), out string val))
{
// special case for handling skins which use 1 or 0 to signify a boolean state.
// ..or in some cases 2 (https://github.com/ppy/osu/issues/18579).
if (typeof(TValue) == typeof(bool))
val = val == "1" ? "true" : "false";
{
val = bool.TryParse(val, out bool boolVal)
? Convert.ChangeType(boolVal, typeof(bool)).ToString()
: Convert.ChangeType(Convert.ToInt32(val), typeof(bool)).ToString();
}
var bindable = new Bindable<TValue>();
if (val != null)