1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 14:12:55 +08:00

Move FindProvider to ISkinSource

This commit is contained in:
Dean Herbert 2021-06-06 11:08:54 +09:00
parent ae2165b3be
commit 39f99bf785
6 changed files with 18 additions and 33 deletions

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using JetBrains.Annotations;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
@ -58,13 +57,5 @@ namespace osu.Game.Skinning
/// <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>
/// Find the first (if any) 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);
}
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using JetBrains.Annotations;
namespace osu.Game.Skinning
{
@ -11,5 +12,13 @@ namespace osu.Game.Skinning
public interface ISkinSource : ISkin
{
event Action SourceChanged;
/// <summary>
/// Find the first (if any) 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);
}
}

View File

@ -54,9 +54,6 @@ namespace osu.Game.Skinning
private readonly Dictionary<int, LegacyManiaSkinConfiguration> maniaConfigurations = new Dictionary<int, LegacyManiaSkinConfiguration>();
[CanBeNull]
private readonly DefaultLegacySkin legacyDefaultFallback;
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedWithFixedConstructorSignature)]
public LegacySkin(SkinInfo skin, IStorageResourceProvider resources)
: this(skin, new LegacySkinResourceStore<SkinFileInfo>(skin, resources.Files), resources, "skin.ini")
@ -73,9 +70,6 @@ namespace osu.Game.Skinning
protected LegacySkin(SkinInfo skin, [CanBeNull] IResourceStore<byte[]> storage, [CanBeNull] IStorageResourceProvider resources, string configurationFilename)
: base(skin, resources)
{
if (resources != null)
legacyDefaultFallback = CreateFallbackSkin(storage, resources);
using (var stream = storage?.GetStream(configurationFilename))
{
if (stream != null)
@ -158,7 +152,7 @@ namespace osu.Game.Skinning
return genericLookup<TLookup, TValue>(lookup);
}
return legacyDefaultFallback?.GetConfig<TLookup, TValue>(lookup);
return null;
}
private IBindable<TValue> lookupForMania<TValue>(LegacyManiaSkinConfigurationLookup maniaLookup)
@ -335,7 +329,7 @@ namespace osu.Game.Skinning
{
}
return legacyDefaultFallback?.GetConfig<TLookup, TValue>(lookup);
return null;
}
public override Drawable GetDrawableComponent(ISkinComponent component)
@ -406,6 +400,7 @@ namespace osu.Game.Skinning
return null;
case GameplaySkinComponent<HitResult> resultComponent:
// TODO: this should be inside the judgement pieces.
Func<Drawable> createDrawable = () => getJudgementAnimation(resultComponent.Component);
// kind of wasteful that we throw this away, but should do for now.
@ -427,7 +422,7 @@ namespace osu.Game.Skinning
if (animation != null)
return animation;
return legacyDefaultFallback?.GetDrawableComponent(component);
return null;
}
private Texture getParticleTexture(HitResult result)
@ -487,7 +482,7 @@ namespace osu.Game.Skinning
return texture;
}
return legacyDefaultFallback?.GetTexture(componentName, wrapModeS, wrapModeT);
return null;
}
public override ISample GetSample(ISampleInfo sampleInfo)
@ -511,17 +506,7 @@ namespace osu.Game.Skinning
}
}
return legacyDefaultFallback?.GetSample(sampleInfo);
}
public override ISkin FindProvider(Func<ISkin, bool> lookupFunction)
{
var source = base.FindProvider(lookupFunction);
if (source != null)
return source;
return legacyDefaultFallback?.FindProvider(lookupFunction);
return null;
}
private IEnumerable<string> getLegacyLookupNames(HitSampleInfo hitSample)

View File

@ -35,8 +35,6 @@ namespace osu.Game.Skinning
public abstract IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup);
public virtual ISkin FindProvider(Func<ISkin, bool> lookupFunction) => lookupFunction(this) ? this : null;
protected Skin(SkinInfo skin, IStorageResourceProvider resources)
{
SkinInfo = skin;

View File

@ -212,7 +212,7 @@ namespace osu.Game.Skinning
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => CurrentSkin.Value.GetConfig<TLookup, TValue>(lookup);
public ISkin FindProvider(Func<ISkin, bool> lookupFunction) => CurrentSkin.Value.FindProvider(lookupFunction);
public ISkin FindProvider(Func<ISkin, bool> lookupFunction) => lookupFunction(CurrentSkin.Value) ? CurrentSkin.Value : null;
#region IResourceStorageProvider

View File

@ -158,6 +158,8 @@ namespace osu.Game.Tests.Beatmaps
add { }
remove { }
}
public ISkin FindProvider(Func<ISkin, bool> lookupFunction) => null;
}
}
}