mirror of
https://github.com/osukey/osukey.git
synced 2025-08-06 16:13:57 +09:00
Add support for reading skin frame rate from configuration file
This commit is contained in:
@ -46,17 +46,20 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
switch (osuComponent.Component)
|
switch (osuComponent.Component)
|
||||||
{
|
{
|
||||||
case OsuSkinComponents.FollowPoint:
|
case OsuSkinComponents.FollowPoint:
|
||||||
return this.GetAnimation(component.LookupName, true, false);
|
return this.GetAnimation(component.LookupName, true, false, true);
|
||||||
|
|
||||||
case OsuSkinComponents.SliderFollowCircle:
|
case OsuSkinComponents.SliderFollowCircle:
|
||||||
var followCircle = this.GetAnimation("sliderfollowcircle", true, true);
|
var followCircle = this.GetAnimation("sliderfollowcircle", true, true, true);
|
||||||
if (followCircle != null)
|
if (followCircle != null)
|
||||||
// follow circles are 2x the hitcircle resolution in legacy skins (since they are scaled down from >1x
|
// follow circles are 2x the hitcircle resolution in legacy skins (since they are scaled down from >1x
|
||||||
followCircle.Scale *= 0.5f;
|
followCircle.Scale *= 0.5f;
|
||||||
return followCircle;
|
return followCircle;
|
||||||
|
|
||||||
case OsuSkinComponents.SliderBall:
|
case OsuSkinComponents.SliderBall:
|
||||||
var sliderBallContent = this.GetAnimation("sliderb", true, true, "");
|
var sliderBallContent = this.GetAnimation("sliderb", true, true, animationSeparator: "");
|
||||||
|
|
||||||
|
// todo: slider ball has a custom frame delay based on velocity
|
||||||
|
// Math.Max((150 / Velocity) * GameBase.SIXTY_FRAME_TIME, GameBase.SIXTY_FRAME_TIME);
|
||||||
|
|
||||||
if (sliderBallContent != null)
|
if (sliderBallContent != null)
|
||||||
{
|
{
|
||||||
|
@ -5,5 +5,6 @@ namespace osu.Game.Skinning
|
|||||||
{
|
{
|
||||||
public enum GlobalSkinConfiguration
|
public enum GlobalSkinConfiguration
|
||||||
{
|
{
|
||||||
|
AnimationFramerate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
// 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.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Animations;
|
using osu.Framework.Graphics.Animations;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
@ -10,48 +12,62 @@ namespace osu.Game.Skinning
|
|||||||
{
|
{
|
||||||
public static class LegacySkinExtensions
|
public static class LegacySkinExtensions
|
||||||
{
|
{
|
||||||
public static Drawable GetAnimation(this ISkin source, string componentName, bool animatable, bool looping, string animationSeparator = "-")
|
public static Drawable GetAnimation(this ISkin source, string componentName, bool animatable, bool looping, bool applyConfigFrameRate = false, string animationSeparator = "-")
|
||||||
{
|
{
|
||||||
const double default_frame_time = 1000 / 60d;
|
|
||||||
|
|
||||||
Texture texture;
|
Texture texture;
|
||||||
|
|
||||||
Texture getFrameTexture(int frame) => source.GetTexture($"{componentName}{animationSeparator}{frame}");
|
|
||||||
|
|
||||||
TextureAnimation animation = null;
|
|
||||||
|
|
||||||
if (animatable)
|
if (animatable)
|
||||||
{
|
{
|
||||||
for (int i = 0; true; i++)
|
var textures = getTextures().ToArray();
|
||||||
|
|
||||||
|
if (textures.Length > 0)
|
||||||
{
|
{
|
||||||
if ((texture = getFrameTexture(i)) == null)
|
var animation = new TextureAnimation
|
||||||
break;
|
|
||||||
|
|
||||||
if (animation == null)
|
|
||||||
{
|
{
|
||||||
animation = new TextureAnimation
|
DefaultFrameLength = getFrameLength(source, applyConfigFrameRate, textures),
|
||||||
{
|
Repeat = looping,
|
||||||
DefaultFrameLength = default_frame_time,
|
};
|
||||||
Repeat = looping
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
animation.AddFrame(texture);
|
foreach (var t in textures)
|
||||||
|
animation.AddFrame(t);
|
||||||
|
|
||||||
|
return animation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (animation != null)
|
// if an animation was not allowed or not found, fall back to a sprite retrieval.
|
||||||
return animation;
|
|
||||||
|
|
||||||
if ((texture = source.GetTexture(componentName)) != null)
|
if ((texture = source.GetTexture(componentName)) != null)
|
||||||
{
|
return new Sprite { Texture = texture };
|
||||||
return new Sprite
|
|
||||||
{
|
|
||||||
Texture = texture
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
IEnumerable<Texture> getTextures()
|
||||||
|
{
|
||||||
|
for (int i = 0; true; i++)
|
||||||
|
{
|
||||||
|
if ((texture = source.GetTexture($"{componentName}{animationSeparator}{i}")) == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
yield return texture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private const double default_frame_time = 1000 / 60d;
|
||||||
|
|
||||||
|
private static double getFrameLength(ISkin source, bool applyConfigFrameRate, Texture[] textures)
|
||||||
|
{
|
||||||
|
if (applyConfigFrameRate)
|
||||||
|
{
|
||||||
|
var iniRate = source.GetConfig<GlobalSkinConfiguration, int>(GlobalSkinConfiguration.AnimationFramerate);
|
||||||
|
|
||||||
|
if (iniRate != null)
|
||||||
|
return 1000f / iniRate.Value;
|
||||||
|
|
||||||
|
return 1000f / textures.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return default_frame_time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user