1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 04:53:12 +08:00

Expose as Skins and consume SkinInfo from instances

This commit is contained in:
Dean Herbert 2021-06-11 14:49:35 +09:00
parent 2240e2c39c
commit b9050f91a4

View File

@ -48,19 +48,15 @@ namespace osu.Game.Skinning
protected override string ImportFromStablePath => "Skins"; protected override string ImportFromStablePath => "Skins";
private readonly Skin defaultSkin;
/// <summary> /// <summary>
/// An <see cref="ISkin"/> providing the resources of the default skin. /// An <see cref="ISkin"/> providing the resources of the default skin.
/// </summary> /// </summary>
public ISkin DefaultSkin => defaultSkin; public Skin DefaultSkin { get; }
private readonly Skin defaultLegacySkin;
/// <summary> /// <summary>
/// An <see cref="ISkin"/> providing the resources of the default legacy skin. /// An <see cref="ISkin"/> providing the resources of the default legacy skin.
/// </summary> /// </summary>
public ISkin DefaultLegacySkin => defaultLegacySkin; public Skin DefaultLegacySkin { get; }
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)
@ -69,12 +65,12 @@ namespace osu.Game.Skinning
this.host = host; this.host = host;
this.resources = resources; this.resources = resources;
defaultLegacySkin = new DefaultLegacySkin(this); DefaultLegacySkin = new DefaultLegacySkin(this);
defaultSkin = new DefaultSkin(this); DefaultSkin = new DefaultSkin(this);
CurrentSkinInfo.ValueChanged += skin => CurrentSkin.Value = GetSkin(skin.NewValue); CurrentSkinInfo.ValueChanged += skin => CurrentSkin.Value = GetSkin(skin.NewValue);
CurrentSkin.Value = defaultSkin; CurrentSkin.Value = DefaultSkin;
CurrentSkin.ValueChanged += skin => CurrentSkin.ValueChanged += skin =>
{ {
if (skin.NewValue.SkinInfo != CurrentSkinInfo.Value) if (skin.NewValue.SkinInfo != CurrentSkinInfo.Value)
@ -93,8 +89,8 @@ namespace osu.Game.Skinning
public List<SkinInfo> GetAllUsableSkins() public List<SkinInfo> GetAllUsableSkins()
{ {
var userSkins = GetAllUserSkins(); var userSkins = GetAllUserSkins();
userSkins.Insert(0, SkinInfo.Default); userSkins.Insert(0, DefaultSkin.SkinInfo);
userSkins.Insert(1, Skinning.DefaultLegacySkin.Info); userSkins.Insert(1, DefaultLegacySkin.SkinInfo);
return userSkins; return userSkins;
} }
@ -236,11 +232,11 @@ namespace osu.Game.Skinning
if (lookupFunction(CurrentSkin.Value)) if (lookupFunction(CurrentSkin.Value))
return CurrentSkin.Value; return CurrentSkin.Value;
if (CurrentSkin.Value is LegacySkin && lookupFunction(defaultLegacySkin)) if (CurrentSkin.Value is LegacySkin && lookupFunction(DefaultLegacySkin))
return defaultLegacySkin; return DefaultLegacySkin;
if (lookupFunction(defaultSkin)) if (lookupFunction(DefaultSkin))
return defaultSkin; return DefaultSkin;
return null; return null;
} }
@ -254,11 +250,11 @@ namespace osu.Game.Skinning
// 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 && lookupFunction(defaultLegacySkin) is T legacySourced) if (CurrentSkin.Value is LegacySkin && lookupFunction(DefaultLegacySkin) is T legacySourced)
return legacySourced; return legacySourced;
// Finally fall back to the (non-legacy) default. // Finally fall back to the (non-legacy) default.
return lookupFunction(defaultSkin); return lookupFunction(DefaultSkin);
} }
#region IResourceStorageProvider #region IResourceStorageProvider