mirror of
https://github.com/ppy/osu.git
synced 2024-11-12 07:38:21 +08:00
Merge pull request #8496 from smoogipoo/mania-skin-decoder
Add mania skin decoder
This commit is contained in:
commit
a231dbd670
9
osu.Game.Tests/Resources/mania-skin-duplicate.ini
Normal file
9
osu.Game.Tests/Resources/mania-skin-duplicate.ini
Normal file
@ -0,0 +1,9 @@
|
||||
[Mania]
|
||||
Keys: 4
|
||||
ColumnWidth: 10,10,10,10
|
||||
HitPosition: 470
|
||||
|
||||
[Mania]
|
||||
Keys: 4
|
||||
ColumnWidth: 20,20,20,20
|
||||
HitPosition: 460
|
4
osu.Game.Tests/Resources/mania-skin-extra-data.ini
Normal file
4
osu.Game.Tests/Resources/mania-skin-extra-data.ini
Normal file
@ -0,0 +1,4 @@
|
||||
[Mania]
|
||||
Keys: 4
|
||||
ColumnWidth: 10,10,10,10,10,10,10
|
||||
HitPosition: 470
|
9
osu.Game.Tests/Resources/mania-skin-multiple.ini
Normal file
9
osu.Game.Tests/Resources/mania-skin-multiple.ini
Normal file
@ -0,0 +1,9 @@
|
||||
[Mania]
|
||||
Keys: 4
|
||||
ColumnWidth: 10,10,10,10
|
||||
HitPosition: 470
|
||||
|
||||
[Mania]
|
||||
Keys: 2
|
||||
ColumnWidth: 20,20
|
||||
HitPosition: 460
|
4
osu.Game.Tests/Resources/mania-skin-single.ini
Normal file
4
osu.Game.Tests/Resources/mania-skin-single.ini
Normal file
@ -0,0 +1,4 @@
|
||||
[Mania]
|
||||
Keys: 4
|
||||
ColumnWidth: 10,10,10,10
|
||||
HitPosition: 470
|
87
osu.Game.Tests/Skins/LegacyManiaSkinDecoderTest.cs
Normal file
87
osu.Game.Tests/Skins/LegacyManiaSkinDecoderTest.cs
Normal file
@ -0,0 +1,87 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using NUnit.Framework;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.Skinning;
|
||||
using osu.Game.Tests.Resources;
|
||||
|
||||
namespace osu.Game.Tests.Skins
|
||||
{
|
||||
[TestFixture]
|
||||
public class LegacyManiaSkinDecoderTest
|
||||
{
|
||||
[Test]
|
||||
public void TestParseSingleConfig()
|
||||
{
|
||||
var decoder = new LegacyManiaSkinDecoder();
|
||||
|
||||
using (var resStream = TestResources.OpenResource("mania-skin-single.ini"))
|
||||
using (var stream = new LineBufferedReader(resStream))
|
||||
{
|
||||
var configs = decoder.Decode(stream);
|
||||
|
||||
Assert.That(configs.Count, Is.EqualTo(1));
|
||||
Assert.That(configs[0].Keys, Is.EqualTo(4));
|
||||
Assert.That(configs[0].ColumnWidth, Is.EquivalentTo(new float[] { 16, 16, 16, 16 }));
|
||||
Assert.That(configs[0].HitPosition, Is.EqualTo(16));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestParseMultipleConfig()
|
||||
{
|
||||
var decoder = new LegacyManiaSkinDecoder();
|
||||
|
||||
using (var resStream = TestResources.OpenResource("mania-skin-multiple.ini"))
|
||||
using (var stream = new LineBufferedReader(resStream))
|
||||
{
|
||||
var configs = decoder.Decode(stream);
|
||||
|
||||
Assert.That(configs.Count, Is.EqualTo(2));
|
||||
|
||||
Assert.That(configs[0].Keys, Is.EqualTo(4));
|
||||
Assert.That(configs[0].ColumnWidth, Is.EquivalentTo(new float[] { 16, 16, 16, 16 }));
|
||||
Assert.That(configs[0].HitPosition, Is.EqualTo(16));
|
||||
|
||||
Assert.That(configs[1].Keys, Is.EqualTo(2));
|
||||
Assert.That(configs[1].ColumnWidth, Is.EquivalentTo(new float[] { 32, 32 }));
|
||||
Assert.That(configs[1].HitPosition, Is.EqualTo(32));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestParseDuplicateConfig()
|
||||
{
|
||||
var decoder = new LegacyManiaSkinDecoder();
|
||||
|
||||
using (var resStream = TestResources.OpenResource("mania-skin-single.ini"))
|
||||
using (var stream = new LineBufferedReader(resStream))
|
||||
{
|
||||
var configs = decoder.Decode(stream);
|
||||
|
||||
Assert.That(configs.Count, Is.EqualTo(1));
|
||||
Assert.That(configs[0].Keys, Is.EqualTo(4));
|
||||
Assert.That(configs[0].ColumnWidth, Is.EquivalentTo(new float[] { 16, 16, 16, 16 }));
|
||||
Assert.That(configs[0].HitPosition, Is.EqualTo(16));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestParseWithUnnecessaryExtraData()
|
||||
{
|
||||
var decoder = new LegacyManiaSkinDecoder();
|
||||
|
||||
using (var resStream = TestResources.OpenResource("mania-skin-extra-data.ini"))
|
||||
using (var stream = new LineBufferedReader(resStream))
|
||||
{
|
||||
var configs = decoder.Decode(stream);
|
||||
|
||||
Assert.That(configs.Count, Is.EqualTo(1));
|
||||
Assert.That(configs[0].Keys, Is.EqualTo(4));
|
||||
Assert.That(configs[0].ColumnWidth, Is.EquivalentTo(new float[] { 16, 16, 16, 16 }));
|
||||
Assert.That(configs[0].HitPosition, Is.EqualTo(16));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -41,6 +41,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
section = Section.None;
|
||||
}
|
||||
|
||||
OnBeginNewSection(section);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -57,6 +58,14 @@ namespace osu.Game.Beatmaps.Formats
|
||||
|
||||
protected virtual bool ShouldSkipLine(string line) => string.IsNullOrWhiteSpace(line) || line.AsSpan().TrimStart().StartsWith("//".AsSpan(), StringComparison.Ordinal);
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a new <see cref="Section"/> has been entered.
|
||||
/// </summary>
|
||||
/// <param name="section">The entered <see cref="Section"/>.</param>
|
||||
protected virtual void OnBeginNewSection(Section section)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void ParseLine(T output, Section section, string line)
|
||||
{
|
||||
line = StripComments(line);
|
||||
@ -139,7 +148,8 @@ namespace osu.Game.Beatmaps.Formats
|
||||
Colours,
|
||||
HitObjects,
|
||||
Variables,
|
||||
Fonts
|
||||
Fonts,
|
||||
Mania
|
||||
}
|
||||
|
||||
internal class LegacyDifficultyControlPoint : DifficultyControlPoint
|
||||
|
30
osu.Game/Skinning/LegacyManiaSkinConfiguration.cs
Normal file
30
osu.Game/Skinning/LegacyManiaSkinConfiguration.cs
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
public class LegacyManiaSkinConfiguration
|
||||
{
|
||||
public readonly int Keys;
|
||||
|
||||
public readonly float[] ColumnLineWidth;
|
||||
public readonly float[] ColumnSpacing;
|
||||
public readonly float[] ColumnWidth;
|
||||
|
||||
public float HitPosition = 124.8f; // (480 - 402) * 1.6f
|
||||
|
||||
public LegacyManiaSkinConfiguration(int keys)
|
||||
{
|
||||
Keys = keys;
|
||||
|
||||
ColumnLineWidth = new float[keys + 1];
|
||||
ColumnSpacing = new float[keys - 1];
|
||||
ColumnWidth = new float[keys];
|
||||
|
||||
ColumnLineWidth.AsSpan().Fill(2);
|
||||
ColumnWidth.AsSpan().Fill(48);
|
||||
}
|
||||
}
|
||||
}
|
110
osu.Game/Skinning/LegacyManiaSkinDecoder.cs
Normal file
110
osu.Game/Skinning/LegacyManiaSkinDecoder.cs
Normal file
@ -0,0 +1,110 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
public class LegacyManiaSkinDecoder : LegacyDecoder<List<LegacyManiaSkinConfiguration>>
|
||||
{
|
||||
private const float size_scale_factor = 1.6f;
|
||||
|
||||
public LegacyManiaSkinDecoder()
|
||||
: base(1)
|
||||
{
|
||||
}
|
||||
|
||||
private readonly List<string> pendingLines = new List<string>();
|
||||
private LegacyManiaSkinConfiguration currentConfig;
|
||||
|
||||
protected override void OnBeginNewSection(Section section)
|
||||
{
|
||||
base.OnBeginNewSection(section);
|
||||
|
||||
// If a new section is reached with pending lines remaining, they can all be discarded as there isn't a valid configuration to parse them into.
|
||||
pendingLines.Clear();
|
||||
currentConfig = null;
|
||||
}
|
||||
|
||||
protected override void ParseLine(List<LegacyManiaSkinConfiguration> output, Section section, string line)
|
||||
{
|
||||
line = StripComments(line);
|
||||
|
||||
switch (section)
|
||||
{
|
||||
case Section.Mania:
|
||||
var pair = SplitKeyVal(line);
|
||||
|
||||
switch (pair.Key)
|
||||
{
|
||||
case "Keys":
|
||||
currentConfig = new LegacyManiaSkinConfiguration(int.Parse(pair.Value, CultureInfo.InvariantCulture));
|
||||
|
||||
// Silently ignore duplicate configurations.
|
||||
if (output.All(c => c.Keys != currentConfig.Keys))
|
||||
output.Add(currentConfig);
|
||||
|
||||
// All existing lines can be flushed now that we have a valid configuration.
|
||||
flushPendingLines();
|
||||
break;
|
||||
|
||||
default:
|
||||
pendingLines.Add(line);
|
||||
|
||||
// Hold all lines until a "Keys" item is found.
|
||||
if (currentConfig != null)
|
||||
flushPendingLines();
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void flushPendingLines()
|
||||
{
|
||||
Debug.Assert(currentConfig != null);
|
||||
|
||||
foreach (var line in pendingLines)
|
||||
{
|
||||
var pair = SplitKeyVal(line);
|
||||
|
||||
switch (pair.Key)
|
||||
{
|
||||
case "ColumnLineWidth":
|
||||
parseArrayValue(pair.Value, currentConfig.ColumnLineWidth);
|
||||
break;
|
||||
|
||||
case "ColumnSpacing":
|
||||
parseArrayValue(pair.Value, currentConfig.ColumnSpacing);
|
||||
break;
|
||||
|
||||
case "ColumnWidth":
|
||||
parseArrayValue(pair.Value, currentConfig.ColumnWidth);
|
||||
break;
|
||||
|
||||
case "HitPosition":
|
||||
currentConfig.HitPosition = (480 - float.Parse(pair.Value, CultureInfo.InvariantCulture)) * size_scale_factor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseArrayValue(string value, float[] output)
|
||||
{
|
||||
string[] values = value.Split(',');
|
||||
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
{
|
||||
if (i >= output.Length)
|
||||
break;
|
||||
|
||||
output[i] = float.Parse(values[i], CultureInfo.InvariantCulture) * size_scale_factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user