1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:07:52 +08:00

Merge pull request #8669 from bdach/fix-legacy-skin-fallback

Fix legacy skin texture fallback logic
This commit is contained in:
Dean Herbert 2020-04-08 10:47:11 +09:00 committed by GitHub
commit d63cfdc024
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 112 additions and 2 deletions

View File

@ -0,0 +1,109 @@
// 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.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics.Textures;
using osu.Game.Skinning;
namespace osu.Game.Tests.NonVisual.Skinning
{
[TestFixture]
public sealed class LegacySkinTextureFallbackTest
{
private static object[][] fallbackTestCases =
{
new object[]
{
// textures in store
new[] { "Gameplay/osu/followpoint@2x", "Gameplay/osu/followpoint" },
// requested component
"Gameplay/osu/followpoint",
// returned texture name & scale
"Gameplay/osu/followpoint@2x", 2
},
new object[]
{
new[] { "Gameplay/osu/followpoint@2x" },
"Gameplay/osu/followpoint",
"Gameplay/osu/followpoint@2x", 2
},
new object[]
{
new[] { "Gameplay/osu/followpoint" },
"Gameplay/osu/followpoint",
"Gameplay/osu/followpoint", 1
},
new object[]
{
new[] { "Gameplay/osu/followpoint", "followpoint@2x" },
"Gameplay/osu/followpoint",
"Gameplay/osu/followpoint", 1
},
new object[]
{
new[] { "followpoint@2x", "followpoint" },
"Gameplay/osu/followpoint",
"followpoint@2x", 2
},
new object[]
{
new[] { "followpoint@2x" },
"Gameplay/osu/followpoint",
"followpoint@2x", 2
},
new object[]
{
new[] { "followpoint" },
"Gameplay/osu/followpoint",
"followpoint", 1
},
};
[TestCaseSource(nameof(fallbackTestCases))]
public void TestFallbackOrder(string[] filesInStore, string requestedComponent, string expectedTexture, float expectedScale)
{
var textureStore = new TestTextureStore(filesInStore);
var legacySkin = new TestLegacySkin(textureStore);
var texture = legacySkin.GetTexture(requestedComponent);
Assert.IsNotNull(texture);
Assert.AreEqual(textureStore.Textures[expectedTexture], texture);
Assert.AreEqual(expectedScale, texture.ScaleAdjust);
}
[Test]
public void TestReturnNullOnFallbackFailure()
{
var textureStore = new TestTextureStore("sliderb", "hit100");
var legacySkin = new TestLegacySkin(textureStore);
var texture = legacySkin.GetTexture("Gameplay/osu/followpoint");
Assert.IsNull(texture);
}
private class TestLegacySkin : LegacySkin
{
public TestLegacySkin(TextureStore textureStore)
: base(new SkinInfo(), null, null, string.Empty)
{
Textures = textureStore;
}
}
private class TestTextureStore : TextureStore
{
public readonly Dictionary<string, Texture> Textures;
public TestTextureStore(params string[] fileNames)
{
Textures = fileNames.ToDictionary(fileName => fileName, fileName => new Texture(1, 1));
}
public override Texture Get(string name) => Textures.GetValueOrDefault(name);
}
}
}

View File

@ -293,9 +293,10 @@ namespace osu.Game.Skinning
texture = Textures?.Get(name);
}
if (texture != null)
texture.ScaleAdjust = ratio;
if (texture == null)
continue;
texture.ScaleAdjust = ratio;
return texture;
}