Fix `FindProvider` not correctly checking legacy default in `SkinManager`

This commit is contained in:
Dean Herbert 2021-06-08 00:42:50 +09:00
parent 273d66a0e0
commit e7e9197f03
1 changed files with 13 additions and 4 deletions

View File

@ -48,6 +48,8 @@ public class SkinManager : ArchiveModelManager<SkinInfo, SkinFileInfo>, ISkinSou
protected override string ImportFromStablePath => "Skins";
private readonly Skin defaultLegacySkin;
public SkinManager(Storage storage, DatabaseContextFactory contextFactory, GameHost host, IResourceStore<byte[]> resources, AudioManager audio)
: base(storage, contextFactory, new SkinStore(contextFactory, storage), host)
{
@ -55,6 +57,8 @@ public SkinManager(Storage storage, DatabaseContextFactory contextFactory, GameH
this.host = host;
this.resources = resources;
defaultLegacySkin = new DefaultLegacySkin(this);
CurrentSkinInfo.ValueChanged += skin => CurrentSkin.Value = GetSkin(skin.NewValue);
CurrentSkin.ValueChanged += skin =>
{
@ -212,9 +216,16 @@ public void Save(Skin skin)
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => lookupWithFallback(s => s.GetConfig<TLookup, TValue>(lookup));
public ISkin FindProvider(Func<ISkin, bool> lookupFunction) => lookupFunction(CurrentSkin.Value) ? CurrentSkin.Value : null;
public ISkin FindProvider(Func<ISkin, bool> lookupFunction)
{
if (lookupFunction(CurrentSkin.Value))
return CurrentSkin.Value;
private Skin defaultLegacySkin;
if (CurrentSkin.Value is LegacySkin && lookupFunction(defaultLegacySkin))
return defaultLegacySkin;
return null;
}
private T lookupWithFallback<T>(Func<ISkin, T> func)
where T : class
@ -224,8 +235,6 @@ private T lookupWithFallback<T>(Func<ISkin, T> func)
if (selectedSkin != null)
return selectedSkin;
defaultLegacySkin ??= new DefaultLegacySkin(this);
if (CurrentSkin.Value is LegacySkin)
return func(defaultLegacySkin);