mirror of https://github.com/ppy/osu
Add `FindProvider` lookup function
This commit is contained in:
parent
1d30791ab0
commit
88ed95e012
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue