diff --git a/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs index 4b52051707..d5b9e46183 100644 --- a/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs @@ -1,6 +1,7 @@ using System; using System.IO; using NUnit.Framework; +using OpenTK.Graphics; using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Samples; using osu.Game.GameModes.Play; @@ -95,5 +96,27 @@ namespace osu.Game.Tests.Beatmaps.Formats Assert.AreEqual(2, difficulty.SliderTickRate); } } + + [Test] + public void TestDecodeColors() + { + var decoder = new OsuLegacyDecoder(); + using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) + { + var beatmap = decoder.Decode(new StreamReader(stream)); + Color4[] expected = + { + new Color4(142, 199, 255, 255), + new Color4(255, 128, 128, 255), + new Color4(128, 255, 255, 255), + new Color4(128, 255, 128, 255), + new Color4(255, 187, 255, 255), + new Color4(255, 177, 140, 255), + }; + Assert.AreEqual(expected.Length, beatmap.ComboColors.Count); + for (int i = 0; i < expected.Length; i++) + Assert.AreEqual(expected[i], beatmap.ComboColors[i]); + } + } } } \ No newline at end of file diff --git a/osu.Game.Tests/OpenTK.dll.config b/osu.Game.Tests/OpenTK.dll.config new file mode 100644 index 0000000000..5620e3d9e2 --- /dev/null +++ b/osu.Game.Tests/OpenTK.dll.config @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/osu.Game.Tests/osu.Game.Tests.csproj b/osu.Game.Tests/osu.Game.Tests.csproj index d61d98434a..36044b4bbf 100644 --- a/osu.Game.Tests/osu.Game.Tests.csproj +++ b/osu.Game.Tests/osu.Game.Tests.csproj @@ -31,9 +31,15 @@ ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + + ..\packages\ppy.OpenTK.1.1.2225.3\lib\net20\OpenTK.dll + + + + diff --git a/osu.Game.Tests/packages.config b/osu.Game.Tests/packages.config index c714ef3a23..46387efcc6 100644 --- a/osu.Game.Tests/packages.config +++ b/osu.Game.Tests/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index c1f3d7f744..99199e421c 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; +using OpenTK.Graphics; using osu.Game.Beatmaps.Objects; using osu.Game.Beatmaps.Samples; using osu.Game.Beatmaps.Timing; @@ -29,6 +30,8 @@ namespace osu.Game.Beatmaps public BeatmapMetadata Metadata { get; set; } [Ignore] public BaseDifficulty BaseDifficulty { get; set; } + [Ignore] + public List ComboColors { get; set; } // General public int AudioLeadIn { get; set; } diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 1a3ea5a53e..e900038120 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using OpenTK.Graphics; using osu.Game.Beatmaps.Events; using osu.Game.Beatmaps.Objects; using osu.Game.Beatmaps.Samples; @@ -180,6 +181,24 @@ namespace osu.Game.Beatmaps.Formats // TODO } + private void HandleColours(Beatmap beatmap, string key, string val) + { + string[] split = val.Split(','); + if (split.Length != 3) + throw new InvalidOperationException($@"Color specified in incorrect format (should be R,G,B): {val}"); + byte r, g, b; + if (!byte.TryParse(split[0], out r) || !byte.TryParse(split[1], out g) || !byte.TryParse(split[2], out b)) + throw new InvalidOperationException($@"Color must be specified with 8-bit integer components"); + // Note: the combo index specified in the beatmap is discarded + beatmap.ComboColors.Add(new Color4 + { + R = r / 255f, + G = g / 255f, + B = b / 255f, + A = 1f, + }); + } + public override Beatmap Decode(TextReader stream) { var beatmap = new Beatmap @@ -188,6 +207,7 @@ namespace osu.Game.Beatmaps.Formats BaseDifficulty = new BaseDifficulty(), HitObjects = new List(), ControlPoints = new List(), + ComboColors = new List(), }; var section = Section.None; string line; @@ -210,8 +230,7 @@ namespace osu.Game.Beatmaps.Formats } string val = line, key = null; - if (section != Section.Events && section != Section.TimingPoints - && section != Section.HitObjects) + if (section != Section.Events && section != Section.TimingPoints && section != Section.HitObjects) { key = val.Remove(val.IndexOf(':')).Trim(); val = val.Substring(val.IndexOf(':') + 1).Trim(); @@ -236,6 +255,9 @@ namespace osu.Game.Beatmaps.Formats case Section.TimingPoints: HandleTimingPoints(beatmap, val); break; + case Section.Colours: + HandleColours(beatmap, key, val); + break; case Section.HitObjects: beatmap.HitObjects.Add(HitObject.Parse(beatmap.Mode, val)); break;