1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-25 05:39:57 +08:00

Add ability for LegacySkins to customise the fallback provider

This commit is contained in:
Dean Herbert
2021-05-31 17:09:30 +09:00
Unverified
parent 88ed95e012
commit 8e489754cc
2 changed files with 20 additions and 8 deletions
+2
View File
@@ -31,6 +31,8 @@ namespace osu.Game.Skinning
Configuration.LegacyVersion = 2.7m;
}
protected override DefaultLegacySkin CreateFallbackSkin(IResourceStore<byte[]> storage, IStorageResourceProvider resources) => null;
public static SkinInfo Info { get; } = new SkinInfo
{
ID = SkinInfo.CLASSIC_SKIN, // this is temporary until database storage is decided upon.
+18 -8
View File
@@ -24,7 +24,7 @@ using osuTK.Graphics;
namespace osu.Game.Skinning
{
public class LegacySkin : Skin
public class LegacySkin : Skin, ISkin
{
private readonly bool fallbackToDefault;
@@ -56,6 +56,7 @@ namespace osu.Game.Skinning
private readonly Dictionary<int, LegacyManiaSkinConfiguration> maniaConfigurations = new Dictionary<int, LegacyManiaSkinConfiguration>();
[CanBeNull]
private readonly DefaultLegacySkin legacyDefaultFallback;
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedWithFixedConstructorSignature)]
@@ -71,12 +72,12 @@ namespace osu.Game.Skinning
/// <param name="storage">A storage for looking up files within this skin using user-facing filenames.</param>
/// <param name="resources">Access to raw game resources.</param>
/// <param name="configurationFilename">The user-facing filename of the configuration file to be parsed. Can accept an .osu or skin.ini file.</param>
/// <param name="fallbackToDefault">Whether lookups should fallback to the <see cref="DefaultLegacySkin"/> implementations if not provided locally.</param>
/// <param name="fallbackToDefault">Whether lookups via <see cref="ISkin.FindProvider"/> fallback to the <see cref="DefaultLegacySkin"/> implementations if not provided locally.</param>
protected LegacySkin(SkinInfo skin, [CanBeNull] IResourceStore<byte[]> storage, [CanBeNull] IStorageResourceProvider resources, string configurationFilename, bool fallbackToDefault = false)
: base(skin, resources)
{
this.fallbackToDefault = fallbackToDefault;
legacyDefaultFallback = new DefaultLegacySkin(storage, resources);
legacyDefaultFallback = CreateFallbackSkin(storage, resources);
using (var stream = storage?.GetStream(configurationFilename))
{
@@ -117,6 +118,10 @@ namespace osu.Game.Skinning
true) != null);
}
[CanBeNull]
protected virtual DefaultLegacySkin CreateFallbackSkin(IResourceStore<byte[]> storage, IStorageResourceProvider resources) =>
new DefaultLegacySkin(storage, resources);
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
{
switch (lookup)
@@ -157,7 +162,7 @@ namespace osu.Game.Skinning
return genericLookup<TLookup, TValue>(lookup);
}
return fallbackToDefault ? legacyDefaultFallback.GetConfig<TLookup, TValue>(lookup) : null;
return legacyDefaultFallback?.GetConfig<TLookup, TValue>(lookup);
}
private IBindable<TValue> lookupForMania<TValue>(LegacyManiaSkinConfigurationLookup maniaLookup)
@@ -334,7 +339,7 @@ namespace osu.Game.Skinning
{
}
return fallbackToDefault ? legacyDefaultFallback.GetConfig<TLookup, TValue>(lookup) : null;
return legacyDefaultFallback?.GetConfig<TLookup, TValue>(lookup);
}
public override Drawable GetDrawableComponent(ISkinComponent component)
@@ -434,7 +439,12 @@ namespace osu.Game.Skinning
break;
}
return this.GetAnimation(component.LookupName, false, false);
var animation = this.GetAnimation(component.LookupName, false, false);
if (animation != null)
return animation;
return legacyDefaultFallback?.GetDrawableComponent(component);
}
private Texture getParticleTexture(HitResult result)
@@ -494,7 +504,7 @@ namespace osu.Game.Skinning
return texture;
}
return null;
return legacyDefaultFallback?.GetTexture(componentName, wrapModeS, wrapModeT);
}
public override ISample GetSample(ISampleInfo sampleInfo)
@@ -516,7 +526,7 @@ namespace osu.Game.Skinning
return sample;
}
return fallbackToDefault ? legacyDefaultFallback.GetSample(sampleInfo) : null;
return legacyDefaultFallback?.GetSample(sampleInfo);
}
private IEnumerable<string> getLegacyLookupNames(HitSampleInfo hitSample)