49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using cryptonymthunder.Code.Interfaces;
|
|
using GameCore.ECS;
|
|
using Godot;
|
|
|
|
namespace CryptonymThunder.Code.Resources;
|
|
|
|
[GlobalClass]
|
|
public partial class AnimationPlayerDoorBehavior : DoorBehaviorResource, IDoorBehavior
|
|
{
|
|
[Export] private NodePath _animationPlayerPath;
|
|
[Export] private string _animationName = "Open";
|
|
|
|
private AnimationPlayer _animationPlayer;
|
|
private Animation _animation;
|
|
|
|
public override void Initialize(Node3D doorNode, World world)
|
|
{
|
|
if (_animationPlayerPath == null)
|
|
{
|
|
world.Logger.Error($"[AnimationPlayerDoorBehavior] NodePath is not set for door '{doorNode.Name}'");
|
|
return;
|
|
}
|
|
|
|
_animationPlayer = doorNode.GetNode<AnimationPlayer>(_animationPlayerPath);
|
|
if (_animationPlayer == null)
|
|
{
|
|
world.Logger.Error($"[AnimationPlayerDoorBehavior] Could not find AnimationPlayer at path '{_animationPlayerPath}' on door '{doorNode.Name}'");
|
|
return;
|
|
}
|
|
|
|
if (!_animationPlayer.HasAnimation(_animationName))
|
|
{
|
|
world.Logger.Error($"[AnimationPlayerDoorBehavior] AnimationPlayer on '{doorNode.Name}' is missing animation: '{_animationName}'");
|
|
return;
|
|
}
|
|
|
|
_animation = _animationPlayer.GetAnimation(_animationName);
|
|
_animationPlayer.Play(_animationName);
|
|
_animationPlayer.Pause();
|
|
}
|
|
|
|
public override void UpdateProgress(float progress, float delta)
|
|
{
|
|
if (_animationPlayer == null || _animation == null) return;
|
|
|
|
var targetTime = progress * _animation.Length;
|
|
_animationPlayer.Seek(targetTime, true);
|
|
}
|
|
} |