1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 05:42:56 +08:00

Merge pull request #13408 from peppy/default-skin-fallback

Add fallback lookup support for `DefaultSkin`
This commit is contained in:
Dan Balasescu 2021-06-10 16:37:48 +09:00 committed by GitHub
commit 4eab717a80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,6 +50,8 @@ namespace osu.Game.Skinning
private readonly Skin defaultLegacySkin; private readonly Skin defaultLegacySkin;
private readonly Skin defaultSkin;
public SkinManager(Storage storage, DatabaseContextFactory contextFactory, GameHost host, IResourceStore<byte[]> resources, AudioManager audio) public SkinManager(Storage storage, DatabaseContextFactory contextFactory, GameHost host, IResourceStore<byte[]> resources, AudioManager audio)
: base(storage, contextFactory, new SkinStore(contextFactory, storage), host) : base(storage, contextFactory, new SkinStore(contextFactory, storage), host)
{ {
@ -58,10 +60,11 @@ namespace osu.Game.Skinning
this.resources = resources; this.resources = resources;
defaultLegacySkin = new DefaultLegacySkin(this); defaultLegacySkin = new DefaultLegacySkin(this);
defaultSkin = new DefaultSkin(this);
CurrentSkinInfo.ValueChanged += skin => CurrentSkin.Value = GetSkin(skin.NewValue); CurrentSkinInfo.ValueChanged += skin => CurrentSkin.Value = GetSkin(skin.NewValue);
CurrentSkin.Value = new DefaultSkin(this); CurrentSkin.Value = defaultSkin;
CurrentSkin.ValueChanged += skin => CurrentSkin.ValueChanged += skin =>
{ {
if (skin.NewValue.SkinInfo != CurrentSkinInfo.Value) if (skin.NewValue.SkinInfo != CurrentSkinInfo.Value)
@ -226,24 +229,26 @@ namespace osu.Game.Skinning
if (CurrentSkin.Value is LegacySkin && lookupFunction(defaultLegacySkin)) if (CurrentSkin.Value is LegacySkin && lookupFunction(defaultLegacySkin))
return defaultLegacySkin; return defaultLegacySkin;
if (lookupFunction(defaultSkin))
return defaultSkin;
return null; return null;
} }
private T lookupWithFallback<T>(Func<ISkin, T> func) private T lookupWithFallback<T>(Func<ISkin, T> lookupFunction)
where T : class where T : class
{ {
var selectedSkin = func(CurrentSkin.Value); if (lookupFunction(CurrentSkin.Value) is T skinSourced)
return skinSourced;
if (selectedSkin != null)
return selectedSkin;
// TODO: we also want to return a DefaultLegacySkin here if the current *beatmap* is providing any skinned elements. // TODO: we also want to return a DefaultLegacySkin here if the current *beatmap* is providing any skinned elements.
// When attempting to address this, we may want to move the full DefaultLegacySkin fallback logic to within Player itself (to better allow // When attempting to address this, we may want to move the full DefaultLegacySkin fallback logic to within Player itself (to better allow
// for beatmap skin visibility). // for beatmap skin visibility).
if (CurrentSkin.Value is LegacySkin) if (CurrentSkin.Value is LegacySkin && lookupFunction(defaultLegacySkin) is T legacySourced)
return func(defaultLegacySkin); return legacySourced;
return null; // Finally fall back to the (non-legacy) default.
return lookupFunction(defaultSkin);
} }
#region IResourceStorageProvider #region IResourceStorageProvider