1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 23:59:16 +08:00

Refactor texture lookup code

This commit is contained in:
Dean Herbert 2019-08-19 19:23:54 +09:00
parent d02b8d14f7
commit 539a27a557

View File

@ -1,4 +1,4 @@
// 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 System;
@ -142,28 +142,31 @@ namespace osu.Game.Skinning
}; };
} }
return getAnimation(componentName, animatable, looping);
}
private Drawable getAnimation(string componentName, bool animatable, bool looping, string animationSeparator = "-")
{
Texture texture; Texture texture;
if (animatable && (texture = GetTexture($"{componentName}-0")) != null) Texture getFrameTexture(int frame) => GetTexture($"{componentName}{animationSeparator}{frame}");
if (animatable && (texture = getFrameTexture(0)) != null)
{ {
var animation = new TextureAnimation { DefaultFrameLength = default_frame_time }; var animation = new TextureAnimation { DefaultFrameLength = default_frame_time };
for (int i = 1; texture != null; i++) for (int i = 1; texture != null; i++)
{ {
animation.AddFrame(texture); animation.AddFrame(texture);
texture = GetTexture($"{componentName}-{i}"); texture = getFrameTexture(i);
} }
animation.Repeat = looping; animation.Repeat = looping;
return animation; return animation;
} }
else
{
texture = GetTexture(componentName);
return texture == null ? null : new Sprite { Texture = texture }; return (texture = GetTexture(componentName)) == null ? null : new Sprite { Texture = texture };
}
} }
public class LegacySliderBall : Sprite public class LegacySliderBall : Sprite