Make versionless skins fallback to version 1.0

This commit is contained in:
smoogipoo 2020-04-06 19:36:04 +09:00
parent 8438ee7e07
commit a4208f35c4
4 changed files with 25 additions and 6 deletions

View File

@ -106,7 +106,7 @@ public void TestDecodeNoVersion()
var decoder = new LegacySkinDecoder(); var decoder = new LegacySkinDecoder();
using (var resStream = TestResources.OpenResource("skin-empty.ini")) using (var resStream = TestResources.OpenResource("skin-empty.ini"))
using (var stream = new LineBufferedReader(resStream)) using (var stream = new LineBufferedReader(resStream))
Assert.IsNull(decoder.Decode(stream).LegacyVersion); Assert.That(decoder.Decode(stream).LegacyVersion, Is.EqualTo(1.0m));
} }
} }
} }

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.IO.Stores; using osu.Framework.IO.Stores;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -18,6 +19,20 @@ public LegacyBeatmapSkin(BeatmapInfo beatmap, IResourceStore<byte[]> storage, Au
Configuration.AllowDefaultComboColoursFallback = false; Configuration.AllowDefaultComboColoursFallback = false;
} }
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
{
switch (lookup)
{
case LegacySkinConfiguration.LegacySetting s when s == LegacySkinConfiguration.LegacySetting.Version:
if (Configuration.LegacyVersion is decimal version)
return SkinUtils.As<TValue>(new Bindable<decimal>(version));
return null;
}
return base.GetConfig<TLookup, TValue>(lookup);
}
private static SkinInfo createSkinInfo(BeatmapInfo beatmap) => private static SkinInfo createSkinInfo(BeatmapInfo beatmap) =>
new SkinInfo { Name = beatmap.ToString(), Creator = beatmap.Metadata.Author.ToString() }; new SkinInfo { Name = beatmap.ToString(), Creator = beatmap.Metadata.Author.ToString() };
} }

View File

@ -71,7 +71,7 @@ protected LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager
} }
} }
else else
Configuration = new LegacySkinConfiguration { LegacyVersion = LegacySkinConfiguration.LATEST_VERSION }; Configuration = new LegacySkinConfiguration();
} }
if (storage != null) if (storage != null)
@ -122,10 +122,7 @@ public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
switch (legacy) switch (legacy)
{ {
case LegacySkinConfiguration.LegacySetting.Version: case LegacySkinConfiguration.LegacySetting.Version:
if (Configuration.LegacyVersion is decimal version) return SkinUtils.As<TValue>(new Bindable<decimal>(Configuration.LegacyVersion ?? LegacySkinConfiguration.LATEST_VERSION));
return SkinUtils.As<TValue>(new Bindable<decimal>(version));
break;
} }
break; break;

View File

@ -52,5 +52,12 @@ protected override void ParseLine(LegacySkinConfiguration skin, Section section,
base.ParseLine(skin, section, line); base.ParseLine(skin, section, line);
} }
protected override LegacySkinConfiguration CreateTemplateObject()
{
var config = base.CreateTemplateObject();
config.LegacyVersion = 1.0m;
return config;
}
} }
} }