1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 03:02:54 +08:00

Convert RulesetResourcesSkin to plain ResourcesSkin and pass non-null resources

This commit is contained in:
Salman Ahmed 2021-06-24 10:07:38 +03:00
parent d484469906
commit a98b5618b8
2 changed files with 25 additions and 23 deletions

View File

@ -13,38 +13,32 @@ using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores; using osu.Framework.IO.Stores;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Rulesets;
namespace osu.Game.Skinning namespace osu.Game.Skinning
{ {
/// <summary> /// <summary>
/// An <see cref="ISkin"/> providing the resources of the ruleset for accessibility during lookups. /// An <see cref="ISkin"/> that uses an underlying <see cref="IResourceStore{T}"/> with namespaces for resources retrieval.
/// </summary> /// </summary>
public class RulesetResourcesSkin : ISkin public class ResourcesSkin : ISkin
{ {
private readonly TextureStore? textures; private readonly TextureStore textures;
private readonly ISampleStore? samples; private readonly ISampleStore samples;
public RulesetResourcesSkin(Ruleset ruleset, GameHost host, AudioManager audio) public ResourcesSkin(IResourceStore<byte[]> resources, GameHost host, AudioManager audio)
{ {
IResourceStore<byte[]>? resources = ruleset.CreateResourceStore(); textures = new TextureStore(host.CreateTextureLoaderStore(new NamespacedResourceStore<byte[]>(resources, @"Textures")));
samples = audio.GetSampleStore(new NamespacedResourceStore<byte[]>(resources, @"Samples"));
if (resources != null)
{
textures = new TextureStore(host.CreateTextureLoaderStore(new NamespacedResourceStore<byte[]>(resources, @"Textures")));
samples = audio.GetSampleStore(new NamespacedResourceStore<byte[]>(resources, @"Samples"));
}
} }
public Drawable? GetDrawableComponent(ISkinComponent component) => null; public Drawable? GetDrawableComponent(ISkinComponent component) => null;
public Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => textures?.Get(componentName, wrapModeS, wrapModeT); public Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => textures.Get(componentName, wrapModeS, wrapModeT);
public ISample? GetSample(ISampleInfo sampleInfo) public ISample? GetSample(ISampleInfo sampleInfo)
{ {
foreach (var lookup in sampleInfo.LookupNames) foreach (var lookup in sampleInfo.LookupNames)
{ {
ISample? sample = samples?.Get(lookup); ISample? sample = samples.Get(lookup);
if (sample != null) if (sample != null)
return sample; return sample;
} }
@ -56,7 +50,7 @@ namespace osu.Game.Skinning
#region Disposal #region Disposal
~RulesetResourcesSkin() ~ResourcesSkin()
{ {
// required to potentially clean up sample store from audio hierarchy. // required to potentially clean up sample store from audio hierarchy.
Dispose(false); Dispose(false);
@ -77,8 +71,8 @@ namespace osu.Game.Skinning
isDisposed = true; isDisposed = true;
textures?.Dispose(); textures.Dispose();
samples?.Dispose(); samples.Dispose();
} }
#endregion #endregion

View File

@ -6,6 +6,7 @@ using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.IO.Stores;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets; using osu.Game.Rulesets;
@ -87,11 +88,18 @@ namespace osu.Game.Skinning
} }
} }
var defaultSkinIndex = SkinSources.IndexOf(skinManager.DefaultSkin); if (Ruleset.CreateResourceStore() is IResourceStore<byte[]> resources)
if (defaultSkinIndex >= 0) {
SkinSources.Insert(defaultSkinIndex, new RulesetResourcesSkin(Ruleset, host, audio)); int defaultSkinIndex = SkinSources.IndexOf(skinManager.DefaultSkin);
else
SkinSources.Add(new RulesetResourcesSkin(Ruleset, host, audio)); if (defaultSkinIndex >= 0)
SkinSources.Insert(defaultSkinIndex, new ResourcesSkin(resources, host, audio));
else
{
// Tests may potentially override the SkinManager with another source that doesn't include it in AllSources.
SkinSources.Add(new ResourcesSkin(resources, host, audio));
}
}
} }
protected ISkin GetLegacyRulesetTransformedSkin(ISkin legacySkin) protected ISkin GetLegacyRulesetTransformedSkin(ISkin legacySkin)