1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 16:47:29 +08:00

Fix colours with alpha components not being parsed

This commit is contained in:
smoogipoo 2018-10-05 11:19:01 +09:00
parent 9d518ff3ab
commit cb1703c6e2
3 changed files with 12 additions and 5 deletions

View File

@ -165,7 +165,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
}
[Test]
public void TestDecodeBeatmapColors()
public void TestDecodeBeatmapColours()
{
var decoder = new LegacySkinDecoder();
using (var resStream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
@ -181,6 +181,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
new Color4(128, 255, 128, 255),
new Color4(255, 187, 255, 255),
new Color4(255, 177, 140, 255),
new Color4(100, 100, 100, 100),
};
Assert.AreEqual(expectedColors.Length, comboColors.Count);
for (int i = 0; i < expectedColors.Length; i++)

View File

@ -101,6 +101,7 @@ Combo3 : 128,255,255
Combo4 : 128,255,128
Combo5 : 255,187,255
Combo6 : 255,177,140
Combo7 : 100,100,100,100
[HitObjects]
192,168,956,6,0,P|184:128|200:80,1,90,4|0,1:2|0:0,0:0:0:0:

View File

@ -85,13 +85,18 @@ namespace osu.Game.Beatmaps.Formats
string[] split = pair.Value.Split(',');
if (split.Length != 3)
throw new InvalidOperationException($@"Color specified in incorrect format (should be R,G,B): {pair.Value}");
if (split.Length != 3 && split.Length != 4)
throw new InvalidOperationException($@"Color specified in incorrect format (should be R,G,B or R,G,B,A): {pair.Value}");
if (!byte.TryParse(split[0], out var r) || !byte.TryParse(split[1], out var g) || !byte.TryParse(split[2], out var b))
byte a = 255;
if (!byte.TryParse(split[0], out var r) || !byte.TryParse(split[1], out var g) || !byte.TryParse(split[2], out var b)
|| split.Length == 4 && !byte.TryParse(split[3], out a))
{
throw new InvalidOperationException(@"Color must be specified with 8-bit integer components");
}
Color4 colour = new Color4(r, g, b, 255);
Color4 colour = new Color4(r, g, b, a);
if (isCombo)
{