osu/osu.Game/Skinning/LegacySkinExtensions.cs

58 lines
1.7 KiB
C#
Raw Normal View History

// 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;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
namespace osu.Game.Skinning
{
public static class LegacySkinExtensions
{
public static Drawable GetAnimation(this ISkin source, string componentName, bool animatable, bool looping, string animationSeparator = "-")
{
const double default_frame_time = 1000 / 60d;
Texture texture;
Texture getFrameTexture(int frame) => source.GetTexture($"{componentName}{animationSeparator}{frame}");
TextureAnimation animation = null;
if (animatable)
{
2019-11-11 11:53:22 +00:00
for (int i = 0; true; i++)
{
if ((texture = getFrameTexture(i)) == null)
break;
if (animation == null)
2019-11-11 11:53:22 +00:00
{
animation = new TextureAnimation
{
DefaultFrameLength = default_frame_time,
Repeat = looping
};
2019-11-11 11:53:22 +00:00
}
animation.AddFrame(texture);
}
}
if (animation != null)
return animation;
if ((texture = source.GetTexture(componentName)) != null)
2019-11-11 11:53:22 +00:00
{
return new Sprite
{
Texture = texture
};
2019-11-11 11:53:22 +00:00
}
return null;
}
}
}