Move basic transformer behaviour to base abstract class

This commit is contained in:
Dean Herbert 2022-09-22 18:50:19 +09:00
parent f8e9a960ba
commit 74aefdc5bd
3 changed files with 41 additions and 43 deletions

View File

@ -1,26 +1,20 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // 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;
using osu.Framework.Graphics.Textures;
using osu.Game.Audio;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning; using osu.Game.Skinning;
namespace osu.Game.Rulesets.Osu.Skinning.Argon namespace osu.Game.Rulesets.Osu.Skinning.Argon
{ {
public class OsuArgonSkinTransformer : ISkinTransformer public class OsuArgonSkinTransformer : SkinTransformer
{ {
public ISkin Skin { get; }
public OsuArgonSkinTransformer(ISkin skin) public OsuArgonSkinTransformer(ISkin skin)
: base(skin)
{ {
Skin = skin;
} }
public Drawable? GetDrawableComponent(ISkinComponent component) public override Drawable? GetDrawableComponent(ISkinComponent component)
{ {
switch (component) switch (component)
{ {
@ -55,16 +49,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Argon
break; break;
} }
return null; return base.GetDrawableComponent(component);
}
public Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => Skin.GetTexture(componentName, wrapModeS, wrapModeT);
public ISample? GetSample(ISampleInfo sampleInfo) => Skin.GetSample(sampleInfo);
public IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup) where TLookup : notnull where TValue : notnull
{
return null;
} }
} }
} }

View File

@ -1,14 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System;
using JetBrains.Annotations;
using osu.Framework.Audio.Sample; 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.Audio;
using osu.Game.Rulesets.Objects.Legacy; using osu.Game.Rulesets.Objects.Legacy;
using static osu.Game.Skinning.SkinConfiguration; using static osu.Game.Skinning.SkinConfiguration;
@ -18,24 +11,14 @@ namespace osu.Game.Skinning
/// <summary> /// <summary>
/// Transformer used to handle support of legacy features for individual rulesets. /// Transformer used to handle support of legacy features for individual rulesets.
/// </summary> /// </summary>
public abstract class LegacySkinTransformer : ISkinTransformer public abstract class LegacySkinTransformer : SkinTransformer
{ {
[NotNull] protected LegacySkinTransformer(ISkin skin)
public ISkin Skin { get; } : base(skin)
protected LegacySkinTransformer([NotNull] ISkin skin)
{ {
Skin = skin ?? throw new ArgumentNullException(nameof(skin));
} }
public virtual Drawable GetDrawableComponent(ISkinComponent component) => Skin.GetDrawableComponent(component); public override ISample? GetSample(ISampleInfo sampleInfo)
public Texture GetTexture(string componentName) => GetTexture(componentName, default, default);
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
=> Skin.GetTexture(componentName, wrapModeS, wrapModeT);
public virtual ISample GetSample(ISampleInfo sampleInfo)
{ {
if (!(sampleInfo is ConvertHitObjectParser.LegacyHitSampleInfo legacySample)) if (!(sampleInfo is ConvertHitObjectParser.LegacyHitSampleInfo legacySample))
return Skin.GetSample(sampleInfo); return Skin.GetSample(sampleInfo);
@ -44,9 +27,7 @@ namespace osu.Game.Skinning
if (legacySample.IsLayered && playLayeredHitSounds?.Value == false) if (legacySample.IsLayered && playLayeredHitSounds?.Value == false)
return new SampleVirtual(); return new SampleVirtual();
return Skin.GetSample(sampleInfo); return base.GetSample(sampleInfo);
} }
public virtual IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => Skin.GetConfig<TLookup, TValue>(lookup);
} }
} }

View File

@ -0,0 +1,32 @@
// 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 System;
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
{
public abstract class SkinTransformer : ISkinTransformer
{
public ISkin Skin { get; }
protected SkinTransformer(ISkin skin)
{
Skin = skin ?? throw new ArgumentNullException(nameof(skin));
}
public virtual Drawable? GetDrawableComponent(ISkinComponent component) => Skin.GetDrawableComponent(component);
public virtual Texture? GetTexture(string componentName) => GetTexture(componentName, default, default);
public virtual Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => Skin.GetTexture(componentName, wrapModeS, wrapModeT);
public virtual ISample? GetSample(ISampleInfo sampleInfo) => Skin.GetSample(sampleInfo);
public virtual IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup) where TLookup : notnull where TValue : notnull => Skin.GetConfig<TLookup, TValue>(lookup);
}
}