Disable alpha component parsing in beatmap / skin colour sections

This commit is contained in:
Dean Herbert 2022-09-21 16:04:32 +09:00
parent 1e9b60f07f
commit 992441b9de
5 changed files with 7 additions and 7 deletions

View File

@ -306,7 +306,7 @@ public void TestDecodeBeatmapColours()
new Color4(128, 255, 128, 255),
new Color4(255, 187, 255, 255),
new Color4(255, 177, 140, 255),
new Color4(100, 100, 100, 100),
new Color4(100, 100, 100, 255), // alpha is specified as 100, but should be ignored.
};
Assert.AreEqual(expectedColors.Length, comboColors.Count);
for (int i = 0; i < expectedColors.Length; i++)

View File

@ -29,7 +29,7 @@ public void TestDecodeSkinColours()
new Color4(142, 199, 255, 255),
new Color4(255, 128, 128, 255),
new Color4(128, 255, 255, 255),
new Color4(100, 100, 100, 100),
new Color4(100, 100, 100, 255), // alpha is specified as 100, but should be ignored.
};
Assert.AreEqual(expectedColors.Count, comboColors.Count);

View File

@ -79,7 +79,7 @@ protected virtual void ParseLine(T output, Section section, string line)
switch (section)
{
case Section.Colours:
HandleColours(output, line);
HandleColours(output, line, false);
return;
}
}
@ -93,7 +93,7 @@ protected string StripComments(string line)
return line;
}
protected void HandleColours<TModel>(TModel output, string line)
protected void HandleColours<TModel>(TModel output, string line, bool allowAlpha)
{
var pair = SplitKeyVal(line);
@ -108,7 +108,7 @@ protected void HandleColours<TModel>(TModel output, string line)
try
{
byte alpha = split.Length == 4 ? byte.Parse(split[3]) : (byte)255;
byte alpha = allowAlpha && split.Length == 4 ? byte.Parse(split[3]) : (byte)255;
colour = new Color4(byte.Parse(split[0]), byte.Parse(split[1]), byte.Parse(split[2]), alpha);
}
catch

View File

@ -121,7 +121,7 @@ private void flushPendingLines()
break;
case string when pair.Key.StartsWith("Colour", StringComparison.Ordinal):
HandleColours(currentConfig, line);
HandleColours(currentConfig, line, true);
break;
// Custom sprite paths

View File

@ -48,7 +48,7 @@ protected override void ParseLine(SkinConfiguration skin, Section section, strin
// osu!catch section only has colour settings
// so no harm in handling the entire section
case Section.CatchTheBeat:
HandleColours(skin, line);
HandleColours(skin, line, true);
return;
}