1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:33:30 +08:00

Add base legacy skin transformer

This commit is contained in:
Bartłomiej Dach 2020-06-21 22:04:10 +02:00
parent 07cbc3e683
commit ad85c5f538
5 changed files with 71 additions and 68 deletions

View File

@ -2,26 +2,21 @@
// See the LICENCE file in the repository root for full licence text.
using Humanizer;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Game.Audio;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Rulesets.Catch.Skinning
{
public class CatchLegacySkinTransformer : ISkin
public class CatchLegacySkinTransformer : LegacySkinTransformer
{
private readonly ISkin source;
public CatchLegacySkinTransformer(ISkin source)
public CatchLegacySkinTransformer(ISkinSource source)
: base(source)
{
this.source = source;
}
public Drawable GetDrawableComponent(ISkinComponent component)
public override Drawable GetDrawableComponent(ISkinComponent component)
{
if (!(component is CatchSkinComponent catchSkinComponent))
return null;
@ -61,19 +56,15 @@ namespace osu.Game.Rulesets.Catch.Skinning
return null;
}
public Texture GetTexture(string componentName) => source.GetTexture(componentName);
public SampleChannel GetSample(ISampleInfo sample) => source.GetSample(sample);
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
{
switch (lookup)
{
case CatchSkinColour colour:
return source.GetConfig<SkinCustomColourLookup, TValue>(new SkinCustomColourLookup(colour));
return Source.GetConfig<SkinCustomColourLookup, TValue>(new SkinCustomColourLookup(colour));
}
return source.GetConfig<TLookup, TValue>(lookup);
return Source.GetConfig<TLookup, TValue>(lookup);
}
}
}

View File

@ -3,11 +3,8 @@
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Game.Rulesets.Scoring;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Skinning;
@ -15,9 +12,8 @@ using System.Collections.Generic;
namespace osu.Game.Rulesets.Mania.Skinning
{
public class ManiaLegacySkinTransformer : ISkin
public class ManiaLegacySkinTransformer : LegacySkinTransformer
{
private readonly ISkin source;
private readonly ManiaBeatmap beatmap;
/// <summary>
@ -59,23 +55,23 @@ namespace osu.Game.Rulesets.Mania.Skinning
private Lazy<bool> hasKeyTexture;
public ManiaLegacySkinTransformer(ISkinSource source, IBeatmap beatmap)
: base(source)
{
this.source = source;
this.beatmap = (ManiaBeatmap)beatmap;
source.SourceChanged += sourceChanged;
Source.SourceChanged += sourceChanged;
sourceChanged();
}
private void sourceChanged()
{
isLegacySkin = new Lazy<bool>(() => source.GetConfig<LegacySkinConfiguration.LegacySetting, decimal>(LegacySkinConfiguration.LegacySetting.Version) != null);
hasKeyTexture = new Lazy<bool>(() => source.GetAnimation(
isLegacySkin = new Lazy<bool>(() => Source.GetConfig<LegacySkinConfiguration.LegacySetting, decimal>(LegacySkinConfiguration.LegacySetting.Version) != null);
hasKeyTexture = new Lazy<bool>(() => Source.GetAnimation(
this.GetManiaSkinConfig<string>(LegacyManiaSkinConfigurationLookups.KeyImage, 0)?.Value
?? "mania-key1", true, true) != null);
}
public Drawable GetDrawableComponent(ISkinComponent component)
public override Drawable GetDrawableComponent(ISkinComponent component)
{
switch (component)
{
@ -133,16 +129,12 @@ namespace osu.Game.Rulesets.Mania.Skinning
return this.GetAnimation(filename, true, true);
}
public Texture GetTexture(string componentName) => source.GetTexture(componentName);
public SampleChannel GetSample(ISampleInfo sample) => source.GetSample(sample);
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
{
if (lookup is ManiaSkinConfigurationLookup maniaLookup)
return source.GetConfig<LegacyManiaSkinConfigurationLookup, TValue>(new LegacyManiaSkinConfigurationLookup(beatmap.TotalColumns, maniaLookup.Lookup, maniaLookup.TargetColumn));
return Source.GetConfig<LegacyManiaSkinConfigurationLookup, TValue>(new LegacyManiaSkinConfigurationLookup(beatmap.TotalColumns, maniaLookup.Lookup, maniaLookup.TargetColumn));
return source.GetConfig<TLookup, TValue>(lookup);
return Source.GetConfig<TLookup, TValue>(lookup);
}
}
}

View File

@ -2,20 +2,15 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Game.Audio;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Rulesets.Osu.Skinning
{
public class OsuLegacySkinTransformer : ISkin
public class OsuLegacySkinTransformer : LegacySkinTransformer
{
private readonly ISkin source;
private Lazy<bool> hasHitCircle;
/// <summary>
@ -26,19 +21,18 @@ namespace osu.Game.Rulesets.Osu.Skinning
public const float LEGACY_CIRCLE_RADIUS = 64 - 5;
public OsuLegacySkinTransformer(ISkinSource source)
: base(source)
{
this.source = source;
source.SourceChanged += sourceChanged;
Source.SourceChanged += sourceChanged;
sourceChanged();
}
private void sourceChanged()
{
hasHitCircle = new Lazy<bool>(() => source.GetTexture("hitcircle") != null);
hasHitCircle = new Lazy<bool>(() => Source.GetTexture("hitcircle") != null);
}
public Drawable GetDrawableComponent(ISkinComponent component)
public override Drawable GetDrawableComponent(ISkinComponent component)
{
if (!(component is OsuSkinComponent osuComponent))
return null;
@ -85,13 +79,13 @@ namespace osu.Game.Rulesets.Osu.Skinning
return null;
case OsuSkinComponents.Cursor:
if (source.GetTexture("cursor") != null)
if (Source.GetTexture("cursor") != null)
return new LegacyCursor();
return null;
case OsuSkinComponents.CursorTrail:
if (source.GetTexture("cursortrail") != null)
if (Source.GetTexture("cursortrail") != null)
return new LegacyCursorTrail();
return null;
@ -102,7 +96,7 @@ namespace osu.Game.Rulesets.Osu.Skinning
return !hasFont(font)
? null
: new LegacySpriteText(source, font)
: new LegacySpriteText(Source, font)
{
// stable applies a blanket 0.8x scale to hitcircle fonts
Scale = new Vector2(0.8f),
@ -113,16 +107,12 @@ namespace osu.Game.Rulesets.Osu.Skinning
return null;
}
public Texture GetTexture(string componentName) => source.GetTexture(componentName);
public SampleChannel GetSample(ISampleInfo sample) => source.GetSample(sample);
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
{
switch (lookup)
{
case OsuSkinColour colour:
return source.GetConfig<SkinCustomColourLookup, TValue>(new SkinCustomColourLookup(colour));
return Source.GetConfig<SkinCustomColourLookup, TValue>(new SkinCustomColourLookup(colour));
case OsuSkinConfiguration osuLookup:
switch (osuLookup)
@ -136,16 +126,16 @@ namespace osu.Game.Rulesets.Osu.Skinning
case OsuSkinConfiguration.HitCircleOverlayAboveNumber:
// See https://osu.ppy.sh/help/wiki/Skinning/skin.ini#%5Bgeneral%5D
// HitCircleOverlayAboveNumer (with typo) should still be supported for now.
return source.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumber) ??
source.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumer);
return Source.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumber) ??
Source.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumer);
}
break;
}
return source.GetConfig<TLookup, TValue>(lookup);
return Source.GetConfig<TLookup, TValue>(lookup);
}
private bool hasFont(string fontName) => source.GetTexture($"{fontName}-0") != null;
private bool hasFont(string fontName) => Source.GetTexture($"{fontName}-0") != null;
}
}

View File

@ -6,23 +6,20 @@ using System.Collections.Generic;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Game.Audio;
using osu.Game.Rulesets.Taiko.UI;
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Taiko.Skinning
{
public class TaikoLegacySkinTransformer : ISkin
public class TaikoLegacySkinTransformer : LegacySkinTransformer
{
private readonly ISkinSource source;
public TaikoLegacySkinTransformer(ISkinSource source)
: base(source)
{
this.source = source;
}
public Drawable GetDrawableComponent(ISkinComponent component)
public override Drawable GetDrawableComponent(ISkinComponent component)
{
if (!(component is TaikoSkinComponent taikoComponent))
return null;
@ -100,7 +97,7 @@ namespace osu.Game.Rulesets.Taiko.Skinning
return null;
}
return source.GetDrawableComponent(component);
return Source.GetDrawableComponent(component);
}
private string getHitName(TaikoSkinComponents component)
@ -120,11 +117,9 @@ namespace osu.Game.Rulesets.Taiko.Skinning
throw new ArgumentOutOfRangeException(nameof(component), "Invalid result type");
}
public Texture GetTexture(string componentName) => source.GetTexture(componentName);
public override SampleChannel GetSample(ISampleInfo sampleInfo) => Source.GetSample(new LegacyTaikoSampleInfo(sampleInfo));
public SampleChannel GetSample(ISampleInfo sampleInfo) => source.GetSample(new LegacyTaikoSampleInfo(sampleInfo));
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => source.GetConfig<TLookup, TValue>(lookup);
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => Source.GetConfig<TLookup, TValue>(lookup);
private class LegacyTaikoSampleInfo : ISampleInfo
{

View File

@ -0,0 +1,35 @@
// 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.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Game.Audio;
namespace osu.Game.Skinning
{
/// <summary>
/// Transformer used to handle support of legacy features for individual rulesets.
/// </summary>
public abstract class LegacySkinTransformer : ISkin
{
/// <summary>
/// Source of the <see cref="ISkin"/> which is being transformed.
/// </summary>
protected ISkinSource Source { get; }
protected LegacySkinTransformer(ISkinSource source)
{
Source = source;
}
public abstract Drawable GetDrawableComponent(ISkinComponent component);
public Texture GetTexture(string componentName) => Source.GetTexture(componentName);
public virtual SampleChannel GetSample(ISampleInfo sampleInfo) => Source.GetSample(sampleInfo);
public abstract IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup);
}
}