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

Convert LegacySkinTransformers to accept raw ISkins rather than a full ISkinSource

This commit is contained in:
Salman Ahmed 2021-06-09 13:34:42 +03:00
parent aed490803f
commit cf40282f1f
11 changed files with 61 additions and 93 deletions

View File

@ -175,7 +175,7 @@ namespace osu.Game.Rulesets.Catch
public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new CatchDifficultyCalculator(this, beatmap); public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new CatchDifficultyCalculator(this, beatmap);
public override ISkin CreateLegacySkinProvider(ISkinSource source, IBeatmap beatmap) => new CatchLegacySkinTransformer(source); public override ISkin CreateLegacySkinProvider(ISkin skin, IBeatmap beatmap) => new CatchLegacySkinTransformer(skin);
public override PerformanceCalculator CreatePerformanceCalculator(DifficultyAttributes attributes, ScoreInfo score) => new CatchPerformanceCalculator(this, attributes, score); public override PerformanceCalculator CreatePerformanceCalculator(DifficultyAttributes attributes, ScoreInfo score) => new CatchPerformanceCalculator(this, attributes, score);

View File

@ -17,8 +17,8 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy
/// </summary> /// </summary>
private bool providesComboCounter => this.HasFont(LegacyFont.Combo); private bool providesComboCounter => this.HasFont(LegacyFont.Combo);
public CatchLegacySkinTransformer(ISkinSource source) public CatchLegacySkinTransformer(ISkin skin)
: base(source) : base(skin)
{ {
} }
@ -29,7 +29,7 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy
switch (targetComponent.Target) switch (targetComponent.Target)
{ {
case SkinnableTarget.MainHUDComponents: case SkinnableTarget.MainHUDComponents:
var components = Source.GetDrawableComponent(component) as SkinnableTargetComponentsContainer; var components = Skin.GetDrawableComponent(component) as SkinnableTargetComponentsContainer;
if (providesComboCounter && components != null) if (providesComboCounter && components != null)
{ {
@ -79,13 +79,13 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy
case CatchSkinComponents.CatchComboCounter: case CatchSkinComponents.CatchComboCounter:
if (providesComboCounter) if (providesComboCounter)
return new LegacyCatchComboCounter(Source); return new LegacyCatchComboCounter(Skin);
return null; return null;
} }
} }
return Source.GetDrawableComponent(component); return Skin.GetDrawableComponent(component);
} }
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
@ -93,7 +93,7 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy
switch (lookup) switch (lookup)
{ {
case CatchSkinColour colour: case CatchSkinColour colour:
var result = (Bindable<Color4>)Source.GetConfig<SkinCustomColourLookup, TValue>(new SkinCustomColourLookup(colour)); var result = (Bindable<Color4>)Skin.GetConfig<SkinCustomColourLookup, TValue>(new SkinCustomColourLookup(colour));
if (result == null) if (result == null)
return null; return null;
@ -101,7 +101,7 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy
return (IBindable<TValue>)result; return (IBindable<TValue>)result;
} }
return Source.GetConfig<TLookup, TValue>(lookup); return Skin.GetConfig<TLookup, TValue>(lookup);
} }
} }
} }

View File

@ -57,7 +57,7 @@ namespace osu.Game.Rulesets.Mania
public override HitObjectComposer CreateHitObjectComposer() => new ManiaHitObjectComposer(this); public override HitObjectComposer CreateHitObjectComposer() => new ManiaHitObjectComposer(this);
public override ISkin CreateLegacySkinProvider(ISkinSource source, IBeatmap beatmap) => new ManiaLegacySkinTransformer(source, beatmap); public override ISkin CreateLegacySkinProvider(ISkin skin, IBeatmap beatmap) => new ManiaLegacySkinTransformer(skin, beatmap);
public override IEnumerable<Mod> ConvertFromLegacyMods(LegacyMods mods) public override IEnumerable<Mod> ConvertFromLegacyMods(LegacyMods mods)
{ {

View File

@ -50,29 +50,25 @@ namespace osu.Game.Rulesets.Mania.Skinning.Legacy
{ HitResult.Miss, "mania-hit0" } { HitResult.Miss, "mania-hit0" }
}; };
private Lazy<bool> isLegacySkin; private readonly Lazy<bool> isLegacySkin;
/// <summary> /// <summary>
/// Whether texture for the keys exists. /// Whether texture for the keys exists.
/// Used to determine if the mania ruleset is skinned. /// Used to determine if the mania ruleset is skinned.
/// </summary> /// </summary>
private Lazy<bool> hasKeyTexture; private readonly Lazy<bool> hasKeyTexture;
public ManiaLegacySkinTransformer(ISkinSource source, IBeatmap beatmap) public ManiaLegacySkinTransformer(ISkin skin, IBeatmap beatmap)
: base(source) : base(skin)
{ {
this.beatmap = (ManiaBeatmap)beatmap; this.beatmap = (ManiaBeatmap)beatmap;
Source.SourceChanged += sourceChanged; isLegacySkin = new Lazy<bool>(() => skin.GetConfig<LegacySkinConfiguration.LegacySetting, decimal>(LegacySkinConfiguration.LegacySetting.Version) != null);
sourceChanged(); hasKeyTexture = new Lazy<bool>(() =>
} {
var keyImage = this.GetManiaSkinConfig<string>(LegacyManiaSkinConfigurationLookups.KeyImage, 0)?.Value ?? "mania-key1";
private void sourceChanged() return skin.GetAnimation(keyImage, true, true) != null;
{ });
isLegacySkin = new Lazy<bool>(() => FindProvider(s => s.GetConfig<LegacySkinConfiguration.LegacySetting, decimal>(LegacySkinConfiguration.LegacySetting.Version) != null) != null);
hasKeyTexture = new Lazy<bool>(() => FindProvider(s => s.GetAnimation(
s.GetManiaSkinConfig<string>(LegacyManiaSkinConfigurationLookups.KeyImage, 0)?.Value
?? "mania-key1", true, true) != null) != null);
} }
public override Drawable GetDrawableComponent(ISkinComponent component) public override Drawable GetDrawableComponent(ISkinComponent component)
@ -125,7 +121,7 @@ namespace osu.Game.Rulesets.Mania.Skinning.Legacy
break; break;
} }
return Source.GetDrawableComponent(component); return Skin.GetDrawableComponent(component);
} }
private Drawable getResult(HitResult result) private Drawable getResult(HitResult result)
@ -146,15 +142,15 @@ namespace osu.Game.Rulesets.Mania.Skinning.Legacy
if (sampleInfo is ConvertHitObjectParser.LegacyHitSampleInfo legacySample && legacySample.IsLayered) if (sampleInfo is ConvertHitObjectParser.LegacyHitSampleInfo legacySample && legacySample.IsLayered)
return new SampleVirtual(); return new SampleVirtual();
return Source.GetSample(sampleInfo); return Skin.GetSample(sampleInfo);
} }
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
{ {
if (lookup is ManiaSkinConfigurationLookup maniaLookup) if (lookup is ManiaSkinConfigurationLookup maniaLookup)
return Source.GetConfig<LegacyManiaSkinConfigurationLookup, TValue>(new LegacyManiaSkinConfigurationLookup(beatmap.TotalColumns, maniaLookup.Lookup, maniaLookup.TargetColumn)); return Skin.GetConfig<LegacyManiaSkinConfigurationLookup, TValue>(new LegacyManiaSkinConfigurationLookup(beatmap.TotalColumns, maniaLookup.Lookup, maniaLookup.TargetColumn));
return Source.GetConfig<TLookup, TValue>(lookup); return Skin.GetConfig<TLookup, TValue>(lookup);
} }
} }
} }

View File

@ -218,7 +218,7 @@ namespace osu.Game.Rulesets.Osu
public override RulesetSettingsSubsection CreateSettings() => new OsuSettingsSubsection(this); public override RulesetSettingsSubsection CreateSettings() => new OsuSettingsSubsection(this);
public override ISkin CreateLegacySkinProvider(ISkinSource source, IBeatmap beatmap) => new OsuLegacySkinTransformer(source); public override ISkin CreateLegacySkinProvider(ISkin skin, IBeatmap beatmap) => new OsuLegacySkinTransformer(skin);
public int LegacyID => 0; public int LegacyID => 0;

View File

@ -11,7 +11,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
{ {
public class OsuLegacySkinTransformer : LegacySkinTransformer public class OsuLegacySkinTransformer : LegacySkinTransformer
{ {
private Lazy<bool> hasHitCircle; private readonly Lazy<bool> hasHitCircle;
/// <summary> /// <summary>
/// On osu-stable, hitcircles have 5 pixels of transparent padding on each side to allow for shadows etc. /// On osu-stable, hitcircles have 5 pixels of transparent padding on each side to allow for shadows etc.
@ -20,16 +20,10 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
/// </summary> /// </summary>
public const float LEGACY_CIRCLE_RADIUS = 64 - 5; public const float LEGACY_CIRCLE_RADIUS = 64 - 5;
public OsuLegacySkinTransformer(ISkinSource source) public OsuLegacySkinTransformer(ISkin skin)
: base(source) : base(skin)
{ {
Source.SourceChanged += sourceChanged; hasHitCircle = new Lazy<bool>(() => Skin.GetTexture("hitcircle") != null);
sourceChanged();
}
private void sourceChanged()
{
hasHitCircle = new Lazy<bool>(() => FindProvider(s => s.GetTexture("hitcircle") != null) != null);
} }
public override Drawable GetDrawableComponent(ISkinComponent component) public override Drawable GetDrawableComponent(ISkinComponent component)
@ -49,16 +43,13 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
return followCircle; return followCircle;
case OsuSkinComponents.SliderBall: case OsuSkinComponents.SliderBall:
// specular and nd layers must come from the same source as the ball texure. var sliderBallContent = this.GetAnimation("sliderb", true, true, animationSeparator: "");
var ballProvider = Source.FindProvider(s => s.GetTexture("sliderb") != null || s.GetTexture("sliderb0") != null);
var sliderBallContent = ballProvider.GetAnimation("sliderb", true, true, animationSeparator: "");
// todo: slider ball has a custom frame delay based on velocity // todo: slider ball has a custom frame delay based on velocity
// Math.Max((150 / Velocity) * GameBase.SIXTY_FRAME_TIME, GameBase.SIXTY_FRAME_TIME); // Math.Max((150 / Velocity) * GameBase.SIXTY_FRAME_TIME, GameBase.SIXTY_FRAME_TIME);
if (sliderBallContent != null) if (sliderBallContent != null)
return new LegacySliderBall(sliderBallContent, ballProvider); return new LegacySliderBall(sliderBallContent, this);
return null; return null;
@ -87,18 +78,14 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
return null; return null;
case OsuSkinComponents.Cursor: case OsuSkinComponents.Cursor:
var cursorProvider = Source.FindProvider(s => s.GetTexture("cursor") != null); if (GetTexture("cursor") != null)
return new LegacyCursor(this);
if (cursorProvider != null)
return new LegacyCursor(cursorProvider);
return null; return null;
case OsuSkinComponents.CursorTrail: case OsuSkinComponents.CursorTrail:
var trailProvider = Source.FindProvider(s => s.GetTexture("cursortrail") != null); if (GetTexture("cursortrail") != null)
return new LegacyCursorTrail(this);
if (trailProvider != null)
return new LegacyCursorTrail(trailProvider);
return null; return null;
@ -113,9 +100,9 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
}; };
case OsuSkinComponents.SpinnerBody: case OsuSkinComponents.SpinnerBody:
bool hasBackground = Source.GetTexture("spinner-background") != null; bool hasBackground = GetTexture("spinner-background") != null;
if (Source.GetTexture("spinner-top") != null && !hasBackground) if (GetTexture("spinner-top") != null && !hasBackground)
return new LegacyNewStyleSpinner(); return new LegacyNewStyleSpinner();
else if (hasBackground) else if (hasBackground)
return new LegacyOldStyleSpinner(); return new LegacyOldStyleSpinner();
@ -124,7 +111,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
} }
} }
return Source.GetDrawableComponent(component); return Skin.GetDrawableComponent(component);
} }
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
@ -132,7 +119,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
switch (lookup) switch (lookup)
{ {
case OsuSkinColour colour: case OsuSkinColour colour:
return Source.GetConfig<SkinCustomColourLookup, TValue>(new SkinCustomColourLookup(colour)); return Skin.GetConfig<SkinCustomColourLookup, TValue>(new SkinCustomColourLookup(colour));
case OsuSkinConfiguration osuLookup: case OsuSkinConfiguration osuLookup:
switch (osuLookup) switch (osuLookup)
@ -146,14 +133,14 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
case OsuSkinConfiguration.HitCircleOverlayAboveNumber: case OsuSkinConfiguration.HitCircleOverlayAboveNumber:
// See https://osu.ppy.sh/help/wiki/Skinning/skin.ini#%5Bgeneral%5D // See https://osu.ppy.sh/help/wiki/Skinning/skin.ini#%5Bgeneral%5D
// HitCircleOverlayAboveNumer (with typo) should still be supported for now. // HitCircleOverlayAboveNumer (with typo) should still be supported for now.
return Source.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumber) ?? return Skin.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumber) ??
Source.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumer); Skin.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumer);
} }
break; break;
} }
return Source.GetConfig<TLookup, TValue>(lookup); return Skin.GetConfig<TLookup, TValue>(lookup);
} }
} }
} }

View File

@ -15,18 +15,12 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Legacy
{ {
public class TaikoLegacySkinTransformer : LegacySkinTransformer public class TaikoLegacySkinTransformer : LegacySkinTransformer
{ {
private Lazy<bool> hasExplosion; private readonly Lazy<bool> hasExplosion;
public TaikoLegacySkinTransformer(ISkinSource source) public TaikoLegacySkinTransformer(ISkin skin)
: base(source) : base(skin)
{ {
Source.SourceChanged += sourceChanged; hasExplosion = new Lazy<bool>(() => Skin.GetTexture(getHitName(TaikoSkinComponents.TaikoExplosionGreat)) != null);
sourceChanged();
}
private void sourceChanged()
{
hasExplosion = new Lazy<bool>(() => Source.GetTexture(getHitName(TaikoSkinComponents.TaikoExplosionGreat)) != null);
} }
public override Drawable GetDrawableComponent(ISkinComponent component) public override Drawable GetDrawableComponent(ISkinComponent component)
@ -132,7 +126,7 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Legacy
} }
} }
return Source.GetDrawableComponent(component); return Skin.GetDrawableComponent(component);
} }
private string getHitName(TaikoSkinComponents component) private string getHitName(TaikoSkinComponents component)
@ -155,12 +149,12 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Legacy
public override ISample GetSample(ISampleInfo sampleInfo) public override ISample GetSample(ISampleInfo sampleInfo)
{ {
if (sampleInfo is HitSampleInfo hitSampleInfo) if (sampleInfo is HitSampleInfo hitSampleInfo)
return Source.GetSample(new LegacyTaikoSampleInfo(hitSampleInfo)); return Skin.GetSample(new LegacyTaikoSampleInfo(hitSampleInfo));
return base.GetSample(sampleInfo); return base.GetSample(sampleInfo);
} }
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => Source.GetConfig<TLookup, TValue>(lookup); public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => Skin.GetConfig<TLookup, TValue>(lookup);
private class LegacyTaikoSampleInfo : HitSampleInfo private class LegacyTaikoSampleInfo : HitSampleInfo
{ {

View File

@ -42,7 +42,7 @@ namespace osu.Game.Rulesets.Taiko
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new TaikoBeatmapConverter(beatmap, this); public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new TaikoBeatmapConverter(beatmap, this);
public override ISkin CreateLegacySkinProvider(ISkinSource source, IBeatmap beatmap) => new TaikoLegacySkinTransformer(source); public override ISkin CreateLegacySkinProvider(ISkin skin, IBeatmap beatmap) => new TaikoLegacySkinTransformer(skin);
public const string SHORT_NAME = "taiko"; public const string SHORT_NAME = "taiko";

View File

@ -116,12 +116,12 @@ namespace osu.Game.Tests.Visual.Gameplay
private class TestOsuRuleset : OsuRuleset private class TestOsuRuleset : OsuRuleset
{ {
public override ISkin CreateLegacySkinProvider(ISkinSource source, IBeatmap beatmap) => new TestOsuLegacySkinTransformer(source); public override ISkin CreateLegacySkinProvider(ISkin skin, IBeatmap beatmap) => new TestOsuLegacySkinTransformer(skin);
private class TestOsuLegacySkinTransformer : OsuLegacySkinTransformer private class TestOsuLegacySkinTransformer : OsuLegacySkinTransformer
{ {
public TestOsuLegacySkinTransformer(ISkinSource source) public TestOsuLegacySkinTransformer(ISkin skin)
: base(source) : base(skin)
{ {
} }
} }

View File

@ -127,7 +127,7 @@ namespace osu.Game.Rulesets
[CanBeNull] [CanBeNull]
public ModAutoplay GetAutoplayMod() => GetAllMods().OfType<ModAutoplay>().FirstOrDefault(); public ModAutoplay GetAutoplayMod() => GetAllMods().OfType<ModAutoplay>().FirstOrDefault();
public virtual ISkin CreateLegacySkinProvider(ISkinSource source, IBeatmap beatmap) => null; public virtual ISkin CreateLegacySkinProvider(ISkin skin, IBeatmap beatmap) => null;
protected Ruleset() protected Ruleset()
{ {

View File

@ -1,7 +1,6 @@
// 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 System;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -16,16 +15,16 @@ 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 : ISkinSource public abstract class LegacySkinTransformer : ISkin
{ {
/// <summary> /// <summary>
/// Source of the <see cref="ISkin"/> which is being transformed. /// The <see cref="ISkin"/> which is being transformed.
/// </summary> /// </summary>
protected ISkinSource Source { get; } protected ISkin Skin { get; }
protected LegacySkinTransformer(ISkinSource source) protected LegacySkinTransformer(ISkin skin)
{ {
Source = source; Skin = skin;
} }
public abstract Drawable GetDrawableComponent(ISkinComponent component); public abstract Drawable GetDrawableComponent(ISkinComponent component);
@ -33,28 +32,20 @@ namespace osu.Game.Skinning
public Texture GetTexture(string componentName) => GetTexture(componentName, default, default); public Texture GetTexture(string componentName) => GetTexture(componentName, default, default);
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
=> Source.GetTexture(componentName, wrapModeS, wrapModeT); => Skin.GetTexture(componentName, wrapModeS, wrapModeT);
public virtual ISample GetSample(ISampleInfo sampleInfo) public virtual ISample GetSample(ISampleInfo sampleInfo)
{ {
if (!(sampleInfo is ConvertHitObjectParser.LegacyHitSampleInfo legacySample)) if (!(sampleInfo is ConvertHitObjectParser.LegacyHitSampleInfo legacySample))
return Source.GetSample(sampleInfo); return Skin.GetSample(sampleInfo);
var playLayeredHitSounds = GetConfig<LegacySetting, bool>(LegacySetting.LayeredHitSounds); var playLayeredHitSounds = GetConfig<LegacySetting, bool>(LegacySetting.LayeredHitSounds);
if (legacySample.IsLayered && playLayeredHitSounds?.Value == false) if (legacySample.IsLayered && playLayeredHitSounds?.Value == false)
return new SampleVirtual(); return new SampleVirtual();
return Source.GetSample(sampleInfo); return Skin.GetSample(sampleInfo);
} }
public abstract IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup); public abstract IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup);
public ISkin FindProvider(Func<ISkin, bool> lookupFunction) => Source.FindProvider(lookupFunction);
public event Action SourceChanged
{
add { throw new NotSupportedException(); }
remove { }
}
} }
} }