2019-08-21 14:11:33 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
using osu.Framework.IO.Stores;
|
2019-08-23 19:32:43 +08:00
|
|
|
using osu.Game.Audio;
|
2019-07-30 22:06:18 +08:00
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
{
|
|
|
|
public class LegacySkin : Skin
|
|
|
|
{
|
|
|
|
protected TextureStore Textures;
|
|
|
|
|
2019-05-28 22:54:42 +08:00
|
|
|
protected IResourceStore<SampleChannel> Samples;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager)
|
|
|
|
: this(skin, new LegacySkinResourceStore<SkinFileInfo>(skin, storage), audioManager, "skin.ini")
|
|
|
|
{
|
2019-08-21 12:56:49 +08:00
|
|
|
// defaults should only be applied for non-beatmap skins (which are parsed via this constructor).
|
2019-08-20 14:02:07 +08:00
|
|
|
if (!Configuration.CustomColours.ContainsKey("SliderBall")) Configuration.CustomColours["SliderBall"] = new Color4(2, 170, 255, 255);
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
2019-02-28 12:31:40 +08:00
|
|
|
protected LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager, string filename)
|
|
|
|
: base(skin)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
Stream stream = storage.GetStream(filename);
|
|
|
|
if (stream != null)
|
|
|
|
using (StreamReader reader = new StreamReader(stream))
|
|
|
|
Configuration = new LegacySkinDecoder().Decode(reader);
|
|
|
|
else
|
|
|
|
Configuration = new SkinConfiguration();
|
|
|
|
|
2019-05-28 16:06:01 +08:00
|
|
|
Samples = audioManager.GetSampleStore(storage);
|
2018-09-07 17:56:08 +08:00
|
|
|
Textures = new TextureStore(new TextureLoaderStore(storage));
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
2019-05-28 22:54:42 +08:00
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
Textures?.Dispose();
|
|
|
|
Samples?.Dispose();
|
|
|
|
}
|
|
|
|
|
2019-08-30 13:39:02 +08:00
|
|
|
public override Drawable GetDrawableComponent(ISkinComponent component)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-08-30 13:39:02 +08:00
|
|
|
switch (component.LookupName)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
case "Play/Miss":
|
2019-08-30 13:39:02 +08:00
|
|
|
return this.GetAnimation("hit0", true, false);
|
2019-04-01 11:16:05 +08:00
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
case "Play/Meh":
|
2019-08-30 13:39:02 +08:00
|
|
|
return this.GetAnimation("hit50", true, false);
|
2019-04-01 11:16:05 +08:00
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
case "Play/Good":
|
2019-08-30 13:39:02 +08:00
|
|
|
return this.GetAnimation("hit100", true, false);
|
2019-04-01 11:16:05 +08:00
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
case "Play/Great":
|
2019-08-30 13:39:02 +08:00
|
|
|
return this.GetAnimation("hit300", true, false);
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
2019-08-30 13:39:02 +08:00
|
|
|
return this.GetAnimation(component.LookupName, false, false);
|
2019-08-19 18:23:54 +08:00
|
|
|
}
|
|
|
|
|
2019-08-27 16:18:32 +08:00
|
|
|
public override Texture GetTexture(string componentName)
|
|
|
|
{
|
|
|
|
componentName = getFallbackName(componentName);
|
|
|
|
|
|
|
|
float ratio = 2;
|
|
|
|
var texture = Textures.Get($"{componentName}@2x");
|
|
|
|
|
|
|
|
if (texture == null)
|
|
|
|
{
|
|
|
|
ratio = 1;
|
|
|
|
texture = Textures.Get(componentName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (texture != null)
|
|
|
|
texture.ScaleAdjust = ratio;
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2019-08-23 19:32:43 +08:00
|
|
|
public override SampleChannel GetSample(ISampleInfo sampleInfo)
|
2019-08-22 17:50:47 +08:00
|
|
|
{
|
2019-08-23 19:32:43 +08:00
|
|
|
foreach (var lookup in sampleInfo.LookupNames)
|
2019-08-22 17:50:47 +08:00
|
|
|
{
|
2019-08-28 01:06:17 +08:00
|
|
|
var sample = Samples.Get(getFallbackName(lookup));
|
2019-08-23 19:32:43 +08:00
|
|
|
|
|
|
|
if (sample != null)
|
|
|
|
return sample;
|
2019-08-22 17:50:47 +08:00
|
|
|
}
|
|
|
|
|
2019-08-23 19:32:43 +08:00
|
|
|
if (sampleInfo is HitSampleInfo hsi)
|
|
|
|
// Try fallback to non-bank samples.
|
2019-08-24 14:30:43 +08:00
|
|
|
return Samples.Get(hsi.Name);
|
2019-08-23 19:32:43 +08:00
|
|
|
|
|
|
|
return null;
|
2019-08-22 17:50:47 +08:00
|
|
|
}
|
2019-08-27 16:18:32 +08:00
|
|
|
|
|
|
|
private string getFallbackName(string componentName)
|
|
|
|
{
|
|
|
|
string lastPiece = componentName.Split('/').Last();
|
|
|
|
return componentName.StartsWith("Gameplay/taiko/") ? "taiko-" + lastPiece : lastPiece;
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|