Skip to content

Commit

Permalink
Avoid making non-ruleset transformers in Ruleset.CreateSkinTransformer
Browse files Browse the repository at this point in the history
This didn't make any sense, so let's do it a better way.
  • Loading branch information
peppy committed Aug 8, 2024
1 parent 3c572ab commit 60d3834
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace osu.Game.Rulesets.Catch.Skinning.Argon
{
public class CatchArgonSkinTransformer : ArgonSkinTransformer
public class CatchArgonSkinTransformer : SkinTransformer
{
public CatchArgonSkinTransformer(ISkin skin)
: base(skin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public CatchLegacySkinTransformer(ISkin skin)
return base.GetDrawableComponent(lookup) as Container;

// Skin has configuration.
if (base.GetDrawableComponent(lookup) is Drawable d)
if (base.GetDrawableComponent(lookup) is UserConfiguredLayoutContainer d)
return d;

// Our own ruleset components default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace osu.Game.Rulesets.Osu.Skinning.Argon
{
public class OsuArgonSkinTransformer : ArgonSkinTransformer
public class OsuArgonSkinTransformer : SkinTransformer
{
public OsuArgonSkinTransformer(ISkin skin)
: base(skin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public OsuLegacySkinTransformer(ISkin skin)
return base.GetDrawableComponent(lookup);

// Skin has configuration.
if (base.GetDrawableComponent(lookup) is Drawable d)
if (base.GetDrawableComponent(lookup) is UserConfiguredLayoutContainer d)
return d;

// Our own ruleset components default.
Expand All @@ -74,6 +74,7 @@ public OsuLegacySkinTransformer(ISkin skin)
{
Children = new Drawable[]
{
new LegacyComboCounter(),
new LegacyKeyCounterDisplay(),
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace osu.Game.Rulesets.Taiko.Skinning.Argon
{
public class TaikoArgonSkinTransformer : ArgonSkinTransformer
public class TaikoArgonSkinTransformer : SkinTransformer
{
public TaikoArgonSkinTransformer(ISkin skin)
: base(skin)
Expand Down
14 changes: 1 addition & 13 deletions osu.Game/Rulesets/Ruleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,7 @@ public virtual LegacyMods ConvertToLegacyMods(Mod[] mods)
/// <param name="skin">The source skin.</param>
/// <param name="beatmap">The current beatmap.</param>
/// <returns>A skin with a transformer applied, or null if no transformation is provided by this ruleset.</returns>
public virtual ISkin? CreateSkinTransformer(ISkin skin, IBeatmap beatmap)
{
switch (skin)
{
case LegacySkin:
return new LegacySkinTransformer(skin);

case ArgonSkin:
return new ArgonSkinTransformer(skin);
}

return null;
}
public virtual ISkin? CreateSkinTransformer(ISkin skin, IBeatmap beatmap) => null;

protected Ruleset()
{
Expand Down
21 changes: 17 additions & 4 deletions osu.Game/Skinning/ArgonSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
using osu.Game.Audio;
using osu.Game.Beatmaps.Formats;
Expand Down Expand Up @@ -93,15 +94,12 @@ public ArgonSkin(SkinInfo skin, IStorageResourceProvider resources)
// Temporary until default skin has a valid hit lighting.
if ((lookup as SkinnableSprite.SpriteComponentLookup)?.LookupName == @"lighting") return Drawable.Empty();

if (base.GetDrawableComponent(lookup) is Drawable c)
if (base.GetDrawableComponent(lookup) is UserConfiguredLayoutContainer c)
return c;

switch (lookup)
{
case SkinComponentsContainerLookup containerLookup:
// Only handle global level defaults for now.
if (containerLookup.Ruleset != null)
return null;

switch (containerLookup.Target)
{
Expand All @@ -114,6 +112,21 @@ public ArgonSkin(SkinInfo skin, IStorageResourceProvider resources)
return songSelectComponents;

case SkinComponentsContainerLookup.TargetArea.MainHUDComponents:
if (containerLookup.Ruleset != null)
{
return new Container
{
RelativeSizeAxes = Axes.Both,
Child = new ArgonComboCounter
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Position = new Vector2(36, -66),
Scale = new Vector2(1.3f),
},
};
}

var mainHUDComponents = new DefaultSkinComponentsContainer(container =>
{
var health = container.OfType<ArgonHealthDisplay>().FirstOrDefault();
Expand Down
40 changes: 0 additions & 40 deletions osu.Game/Skinning/ArgonSkinTransformer.cs

This file was deleted.

16 changes: 11 additions & 5 deletions osu.Game/Skinning/LegacySkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using osu.Game.Audio;
Expand Down Expand Up @@ -349,19 +350,24 @@ protected override void ParseConfigurationStream(Stream stream)

public override Drawable? GetDrawableComponent(ISkinComponentLookup lookup)
{
if (base.GetDrawableComponent(lookup) is Drawable c)
if (base.GetDrawableComponent(lookup) is UserConfiguredLayoutContainer c)
return c;

switch (lookup)
{
case SkinComponentsContainerLookup containerLookup:
// Only handle global level defaults for now.
if (containerLookup.Ruleset != null)
return null;

switch (containerLookup.Target)
{
case SkinComponentsContainerLookup.TargetArea.MainHUDComponents:
if (containerLookup.Ruleset != null)
{
return new Container
{
RelativeSizeAxes = Axes.Both,
Child = new LegacyComboCounter(),
};
}

return new DefaultSkinComponentsContainer(container =>
{
var score = container.OfType<LegacyScoreCounter>().FirstOrDefault();
Expand Down
22 changes: 2 additions & 20 deletions osu.Game/Skinning/LegacySkinTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,24 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Audio;
using osu.Game.Rulesets.Objects.Legacy;
using static osu.Game.Skinning.SkinConfiguration;

namespace osu.Game.Skinning
{
public class LegacySkinTransformer : SkinTransformer
public abstract class LegacySkinTransformer : SkinTransformer
{
/// <summary>
/// Whether the skin being transformed is able to provide legacy resources for the ruleset.
/// </summary>
public virtual bool IsProvidingLegacyResources => this.HasFont(LegacyFont.Combo);

public LegacySkinTransformer(ISkin skin)
protected LegacySkinTransformer(ISkin skin)
: base(skin)
{
}

public override Drawable? GetDrawableComponent(ISkinComponentLookup lookup)
{
if (lookup is SkinComponentsContainerLookup containerLookup
&& containerLookup.Target == SkinComponentsContainerLookup.TargetArea.MainHUDComponents
&& containerLookup.Ruleset != null)
{
return base.GetDrawableComponent(lookup) ?? new Container
{
RelativeSizeAxes = Axes.Both,
Child = new LegacyComboCounter(),
};
}

return base.GetDrawableComponent(lookup);
}

public override ISample? GetSample(ISampleInfo sampleInfo)
{
if (!(sampleInfo is ConvertHitObjectParser.LegacyHitSampleInfo legacySample))
Expand Down
5 changes: 2 additions & 3 deletions osu.Game/Skinning/Skin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using osu.Framework.Bindables;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using osu.Framework.Logging;
Expand All @@ -26,7 +25,7 @@

namespace osu.Game.Skinning
{
public abstract class Skin : IDisposable, ISkin
public abstract partial class Skin : IDisposable, ISkin
{
private readonly IStorageResourceProvider? resources;

Expand Down Expand Up @@ -195,7 +194,7 @@ public void UpdateDrawableTarget(SkinComponentsContainer targetContainer)
if (!LayoutInfos.TryGetValue(containerLookup.Target, out var layoutInfo)) return null;
if (!layoutInfo.TryGetDrawableInfo(containerLookup.Ruleset, out var drawableInfos)) return null;

return new Container
return new UserConfiguredLayoutContainer
{
RelativeSizeAxes = Axes.Both,
ChildrenEnumerable = drawableInfos.Select(i => i.CreateInstance())
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Skinning/TrianglesSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public TrianglesSkin(SkinInfo skin, IStorageResourceProvider resources)
// Temporary until default skin has a valid hit lighting.
if ((lookup as SkinnableSprite.SpriteComponentLookup)?.LookupName == @"lighting") return Drawable.Empty();

if (base.GetDrawableComponent(lookup) is Drawable c)
if (base.GetDrawableComponent(lookup) is UserConfiguredLayoutContainer c)
return c;

switch (lookup)
Expand Down
15 changes: 15 additions & 0 deletions osu.Game/Skinning/UserConfiguredLayoutContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.Graphics.Containers;

namespace osu.Game.Skinning
{
/// <summary>
/// This signifies that a <see cref="Skin.GetDrawableComponent"/> call resolved a configuration created
/// by a user in their skin. Generally this should be given priority over any local defaults or overrides.
/// </summary>
public partial class UserConfiguredLayoutContainer : Container
{
}
}

0 comments on commit 60d3834

Please sign in to comment.