Add `FindProvider` lookup function

This commit is contained in:
Dean Herbert 2021-05-31 17:04:38 +09:00
parent 1d30791ab0
commit 88ed95e012
5 changed files with 31 additions and 4 deletions

View File

@ -69,10 +69,10 @@ public ManiaLegacySkinTransformer(ISkinSource source, IBeatmap beatmap)
private void sourceChanged()
{
isLegacySkin = new Lazy<bool>(() => Source.GetConfig<LegacySkinConfiguration.LegacySetting, decimal>(LegacySkinConfiguration.LegacySetting.Version) != null);
hasKeyTexture = new Lazy<bool>(() => Source.GetAnimation(
isLegacySkin = new Lazy<bool>(() => Source.FindProvider(s => s.GetConfig<LegacySkinConfiguration.LegacySetting, decimal>(LegacySkinConfiguration.LegacySetting.Version) != null) != null);
hasKeyTexture = new Lazy<bool>(() => Source.FindProvider(s => s.GetAnimation(
this.GetManiaSkinConfig<string>(LegacyManiaSkinConfigurationLookups.KeyImage, 0)?.Value
?? "mania-key1", true, true) != null);
?? "mania-key1", true, true) != null) != null);
}
public override Drawable GetDrawableComponent(ISkinComponent component)

View File

@ -29,7 +29,7 @@ public OsuLegacySkinTransformer(ISkinSource source)
private void sourceChanged()
{
hasHitCircle = new Lazy<bool>(() => Source.GetTexture("hitcircle") != null);
hasHitCircle = new Lazy<bool>(Source.FindProvider(s => s.GetTexture("hitcircle") != null) != null);
}
public override Drawable GetDrawableComponent(ISkinComponent component)

View File

@ -57,5 +57,13 @@ public interface ISkin
/// <returns>A matching value boxed in an <see cref="IBindable{TValue}"/>, or null if unavailable.</returns>
[CanBeNull]
IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup);
/// <summary>
/// For the specified texture, find any potential skin that can fulfill the lookup.
/// This should be used for cases where subsequent lookups (for related components) need to occur on the same skin.
/// </summary>
/// <returns>The skin to be used for subsequent lookups, or <c>null</c> if none is available.</returns>
[CanBeNull]
ISkin FindProvider(Func<ISkin, bool> lookupFunction) => lookupFunction(this) ? this : null;
}
}

View File

@ -556,5 +556,16 @@ protected override void Dispose(bool isDisposing)
Textures?.Dispose();
Samples?.Dispose();
}
ISkin ISkin.FindProvider(Func<ISkin, bool> lookupFunction)
{
if (lookupFunction(this))
return this;
if (!fallbackToDefault)
return null;
return (legacyDefaultFallback as ISkin)?.FindProvider(lookupFunction);
}
}
}

View File

@ -41,6 +41,14 @@ public SkinProvidingContainer(ISkin skin)
RelativeSizeAxes = Axes.Both;
}
public ISkin FindProvider(Func<ISkin, bool> lookupFunction)
{
if (lookupFunction(skin))
return skin;
return fallbackSource.FindProvider(lookupFunction);
}
public Drawable GetDrawableComponent(ISkinComponent component)
{
Drawable sourceDrawable;