mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 02:27:19 +08:00
Decode beatmap colours
This commit is contained in:
parent
41292cb5db
commit
8f32284c0d
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using OpenTK.Graphics;
|
||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
using osu.Game.Beatmaps.Samples;
|
using osu.Game.Beatmaps.Samples;
|
||||||
using osu.Game.GameModes.Play;
|
using osu.Game.GameModes.Play;
|
||||||
@ -95,5 +96,27 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
Assert.AreEqual(2, difficulty.SliderTickRate);
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
25
osu.Game.Tests/OpenTK.dll.config
Normal file
25
osu.Game.Tests/OpenTK.dll.config
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<configuration>
|
||||||
|
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1"/>
|
||||||
|
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1"/>
|
||||||
|
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1"/>
|
||||||
|
<dllmap os="linux" dll="alut.dll" target="libalut.so.0"/>
|
||||||
|
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so"/>
|
||||||
|
<dllmap os="linux" dll="libX11" target="libX11.so.6"/>
|
||||||
|
<dllmap os="linux" dll="libXi" target="libXi.so.6"/>
|
||||||
|
<dllmap os="linux" dll="SDL2.dll" target="libSDL2-2.0.so.0"/>
|
||||||
|
<dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL"/>
|
||||||
|
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
||||||
|
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
||||||
|
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||||
|
<dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||||
|
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||||
|
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
|
||||||
|
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib"/>
|
||||||
|
<!-- XQuartz compatibility (X11 on Mac) -->
|
||||||
|
<dllmap os="osx" dll="libGL.so.1" target="/usr/X11/lib/libGL.dylib"/>
|
||||||
|
<dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib"/>
|
||||||
|
<dllmap os="osx" dll="libXcursor.so.1" target="/usr/X11/lib/libXcursor.dylib"/>
|
||||||
|
<dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib"/>
|
||||||
|
<dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib"/>
|
||||||
|
<dllmap os="osx" dll="libXrandr.so.2" target="/usr/X11/lib/libXrandr.dylib"/>
|
||||||
|
</configuration>
|
@ -31,9 +31,15 @@
|
|||||||
<Reference Include="nunit.framework">
|
<Reference Include="nunit.framework">
|
||||||
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
|
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="OpenTK">
|
||||||
|
<HintPath>..\packages\ppy.OpenTK.1.1.2225.3\lib\net20\OpenTK.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
<None Include="OpenTK.dll.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\osu.Game\osu.Game.csproj">
|
<ProjectReference Include="..\osu.Game\osu.Game.csproj">
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="NUnit" version="2.6.4" targetFramework="net45" />
|
<package id="NUnit" version="2.6.4" targetFramework="net45" />
|
||||||
|
<package id="ppy.OpenTK" version="1.1.2225.3" targetFramework="net45" />
|
||||||
</packages>
|
</packages>
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenTK.Graphics;
|
||||||
using osu.Game.Beatmaps.Objects;
|
using osu.Game.Beatmaps.Objects;
|
||||||
using osu.Game.Beatmaps.Samples;
|
using osu.Game.Beatmaps.Samples;
|
||||||
using osu.Game.Beatmaps.Timing;
|
using osu.Game.Beatmaps.Timing;
|
||||||
@ -29,6 +30,8 @@ namespace osu.Game.Beatmaps
|
|||||||
public BeatmapMetadata Metadata { get; set; }
|
public BeatmapMetadata Metadata { get; set; }
|
||||||
[Ignore]
|
[Ignore]
|
||||||
public BaseDifficulty BaseDifficulty { get; set; }
|
public BaseDifficulty BaseDifficulty { get; set; }
|
||||||
|
[Ignore]
|
||||||
|
public List<Color4> ComboColors { get; set; }
|
||||||
|
|
||||||
// General
|
// General
|
||||||
public int AudioLeadIn { get; set; }
|
public int AudioLeadIn { get; set; }
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using OpenTK.Graphics;
|
||||||
using osu.Game.Beatmaps.Events;
|
using osu.Game.Beatmaps.Events;
|
||||||
using osu.Game.Beatmaps.Objects;
|
using osu.Game.Beatmaps.Objects;
|
||||||
using osu.Game.Beatmaps.Samples;
|
using osu.Game.Beatmaps.Samples;
|
||||||
@ -180,6 +181,24 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
// TODO
|
// 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)
|
public override Beatmap Decode(TextReader stream)
|
||||||
{
|
{
|
||||||
var beatmap = new Beatmap
|
var beatmap = new Beatmap
|
||||||
@ -188,6 +207,7 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
BaseDifficulty = new BaseDifficulty(),
|
BaseDifficulty = new BaseDifficulty(),
|
||||||
HitObjects = new List<HitObject>(),
|
HitObjects = new List<HitObject>(),
|
||||||
ControlPoints = new List<ControlPoint>(),
|
ControlPoints = new List<ControlPoint>(),
|
||||||
|
ComboColors = new List<Color4>(),
|
||||||
};
|
};
|
||||||
var section = Section.None;
|
var section = Section.None;
|
||||||
string line;
|
string line;
|
||||||
@ -210,8 +230,7 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
string val = line, key = null;
|
string val = line, key = null;
|
||||||
if (section != Section.Events && section != Section.TimingPoints
|
if (section != Section.Events && section != Section.TimingPoints && section != Section.HitObjects)
|
||||||
&& section != Section.HitObjects)
|
|
||||||
{
|
{
|
||||||
key = val.Remove(val.IndexOf(':')).Trim();
|
key = val.Remove(val.IndexOf(':')).Trim();
|
||||||
val = val.Substring(val.IndexOf(':') + 1).Trim();
|
val = val.Substring(val.IndexOf(':') + 1).Trim();
|
||||||
@ -236,6 +255,9 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
case Section.TimingPoints:
|
case Section.TimingPoints:
|
||||||
HandleTimingPoints(beatmap, val);
|
HandleTimingPoints(beatmap, val);
|
||||||
break;
|
break;
|
||||||
|
case Section.Colours:
|
||||||
|
HandleColours(beatmap, key, val);
|
||||||
|
break;
|
||||||
case Section.HitObjects:
|
case Section.HitObjects:
|
||||||
beatmap.HitObjects.Add(HitObject.Parse(beatmap.Mode, val));
|
beatmap.HitObjects.Add(HitObject.Parse(beatmap.Mode, val));
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user