2018-02-22 16:16:48 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2018-03-05 20:27:37 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2018-02-22 16:16:48 +08:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
using osu.Framework.IO.Stores;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
|
{
|
|
|
|
|
public class LegacySkin : Skin
|
|
|
|
|
{
|
|
|
|
|
private readonly TextureStore textures;
|
|
|
|
|
|
|
|
|
|
private readonly SampleManager samples;
|
|
|
|
|
|
|
|
|
|
public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager)
|
|
|
|
|
: base(skin)
|
|
|
|
|
{
|
2018-03-05 20:27:37 +08:00
|
|
|
|
storage = new LegacySkinResourceStore(skin, storage);
|
2018-02-23 13:24:32 +08:00
|
|
|
|
samples = audioManager.GetSampleManager(storage);
|
2018-02-22 16:16:48 +08:00
|
|
|
|
textures = new TextureStore(new RawTextureLoaderStore(storage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Drawable GetDrawableComponent(string componentName)
|
|
|
|
|
{
|
2018-03-04 02:17:11 +08:00
|
|
|
|
var texture = textures.Get(componentName);
|
2018-02-22 16:16:48 +08:00
|
|
|
|
if (texture == null) return null;
|
|
|
|
|
|
2018-03-07 17:20:20 +08:00
|
|
|
|
return new Sprite { Texture = texture };
|
2018-02-22 16:16:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-04 02:17:11 +08:00
|
|
|
|
public override SampleChannel GetSample(string sampleName) => samples.Get(sampleName);
|
2018-03-05 20:27:37 +08:00
|
|
|
|
|
|
|
|
|
private class LegacySkinResourceStore : IResourceStore<byte[]>
|
|
|
|
|
{
|
|
|
|
|
private readonly SkinInfo skin;
|
|
|
|
|
private readonly IResourceStore<byte[]> underlyingStore;
|
|
|
|
|
|
|
|
|
|
private string getPathForFile(string filename) =>
|
2018-03-07 17:20:20 +08:00
|
|
|
|
skin.Files.FirstOrDefault(f => string.Equals(Path.GetFileNameWithoutExtension(f.Filename), filename.Split('/').Last(), StringComparison.InvariantCultureIgnoreCase))?.FileInfo
|
|
|
|
|
.StoragePath;
|
2018-03-05 20:27:37 +08:00
|
|
|
|
|
|
|
|
|
public LegacySkinResourceStore(SkinInfo skin, IResourceStore<byte[]> underlyingStore)
|
|
|
|
|
{
|
|
|
|
|
this.skin = skin;
|
|
|
|
|
this.underlyingStore = underlyingStore;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Stream GetStream(string name) => underlyingStore.GetStream(getPathForFile(name));
|
|
|
|
|
|
|
|
|
|
byte[] IResourceStore<byte[]>.Get(string name) => underlyingStore.Get(getPathForFile(name));
|
|
|
|
|
}
|
2018-02-22 16:16:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|