2021-06-10 21:25:19 +00:00
|
|
|
// 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.
|
|
|
|
|
2021-06-23 06:41:45 +00:00
|
|
|
using System;
|
2021-06-10 21:25:19 +00:00
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
using osu.Framework.IO.Stores;
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Game.Audio;
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
{
|
|
|
|
/// <summary>
|
2021-06-24 07:07:38 +00:00
|
|
|
/// An <see cref="ISkin"/> that uses an underlying <see cref="IResourceStore{T}"/> with namespaces for resources retrieval.
|
2021-06-10 21:25:19 +00:00
|
|
|
/// </summary>
|
2021-06-28 06:18:29 +00:00
|
|
|
public class ResourceStoreBackedSkin : ISkin, IDisposable
|
2021-06-10 21:25:19 +00:00
|
|
|
{
|
2021-06-24 07:07:38 +00:00
|
|
|
private readonly TextureStore textures;
|
|
|
|
private readonly ISampleStore samples;
|
2021-06-10 21:25:19 +00:00
|
|
|
|
2021-06-28 06:18:29 +00:00
|
|
|
public ResourceStoreBackedSkin(IResourceStore<byte[]> resources, GameHost host, AudioManager audio)
|
2021-06-10 21:25:19 +00:00
|
|
|
{
|
2022-08-02 10:50:57 +00:00
|
|
|
textures = new TextureStore(host.Renderer, host.CreateTextureLoaderStore(new NamespacedResourceStore<byte[]>(resources, @"Textures")));
|
2021-06-24 07:07:38 +00:00
|
|
|
samples = audio.GetSampleStore(new NamespacedResourceStore<byte[]>(resources, @"Samples"));
|
2021-06-10 21:25:19 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 07:04:56 +00:00
|
|
|
public Drawable? GetDrawableComponent(ISkinComponentLookup lookup) => null;
|
2021-06-10 21:25:19 +00:00
|
|
|
|
2021-06-24 07:07:38 +00:00
|
|
|
public Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => textures.Get(componentName, wrapModeS, wrapModeT);
|
2021-06-10 21:25:19 +00:00
|
|
|
|
2021-06-23 06:52:00 +00:00
|
|
|
public ISample? GetSample(ISampleInfo sampleInfo)
|
2021-06-10 21:25:19 +00:00
|
|
|
{
|
2021-10-27 04:04:41 +00:00
|
|
|
foreach (string? lookup in sampleInfo.LookupNames)
|
2021-06-10 21:25:19 +00:00
|
|
|
{
|
2021-06-24 07:07:38 +00:00
|
|
|
ISample? sample = samples.Get(lookup);
|
2021-06-10 21:25:19 +00:00
|
|
|
if (sample != null)
|
|
|
|
return sample;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-03-25 06:53:55 +00:00
|
|
|
public IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup)
|
|
|
|
where TLookup : notnull
|
|
|
|
where TValue : notnull
|
|
|
|
=> null;
|
2021-06-23 06:41:45 +00:00
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
2021-06-24 07:07:38 +00:00
|
|
|
textures.Dispose();
|
|
|
|
samples.Dispose();
|
2021-06-23 06:41:45 +00:00
|
|
|
}
|
2021-06-10 21:25:19 +00:00
|
|
|
}
|
|
|
|
}
|