mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 21:02:54 +08:00
Merge pull request #6450 from iiSaLMaN/add-access-to-skin-legacy-version
Add access to numerical version of legacy skin
This commit is contained in:
commit
0e98dd5a1c
2
osu.Game.Tests/Resources/skin-20.ini
Normal file
2
osu.Game.Tests/Resources/skin-20.ini
Normal file
@ -0,0 +1,2 @@
|
||||
[General]
|
||||
Version: 2
|
2
osu.Game.Tests/Resources/skin-latest.ini
Normal file
2
osu.Game.Tests/Resources/skin-latest.ini
Normal file
@ -0,0 +1,2 @@
|
||||
[General]
|
||||
Version: latest
|
@ -59,5 +59,32 @@ namespace osu.Game.Tests.Skins
|
||||
Assert.AreEqual("TestValue", config.ConfigDictionary["TestLookup"]);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDecodeSpecifiedVersion()
|
||||
{
|
||||
var decoder = new LegacySkinDecoder();
|
||||
using (var resStream = TestResources.OpenResource("skin-20.ini"))
|
||||
using (var stream = new LineBufferedReader(resStream))
|
||||
Assert.AreEqual(2.0m, decoder.Decode(stream).LegacyVersion);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDecodeLatestVersion()
|
||||
{
|
||||
var decoder = new LegacySkinDecoder();
|
||||
using (var resStream = TestResources.OpenResource("skin-latest.ini"))
|
||||
using (var stream = new LineBufferedReader(resStream))
|
||||
Assert.AreEqual(LegacySkinConfiguration.LATEST_VERSION, decoder.Decode(stream).LegacyVersion);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDecodeNoVersion()
|
||||
{
|
||||
var decoder = new LegacySkinDecoder();
|
||||
using (var resStream = TestResources.OpenResource("skin-empty.ini"))
|
||||
using (var stream = new LineBufferedReader(resStream))
|
||||
Assert.IsNull(decoder.Decode(stream).LegacyVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,6 +116,14 @@ namespace osu.Game.Tests.Skins
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLegacyVersionLookup()
|
||||
{
|
||||
AddStep("Set source1 version 2.3", () => source1.Configuration.LegacyVersion = 2.3m);
|
||||
AddStep("Set source2 version null", () => source2.Configuration.LegacyVersion = null);
|
||||
AddAssert("Check legacy version lookup", () => requester.GetConfig<LegacySkinConfiguration.LegacySetting, decimal>(LegacySkinConfiguration.LegacySetting.Version)?.Value == 2.3m);
|
||||
}
|
||||
|
||||
public enum LookupType
|
||||
{
|
||||
Test
|
||||
|
@ -20,6 +20,8 @@ namespace osu.Game.Skinning
|
||||
new Color4(18, 124, 255, 255),
|
||||
new Color4(242, 24, 57, 255),
|
||||
});
|
||||
|
||||
Configuration.LegacyVersion = 2.0m;
|
||||
}
|
||||
|
||||
public static SkinInfo Info { get; } = new SkinInfo
|
||||
|
@ -26,6 +26,12 @@ namespace osu.Game.Skinning
|
||||
[CanBeNull]
|
||||
protected IResourceStore<SampleChannel> Samples;
|
||||
|
||||
public new LegacySkinConfiguration Configuration
|
||||
{
|
||||
get => base.Configuration as LegacySkinConfiguration;
|
||||
set => base.Configuration = value;
|
||||
}
|
||||
|
||||
public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager)
|
||||
: this(skin, new LegacySkinResourceStore<SkinFileInfo>(skin, storage), audioManager, "skin.ini")
|
||||
{
|
||||
@ -42,7 +48,7 @@ namespace osu.Game.Skinning
|
||||
Configuration = new LegacySkinDecoder().Decode(reader);
|
||||
}
|
||||
else
|
||||
Configuration = new DefaultSkinConfiguration();
|
||||
Configuration = new LegacySkinConfiguration { LegacyVersion = LegacySkinConfiguration.LATEST_VERSION };
|
||||
|
||||
if (storage != null)
|
||||
{
|
||||
@ -74,6 +80,18 @@ namespace osu.Game.Skinning
|
||||
case GlobalSkinColour colour:
|
||||
return SkinUtils.As<TValue>(getCustomColour(colour.ToString()));
|
||||
|
||||
case LegacySkinConfiguration.LegacySetting legacy:
|
||||
switch (legacy)
|
||||
{
|
||||
case LegacySkinConfiguration.LegacySetting.Version:
|
||||
if (Configuration.LegacyVersion is decimal version)
|
||||
return SkinUtils.As<TValue>(new Bindable<decimal>(version));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SkinCustomColourLookup customColour:
|
||||
return SkinUtils.As<TValue>(getCustomColour(customColour.Lookup.ToString()));
|
||||
|
||||
|
20
osu.Game/Skinning/LegacySkinConfiguration.cs
Normal file
20
osu.Game/Skinning/LegacySkinConfiguration.cs
Normal file
@ -0,0 +1,20 @@
|
||||
// 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.
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
public class LegacySkinConfiguration : DefaultSkinConfiguration
|
||||
{
|
||||
public const decimal LATEST_VERSION = 2.7m;
|
||||
|
||||
/// <summary>
|
||||
/// Legacy version of this skin.
|
||||
/// </summary>
|
||||
public decimal? LegacyVersion { get; internal set; }
|
||||
|
||||
public enum LegacySetting
|
||||
{
|
||||
Version,
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +1,19 @@
|
||||
// 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.Globalization;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
public class LegacySkinDecoder : LegacyDecoder<DefaultSkinConfiguration>
|
||||
public class LegacySkinDecoder : LegacyDecoder<LegacySkinConfiguration>
|
||||
{
|
||||
public LegacySkinDecoder()
|
||||
: base(1)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void ParseLine(DefaultSkinConfiguration skin, Section section, string line)
|
||||
protected override void ParseLine(LegacySkinConfiguration skin, Section section, string line)
|
||||
{
|
||||
if (section != Section.Colours)
|
||||
{
|
||||
@ -32,6 +33,14 @@ namespace osu.Game.Skinning
|
||||
case @"Author":
|
||||
skin.SkinInfo.Creator = pair.Value;
|
||||
return;
|
||||
|
||||
case @"Version":
|
||||
if (pair.Value == "latest")
|
||||
skin.LegacyVersion = LegacySkinConfiguration.LATEST_VERSION;
|
||||
else if (decimal.TryParse(pair.Value, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var version))
|
||||
skin.LegacyVersion = version;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user