Skip to content

Commit

Permalink
Update GetTexture signature rather than creating new overload
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Sep 5, 2023
1 parent f182f57 commit 96f12cf
Show file tree
Hide file tree
Showing 30 changed files with 84 additions and 73 deletions.
5 changes: 2 additions & 3 deletions osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyBananaPiece.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Graphics.Textures;
using osu.Game.Skinning;
using osuTK;

namespace osu.Game.Rulesets.Catch.Skinning.Legacy
Expand All @@ -15,8 +14,8 @@ protected override void LoadComplete()
{
base.LoadComplete();

Texture? texture = Skin.GetTextureWithMaxSize("fruit-bananas", banana_max_size);
Texture? overlayTexture = Skin.GetTextureWithMaxSize("fruit-bananas-overlay", banana_max_size);
Texture? texture = Skin.GetTexture("fruit-bananas", banana_max_size);
Texture? overlayTexture = Skin.GetTexture("fruit-bananas-overlay", banana_max_size);

SetTexture(texture, overlayTexture);
}
Expand Down
5 changes: 2 additions & 3 deletions osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyDropletPiece.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Graphics.Textures;
using osu.Game.Skinning;
using osuTK;

namespace osu.Game.Rulesets.Catch.Skinning.Legacy
Expand All @@ -20,8 +19,8 @@ protected override void LoadComplete()
{
base.LoadComplete();

Texture? texture = Skin.GetTextureWithMaxSize("fruit-drop", droplet_max_size);
Texture? overlayTexture = Skin.GetTextureWithMaxSize("fruit-drop-overlay", droplet_max_size);
Texture? texture = Skin.GetTexture("fruit-drop", droplet_max_size);
Texture? overlayTexture = Skin.GetTexture("fruit-drop-overlay", droplet_max_size);

SetTexture(texture, overlayTexture);
}
Expand Down
9 changes: 4 additions & 5 deletions osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyFruitPiece.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Skinning;
using osuTK;

namespace osu.Game.Rulesets.Catch.Skinning.Legacy
Expand All @@ -26,19 +25,19 @@ private void setTexture(FruitVisualRepresentation visualRepresentation)
switch (visualRepresentation)
{
case FruitVisualRepresentation.Pear:
SetTexture(Skin.GetTextureWithMaxSize("fruit-pear", fruit_max_size), Skin.GetTextureWithMaxSize("fruit-pear-overlay", fruit_max_size));
SetTexture(Skin.GetTexture("fruit-pear", fruit_max_size), Skin.GetTexture("fruit-pear-overlay", fruit_max_size));
break;

case FruitVisualRepresentation.Grape:
SetTexture(Skin.GetTextureWithMaxSize("fruit-grapes", fruit_max_size), Skin.GetTextureWithMaxSize("fruit-grapes-overlay", fruit_max_size));
SetTexture(Skin.GetTexture("fruit-grapes", fruit_max_size), Skin.GetTexture("fruit-grapes-overlay", fruit_max_size));
break;

case FruitVisualRepresentation.Pineapple:
SetTexture(Skin.GetTextureWithMaxSize("fruit-apple", fruit_max_size), Skin.GetTextureWithMaxSize("fruit-apple-overlay", fruit_max_size));
SetTexture(Skin.GetTexture("fruit-apple", fruit_max_size), Skin.GetTexture("fruit-apple-overlay", fruit_max_size));
break;

case FruitVisualRepresentation.Raspberry:
SetTexture(Skin.GetTextureWithMaxSize("fruit-orange", fruit_max_size), Skin.GetTextureWithMaxSize("fruit-orange-overlay", fruit_max_size));
SetTexture(Skin.GetTexture("fruit-orange", fruit_max_size), Skin.GetTexture("fruit-orange-overlay", fruit_max_size));
break;
}
}
Expand Down
5 changes: 3 additions & 2 deletions osu.Game.Rulesets.Osu.Tests/LegacyMainCirclePieceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using osu.Game.Rulesets.Osu.Skinning.Legacy;
using osu.Game.Skinning;
using osu.Game.Tests.Visual;
using osuTK;

namespace osu.Game.Rulesets.Osu.Tests
{
Expand Down Expand Up @@ -77,9 +78,9 @@ public void TestTexturePriorities(string[] textureFilenames, string priorityLook
// shouldn't be required as GetTexture(string) calls GetTexture(string, WrapMode, WrapMode) by default,
// but moq doesn't handle that well, therefore explicitly requiring to use `CallBase`:
// https://github.com/moq/moq4/issues/972
skin.Setup(s => s.GetTexture(It.IsAny<string>())).CallBase();
skin.Setup(s => s.GetTexture(It.IsAny<string>(), It.IsAny<Vector2>(), It.IsAny<WrapMode>(), It.IsAny<WrapMode>())).CallBase();
skin.Setup(s => s.GetTexture(It.IsIn(textureFilenames), It.IsAny<WrapMode>(), It.IsAny<WrapMode>()))
skin.Setup(s => s.GetTexture(It.IsIn(textureFilenames), It.IsAny<Vector2>(), It.IsAny<WrapMode>(), It.IsAny<WrapMode>()))
.Returns((string componentName, WrapMode _, WrapMode _) =>
{
var tex = renderer.CreateTexture(1, 1);
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Osu.Tests/TestSceneCursorTrail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public LegacySkinContainer(IRenderer renderer, bool disjoint)

public Drawable GetDrawableComponent(ISkinComponentLookup lookup) => null;

public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
public Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default)
{
switch (componentName)
{
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Osu.Tests/TestSceneGameplayCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void loadContent(bool automated, Func<SkinProvidingContainer> skinProvid
private class TopLeftCursorSkin : ISkin
{
public Drawable GetDrawableComponent(ISkinComponentLookup lookup) => null;
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => null;
public Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default) => null;
public ISample GetSample(ISampleInfo sampleInfo) => null;

public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
Expand Down
3 changes: 2 additions & 1 deletion osu.Game.Rulesets.Osu.Tests/TestSceneSkinFallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using osu.Game.Skinning;
using osu.Game.Storyboards;
using osu.Game.Tests.Visual;
using osuTK;

namespace osu.Game.Rulesets.Osu.Tests
{
Expand Down Expand Up @@ -163,7 +164,7 @@ public Drawable GetDrawableComponent(ISkinComponentLookup lookup)
};
}

public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => null;
public Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default) => null;

public ISample GetSample(ISampleInfo sampleInfo) => null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void load()
// expected behaviour in this scenario is not showing the overlay, rather than using hitcircleoverlay.png.
InternalChildren = new[]
{
CircleSprite = new LegacyKiaiFlashingDrawable(() => new Sprite { Texture = skin.GetTextureWithMaxSize(circleName, circle_piece_size) })
CircleSprite = new LegacyKiaiFlashingDrawable(() => new Sprite { Texture = skin.GetTexture(circleName, circle_piece_size) })
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Expand Down
3 changes: 2 additions & 1 deletion osu.Game.Tests/Gameplay/TestSceneHitObjectAccentColour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Skinning;
using osu.Game.Tests.Visual;
using osuTK;
using osuTK.Graphics;

namespace osu.Game.Tests.Gameplay
Expand Down Expand Up @@ -140,7 +141,7 @@ private class TestSkin : ISkin

public Drawable GetDrawableComponent(ISkinComponentLookup lookup) => throw new NotImplementedException();

public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => throw new NotImplementedException();
public Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default) => throw new NotImplementedException();

public ISample GetSample(ISampleInfo sampleInfo) => throw new NotImplementedException();

Expand Down
3 changes: 2 additions & 1 deletion osu.Game.Tests/NonVisual/Skinning/LegacySkinAnimationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using osu.Game.Audio;
using osu.Game.Skinning;
using osu.Game.Tests.Visual;
using osuTK;

namespace osu.Game.Tests.NonVisual.Skinning
{
Expand Down Expand Up @@ -68,7 +69,7 @@ public TestSkin(IRenderer renderer)
this.renderer = renderer;
}

public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
public Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default)
{
return lookup_names.Contains(componentName) ? renderer.WhitePixel : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using osu.Game.Skinning;
using osu.Game.Tests.Testing;
using osu.Game.Tests.Visual;
using osuTK;

namespace osu.Game.Tests.Rulesets
{
Expand Down Expand Up @@ -80,7 +81,7 @@ private void load(ISkinSource skin)

public Drawable GetDrawableComponent(ISkinComponentLookup lookup) => skin.GetDrawableComponent(lookup);

public Texture GetTexture(string componentName, WrapMode wrapModeS = default, WrapMode wrapModeT = default) => skin.GetTexture(componentName);
public Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default) => skin.GetTexture(componentName);

public ISample GetSample(ISampleInfo sampleInfo) => skin.GetSample(sampleInfo);

Expand Down
3 changes: 2 additions & 1 deletion osu.Game.Tests/Skins/SkinDeserialisationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using osu.Game.Screens.Play.HUD.HitErrorMeters;
using osu.Game.Skinning;
using osu.Game.Tests.Resources;
using osuTK;

namespace osu.Game.Tests.Skins
{
Expand Down Expand Up @@ -133,7 +134,7 @@ public TestSkin(SkinInfo skin, IStorageResourceProvider? resources, IResourceSto
{
}

public override Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => throw new NotImplementedException();
public override Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default) => throw new NotImplementedException();

public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => throw new NotImplementedException();

Expand Down
4 changes: 3 additions & 1 deletion osu.Game.Tests/Skins/TestSceneBeatmapSkinLookupDisables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using osu.Game.Skinning;
using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Visual;
using osuTK;

namespace osu.Game.Tests.Skins
{
Expand Down Expand Up @@ -100,7 +101,8 @@ private void load(ISkinSource skin)

public Drawable GetDrawableComponent(ISkinComponentLookup lookup) => skin.GetDrawableComponent(lookup);

public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => skin.GetTexture(componentName, wrapModeS, wrapModeT);
public Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default) =>
skin.GetTexture(componentName, maxSize, wrapModeS, wrapModeT);

public ISample GetSample(ISampleInfo sampleInfo) => skin.GetSample(sampleInfo);

Expand Down
4 changes: 3 additions & 1 deletion osu.Game.Tests/Skins/TestSceneSkinConfigurationLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using osu.Game.Skinning;
using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Visual;
using osuTK;
using osuTK.Graphics;

namespace osu.Game.Tests.Skins
Expand Down Expand Up @@ -223,7 +224,8 @@ private void load(ISkinSource skin)

public Drawable GetDrawableComponent(ISkinComponentLookup lookup) => skin.GetDrawableComponent(lookup);

public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => skin.GetTexture(componentName, wrapModeS, wrapModeT);
public Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default) =>
skin.GetTexture(componentName, maxSize, wrapModeS, wrapModeT);

public ISample GetSample(ISampleInfo sampleInfo) => skin.GetSample(sampleInfo);

Expand Down
3 changes: 2 additions & 1 deletion osu.Game.Tests/Skins/TestSceneSkinProvidingContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using osu.Game.Audio;
using osu.Game.Skinning;
using osu.Game.Tests.Visual;
using osuTK;

namespace osu.Game.Tests.Skins
{
Expand Down Expand Up @@ -89,7 +90,7 @@ public TestSkin(IRenderer renderer)

public Drawable GetDrawableComponent(ISkinComponentLookup lookup) => throw new System.NotImplementedException();

public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
public Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default)
{
if (componentName == TEXTURE_NAME)
return renderer.WhitePixel;
Expand Down
3 changes: 2 additions & 1 deletion osu.Game.Tests/Skins/TestSceneSkinResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using osu.Game.Skinning;
using osu.Game.Tests.Resources;
using osu.Game.Tests.Visual;
using osuTK;

namespace osu.Game.Tests.Skins
{
Expand Down Expand Up @@ -100,7 +101,7 @@ public TestSkin(SkinInfo skin, IStorageResourceProvider? resources, IResourceSto
{
}

public override Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => throw new NotImplementedException();
public override Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default) => throw new NotImplementedException();

public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => throw new NotImplementedException();

Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableDrawable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public SizedSource(float size)
}
: null;

public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => throw new NotImplementedException();
public Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default) => throw new NotImplementedException();

public ISample GetSample(ISampleInfo sampleInfo) => throw new NotImplementedException();

Expand All @@ -308,7 +308,7 @@ private class SecondarySource : ISkin
{
public Drawable GetDrawableComponent(ISkinComponentLookup componentLookupName) => new SecondarySourceBox();

public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => throw new NotImplementedException();
public Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default) => throw new NotImplementedException();

public ISample GetSample(ISampleInfo sampleInfo) => throw new NotImplementedException();

Expand All @@ -320,7 +320,7 @@ private partial class SkinSourceContainer : Container, ISkinSource
{
public Drawable GetDrawableComponent(ISkinComponentLookup componentLookupName) => new BaseSourceBox();

public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => throw new NotImplementedException();
public Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default) => throw new NotImplementedException();

public ISample GetSample(ISampleInfo sampleInfo) => throw new NotImplementedException();

Expand Down
6 changes: 5 additions & 1 deletion osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using osu.Framework.Testing;
using osu.Game.Audio;
using osu.Game.Skinning;
using osuTK;

namespace osu.Game.Tests.Visual.Gameplay
{
Expand Down Expand Up @@ -163,7 +164,10 @@ private partial class TestSkinSourceContainer : Container, ISkinSource, ISampleP
IBindable<bool> ISamplePlaybackDisabler.SamplePlaybackDisabled => SamplePlaybackDisabled;

public Drawable? GetDrawableComponent(ISkinComponentLookup lookup) => source.GetDrawableComponent(lookup);
public Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => source.GetTexture(componentName, wrapModeS, wrapModeT);

public Texture? GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default) =>
source.GetTexture(componentName, maxSize, wrapModeS, wrapModeT);

public ISample? GetSample(ISampleInfo sampleInfo) => OverridingSample ?? source.GetSample(sampleInfo);

public IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup)
Expand Down
6 changes: 5 additions & 1 deletion osu.Game/Screens/Edit/EditorBeatmapSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using osu.Framework.Graphics.Textures;
using osu.Game.Audio;
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;

namespace osu.Game.Screens.Edit
Expand Down Expand Up @@ -54,7 +55,10 @@ private void updateColours()
#region Delegated ISkin implementation

public Drawable GetDrawableComponent(ISkinComponentLookup lookup) => Skin.GetDrawableComponent(lookup);
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => Skin.GetTexture(componentName, wrapModeS, wrapModeT);

public Texture GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default) =>
Skin.GetTexture(componentName, maxSize, wrapModeS, wrapModeT);

public ISample GetSample(ISampleInfo sampleInfo) => Skin.GetSample(sampleInfo);
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => Skin.GetConfig<TLookup, TValue>(lookup);

Expand Down
3 changes: 2 additions & 1 deletion osu.Game/Skinning/ArgonSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public ArgonSkin(SkinInfo skin, IStorageResourceProvider resources)
};
}

public override Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => Textures?.Get(componentName, wrapModeS, wrapModeT);
public override Texture? GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default) =>
Textures?.Get(componentName, wrapModeS, wrapModeT).WithMaximumSize(maxSize);

public override ISample? GetSample(ISampleInfo sampleInfo)
{
Expand Down
11 changes: 3 additions & 8 deletions osu.Game/Skinning/ISkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Game.Audio;
using osuTK;

namespace osu.Game.Skinning
{
Expand All @@ -25,17 +26,11 @@ public interface ISkin
/// Retrieve a <see cref="Texture"/>.
/// </summary>
/// <param name="componentName">The requested texture.</param>
/// <returns>A matching texture, or null if unavailable.</returns>
Texture? GetTexture(string componentName) => GetTexture(componentName, default, default);

/// <summary>
/// Retrieve a <see cref="Texture"/>.
/// </summary>
/// <param name="componentName">The requested texture.</param>
/// <param name="maxSize">The maximum dimensions that the texture should be.</param>
/// <param name="wrapModeS">The texture wrap mode in horizontal direction.</param>
/// <param name="wrapModeT">The texture wrap mode in vertical direction.</param>
/// <returns>A matching texture, or null if unavailable.</returns>
Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT);
Texture? GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default);

/// <summary>
/// Retrieve a <see cref="SampleChannel"/>.
Expand Down
5 changes: 3 additions & 2 deletions osu.Game/Skinning/LegacySkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ protected override void ParseConfigurationStream(Stream stream)
return null;
}

public override Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
public override Texture? GetTexture(string componentName, Vector2? maxSize = null, WrapMode wrapModeS = default, WrapMode wrapModeT = default)
{
switch (componentName)
{
Expand Down Expand Up @@ -497,7 +497,8 @@ protected override void ParseConfigurationStream(Stream stream)
continue;

texture.ScaleAdjust = ratio;
return texture;

return texture.WithMaximumSize(maxSize);
}

return null;
Expand Down

0 comments on commit 96f12cf

Please sign in to comment.