mirror of
https://github.com/osukey/osukey.git
synced 2025-05-30 01:47:30 +09:00
Refactor animation lookup to properly handle skins providing non-animated resources
This commit is contained in:
parent
e7e9197f03
commit
2c1f22d7ae
@ -27,6 +27,18 @@ namespace osu.Game.Skinning
|
|||||||
{
|
{
|
||||||
Texture texture;
|
Texture texture;
|
||||||
|
|
||||||
|
// find the first source which provides either the animated or non-animated version.
|
||||||
|
ISkin skin = (source as ISkinSource)?.FindProvider(s =>
|
||||||
|
{
|
||||||
|
if (animatable && s.GetTexture(getFrameName(0)) != null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return s.GetTexture(componentName, wrapModeS, wrapModeT) != null;
|
||||||
|
}) ?? source;
|
||||||
|
|
||||||
|
if (skin == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
if (animatable)
|
if (animatable)
|
||||||
{
|
{
|
||||||
var textures = getTextures().ToArray();
|
var textures = getTextures().ToArray();
|
||||||
@ -35,7 +47,7 @@ namespace osu.Game.Skinning
|
|||||||
{
|
{
|
||||||
var animation = new SkinnableTextureAnimation(startAtCurrentTime)
|
var animation = new SkinnableTextureAnimation(startAtCurrentTime)
|
||||||
{
|
{
|
||||||
DefaultFrameLength = frameLength ?? getFrameLength(source, applyConfigFrameRate, textures),
|
DefaultFrameLength = frameLength ?? getFrameLength(skin, applyConfigFrameRate, textures),
|
||||||
Loop = looping,
|
Loop = looping,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -47,28 +59,23 @@ namespace osu.Game.Skinning
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if an animation was not allowed or not found, fall back to a sprite retrieval.
|
// if an animation was not allowed or not found, fall back to a sprite retrieval.
|
||||||
if ((texture = source.GetTexture(componentName, wrapModeS, wrapModeT)) != null)
|
if ((texture = skin.GetTexture(componentName, wrapModeS, wrapModeT)) != null)
|
||||||
return new Sprite { Texture = texture };
|
return new Sprite { Texture = texture };
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
IEnumerable<Texture> getTextures()
|
IEnumerable<Texture> getTextures()
|
||||||
{
|
{
|
||||||
ISkin lookupSource = null;
|
|
||||||
|
|
||||||
for (int i = 0; true; i++)
|
for (int i = 0; true; i++)
|
||||||
{
|
{
|
||||||
string frameName = $"{componentName}{animationSeparator}{i}";
|
if ((texture = skin.GetTexture(getFrameName(i), wrapModeS, wrapModeT)) == null)
|
||||||
|
|
||||||
// ensure all textures are retrieved from the same skin source.
|
|
||||||
lookupSource ??= (source as ISkinSource)?.FindProvider(s => s.GetTexture(frameName, wrapModeS, wrapModeT) != null) ?? source;
|
|
||||||
|
|
||||||
if ((texture = lookupSource?.GetTexture(frameName, wrapModeS, wrapModeT)) == null)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
yield return texture;
|
yield return texture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string getFrameName(int frameIndex) => $"{componentName}{animationSeparator}{frameIndex}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HasFont(this ISkin source, LegacyFont font)
|
public static bool HasFont(this ISkin source, LegacyFont font)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user