From cb1703c6e2181cd2ada72d90dba67c874d068887 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 5 Oct 2018 11:19:01 +0900 Subject: [PATCH 1/3] Fix colours with alpha components not being parsed --- .../Beatmaps/Formats/LegacyBeatmapDecoderTest.cs | 3 ++- .../Resources/Soleily - Renatus (Gamu) [Insane].osu | 1 + osu.Game/Beatmaps/Formats/LegacyDecoder.cs | 13 +++++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs index d3351f86f8..af63a39662 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs @@ -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++) diff --git a/osu.Game.Tests/Resources/Soleily - Renatus (Gamu) [Insane].osu b/osu.Game.Tests/Resources/Soleily - Renatus (Gamu) [Insane].osu index 3e44dc0af8..67570ad21b 100644 --- a/osu.Game.Tests/Resources/Soleily - Renatus (Gamu) [Insane].osu +++ b/osu.Game.Tests/Resources/Soleily - Renatus (Gamu) [Insane].osu @@ -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: diff --git a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs index e9f37e583b..7ac88dfc5b 100644 --- a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs @@ -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) { From 40c17cfa5a504577e1c1c119b4970f76d880c67c Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 5 Oct 2018 11:55:59 +0900 Subject: [PATCH 2/3] Remove ugly if-statement --- osu.Game/Beatmaps/Formats/LegacyDecoder.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs index 7ac88dfc5b..222f3589dc 100644 --- a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs @@ -88,16 +88,17 @@ namespace osu.Game.Beatmaps.Formats 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}"); - byte a = 255; + Color4 colour; - 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)) + try + { + colour = new Color4(byte.Parse(split[0]), byte.Parse(split[1]), byte.Parse(split[2]), split.Length == 4 ? byte.Parse(split[3]) : 255); + } + catch (Exception e) { throw new InvalidOperationException(@"Color must be specified with 8-bit integer components"); } - Color4 colour = new Color4(r, g, b, a); - if (isCombo) { if (!(output is IHasComboColours tHasComboColours)) return; From 794501cc5a5297dff081c69eaf87e4a3e1a9ce2b Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 5 Oct 2018 12:06:24 +0900 Subject: [PATCH 3/3] Fix incorrect result of ternary --- osu.Game/Beatmaps/Formats/LegacyDecoder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs index 222f3589dc..a9e1e4c55d 100644 --- a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs @@ -92,7 +92,7 @@ namespace osu.Game.Beatmaps.Formats try { - colour = new Color4(byte.Parse(split[0]), byte.Parse(split[1]), byte.Parse(split[2]), split.Length == 4 ? byte.Parse(split[3]) : 255); + colour = new Color4(byte.Parse(split[0]), byte.Parse(split[1]), byte.Parse(split[2]), split.Length == 4 ? byte.Parse(split[3]) : (byte)255); } catch (Exception e) {