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
|
|
|
|
2019-09-03 16:57:34 +08:00
|
|
|
using System.Collections.Generic;
|
2018-04-13 17:19:50 +08:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2019-09-04 14:59:09 +08:00
|
|
|
using JetBrains.Annotations;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
2019-09-03 16:57:34 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
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-09-10 06:43:30 +08:00
|
|
|
using osu.Game.IO;
|
2019-08-30 14:12:03 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
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
|
|
|
|
{
|
2019-09-04 14:59:09 +08:00
|
|
|
[CanBeNull]
|
2018-04-13 17:19:50 +08:00
|
|
|
protected TextureStore Textures;
|
|
|
|
|
2019-09-04 14:59:09 +08:00
|
|
|
[CanBeNull]
|
2019-05-28 22:54:42 +08:00
|
|
|
protected IResourceStore<SampleChannel> Samples;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-11-24 09:10:04 +08:00
|
|
|
public new LegacySkinConfiguration Configuration
|
2019-11-20 06:15:40 +08:00
|
|
|
{
|
|
|
|
get => base.Configuration as LegacySkinConfiguration;
|
|
|
|
set => base.Configuration = value;
|
|
|
|
}
|
2019-10-10 04:04:34 +08:00
|
|
|
|
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-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
|
|
|
{
|
2019-09-04 12:29:55 +08:00
|
|
|
Stream stream = storage?.GetStream(filename);
|
2019-11-11 20:05:36 +08:00
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
if (stream != null)
|
2019-11-11 19:53:22 +08:00
|
|
|
{
|
2019-09-10 06:43:30 +08:00
|
|
|
using (LineBufferedReader reader = new LineBufferedReader(stream))
|
2018-04-13 17:19:50 +08:00
|
|
|
Configuration = new LegacySkinDecoder().Decode(reader);
|
2019-11-11 19:53:22 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
else
|
2019-11-20 06:15:40 +08:00
|
|
|
Configuration = new LegacySkinConfiguration { LegacyVersion = LegacySkinConfiguration.LATEST_VERSION };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-09-04 14:59:09 +08:00
|
|
|
if (storage != null)
|
|
|
|
{
|
|
|
|
Samples = audioManager?.GetSampleStore(storage);
|
|
|
|
Textures = new TextureStore(new TextureLoaderStore(storage));
|
2020-02-18 12:21:55 +08:00
|
|
|
|
|
|
|
(storage as ResourceStore<byte[]>)?.AddExtension("ogg");
|
2019-09-04 14:59:09 +08:00
|
|
|
}
|
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-09-03 16:57:34 +08:00
|
|
|
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
|
|
|
|
{
|
|
|
|
switch (lookup)
|
|
|
|
{
|
2020-02-07 13:58:07 +08:00
|
|
|
case GlobalSkinColours colour:
|
|
|
|
switch (colour)
|
2019-09-03 16:57:34 +08:00
|
|
|
{
|
2020-02-07 13:58:07 +08:00
|
|
|
case GlobalSkinColours.ComboColours:
|
2019-11-07 04:20:36 +08:00
|
|
|
var comboColours = Configuration.ComboColours;
|
|
|
|
if (comboColours != null)
|
2019-11-07 20:54:30 +08:00
|
|
|
return SkinUtils.As<TValue>(new Bindable<IReadOnlyList<Color4>>(comboColours));
|
2019-10-10 02:08:07 +08:00
|
|
|
|
|
|
|
break;
|
2020-02-07 13:58:07 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
return SkinUtils.As<TValue>(getCustomColour(colour.ToString()));
|
2019-09-03 16:57:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2019-11-20 14:40:35 +08:00
|
|
|
case LegacySkinConfiguration.LegacySetting legacy:
|
2019-10-10 04:04:34 +08:00
|
|
|
switch (legacy)
|
|
|
|
{
|
2019-11-20 14:40:35 +08:00
|
|
|
case LegacySkinConfiguration.LegacySetting.Version:
|
2019-11-07 01:46:02 +08:00
|
|
|
if (Configuration.LegacyVersion is decimal version)
|
|
|
|
return SkinUtils.As<TValue>(new Bindable<decimal>(version));
|
2019-10-10 04:04:34 +08:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2019-09-03 16:57:34 +08:00
|
|
|
case SkinCustomColourLookup customColour:
|
2019-09-05 15:39:58 +08:00
|
|
|
return SkinUtils.As<TValue>(getCustomColour(customColour.Lookup.ToString()));
|
2019-09-03 16:57:34 +08:00
|
|
|
|
|
|
|
default:
|
2020-02-07 13:58:07 +08:00
|
|
|
// handles lookups like GlobalSkinConfiguration
|
|
|
|
|
2019-09-03 16:57:34 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (Configuration.ConfigDictionary.TryGetValue(lookup.ToString(), out var val))
|
|
|
|
{
|
2019-09-04 12:29:55 +08:00
|
|
|
// special case for handling skins which use 1 or 0 to signify a boolean state.
|
|
|
|
if (typeof(TValue) == typeof(bool))
|
|
|
|
val = val == "1" ? "true" : "false";
|
|
|
|
|
2019-09-03 16:57:34 +08:00
|
|
|
var bindable = new Bindable<TValue>();
|
2019-09-04 12:30:46 +08:00
|
|
|
if (val != null)
|
|
|
|
bindable.Parse(val);
|
2019-09-03 16:57:34 +08:00
|
|
|
return bindable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private IBindable<Color4> getCustomColour(string lookup) => Configuration.CustomColours.TryGetValue(lookup, out var col) ? new Bindable<Color4>(col) : null;
|
|
|
|
|
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 14:12:03 +08:00
|
|
|
switch (component)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-08-30 14:10:11 +08:00
|
|
|
case GameplaySkinComponent<HitResult> resultComponent:
|
2019-08-30 14:12:03 +08:00
|
|
|
switch (resultComponent.Component)
|
|
|
|
{
|
|
|
|
case HitResult.Miss:
|
|
|
|
return this.GetAnimation("hit0", true, false);
|
2019-04-01 11:16:05 +08:00
|
|
|
|
2019-08-30 14:12:03 +08:00
|
|
|
case HitResult.Meh:
|
|
|
|
return this.GetAnimation("hit50", true, false);
|
2019-04-01 11:16:05 +08:00
|
|
|
|
2019-08-30 14:12:03 +08:00
|
|
|
case HitResult.Good:
|
|
|
|
return this.GetAnimation("hit100", true, false);
|
2019-04-01 11:16:05 +08:00
|
|
|
|
2019-08-30 14:12:03 +08:00
|
|
|
case HitResult.Great:
|
|
|
|
return this.GetAnimation("hit300", true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
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;
|
2019-09-04 14:59:09 +08:00
|
|
|
var texture = Textures?.Get($"{componentName}@2x");
|
2019-08-27 16:18:32 +08:00
|
|
|
|
|
|
|
if (texture == null)
|
|
|
|
{
|
|
|
|
ratio = 1;
|
2019-09-04 14:59:09 +08:00
|
|
|
texture = Textures?.Get(componentName);
|
2019-08-27 16:18:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2020-01-02 13:07:22 +08:00
|
|
|
var sample = Samples?.Get(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-09-04 14:59:09 +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
|
|
|
}
|
|
|
|
}
|