Add door behavior interface and implementations for animation and linear movement

This commit is contained in:
2025-10-30 01:31:20 +01:00
parent 5ae8b6f08c
commit f2ff758dcb
10 changed files with 162 additions and 66 deletions

View File

@@ -0,0 +1,49 @@
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);
}
}