SupaLidlGame/Extensions/AnimationPlayer.cs

69 lines
1.6 KiB
C#
Raw Normal View History

2023-08-05 23:50:08 -07:00
using Godot;
2023-08-08 00:54:00 -07:00
namespace SupaLidlGame.Extensions;
2023-08-05 23:50:08 -07:00
public static class AnimationPlayerExtensions
{
public static bool TryPlay(this AnimationPlayer player, string name)
{
var hasAnimation = player.HasAnimation(name);
if (hasAnimation)
{
player.Play(name);
}
return hasAnimation;
}
2023-10-02 00:10:24 -07:00
public static bool TryPlayAny(this AnimationPlayer player,
params string[] names)
{
return player.TryPlayAny(out var _, names);
}
public static bool TryPlayAny(this AnimationPlayer player,
out string resultName, params string[] names)
{
foreach (string name in names)
{
if (player.TryPlay(name))
{
resultName = name;
return true;
}
}
resultName = default;
return false;
}
2023-08-05 23:50:08 -07:00
public static bool TryQueue(this AnimationPlayer player, string name)
{
var hasAnimation = player.HasAnimation(name);
if (hasAnimation)
{
player.Queue(name);
}
return hasAnimation;
}
2023-10-02 00:10:24 -07:00
public static bool TryQueueAny(this AnimationPlayer player,
params string[] names)
{
return player.TryQueueAny(out var _, names);
}
public static bool TryQueueAny(this AnimationPlayer player,
out string resultName, params string[] names)
{
foreach (string name in names)
{
if (player.TryQueue(name))
{
resultName = name;
return true;
}
}
resultName = default;
return false;
}
2023-08-05 23:50:08 -07:00
}