1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 20:13:20 +08:00

Add skin providing ruleset resources in RulesetSkinProvidingContainer

This commit is contained in:
Salman Ahmed 2021-06-11 00:25:19 +03:00
parent 2240e2c39c
commit 169c98f963
2 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,51 @@
// 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 osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.OpenGL.Textures;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using osu.Framework.Platform;
using osu.Game.Audio;
using osu.Game.Rulesets;
namespace osu.Game.Skinning
{
/// <summary>
/// An <see cref="ISkin"/> providing the resources of the ruleset for accessibility during lookups.
/// </summary>
public class RulesetResourcesSkin : ISkin
{
private readonly TextureStore rulesetTextures;
private readonly ISampleStore rulesetSamples;
public RulesetResourcesSkin(Ruleset ruleset, GameHost host, AudioManager audio)
{
IResourceStore<byte[]> rulesetResources = ruleset.CreateResourceStore();
rulesetTextures = new TextureStore(host.CreateTextureLoaderStore(new NamespacedResourceStore<byte[]>(rulesetResources, @"Textures")));
rulesetSamples = audio.GetSampleStore(new NamespacedResourceStore<byte[]>(rulesetResources, @"Samples"));
}
public Drawable GetDrawableComponent(ISkinComponent component) => null;
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => rulesetTextures.Get(componentName, wrapModeS, wrapModeT);
public ISample GetSample(ISampleInfo sampleInfo)
{
foreach (var lookup in sampleInfo.LookupNames)
{
ISample sample = rulesetSamples.Get(lookup);
if (sample != null)
return sample;
}
return null;
}
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => null;
}
}

View File

@ -3,8 +3,10 @@
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
@ -35,6 +37,12 @@ namespace osu.Game.Skinning
};
}
[Resolved]
private GameHost host { get; set; }
[Resolved]
private AudioManager audio { get; set; }
[Resolved]
private SkinManager skinManager { get; set; }
@ -60,6 +68,8 @@ namespace osu.Game.Skinning
SkinSources.Add(Ruleset.CreateLegacySkinProvider(skinManager.DefaultLegacySkin, Beatmap));
SkinSources.Add(Ruleset.CreateLegacySkinProvider(skinManager.DefaultSkin, Beatmap));
SkinSources.Add(new RulesetResourcesSkin(Ruleset, host, audio));
}
}
}