Add door behavior interface and implementations for animation and linear movement
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using CryptonymThunder.Code.Resources;
|
||||
using GameCore.ECS;
|
||||
using GameCore.ECS.Interfaces;
|
||||
using GameCore.Interaction;
|
||||
@@ -6,13 +7,11 @@ using Godot;
|
||||
namespace CryptonymThunder.Code.Presenters;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class DoorPresenter : AnimatableBody3D, IEntityPresenter, IPresenterComponent
|
||||
public partial class DoorPresenter : CharacterBody3D, IEntityPresenter, IPresenterComponent
|
||||
{
|
||||
[Export] private AnimationPlayer _animationPlayer;
|
||||
[Export] private string _openAnimationName = "Open";
|
||||
[Export] private DoorBehaviorResource _behavior;
|
||||
|
||||
private DoorComponent _doorComponent;
|
||||
private Animation _openAnimation;
|
||||
|
||||
public Entity CoreEntity { get; set; }
|
||||
|
||||
@@ -21,31 +20,21 @@ public partial class DoorPresenter : AnimatableBody3D, IEntityPresenter, IPresen
|
||||
CoreEntity = coreEntity;
|
||||
_doorComponent = world.GetComponent<DoorComponent>(CoreEntity);
|
||||
|
||||
if (_animationPlayer == null)
|
||||
if (_behavior == null)
|
||||
{
|
||||
world.Logger.Error($"DoorPresenter '{Name}' is missing an AnimationPlayer!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_animationPlayer.HasAnimation(_openAnimationName))
|
||||
{
|
||||
world.Logger.Error($"DoorPresenter '{Name}' AnimationPlayer is missing animation: '{_openAnimationName}'");
|
||||
world.Logger.Error($"DoorPresenter '{Name}' is missing a DoorBehaviorResource!");
|
||||
return;
|
||||
}
|
||||
|
||||
_openAnimation = _animationPlayer.GetAnimation(_openAnimationName);
|
||||
_animationPlayer.Play(_openAnimationName);
|
||||
_animationPlayer.Pause();
|
||||
_behavior.Initialize(this, world);
|
||||
|
||||
SyncToPresentation(0f);
|
||||
}
|
||||
|
||||
public void SyncToPresentation(float delta)
|
||||
{
|
||||
if (_doorComponent == null || _openAnimation == null) return;
|
||||
|
||||
var targetTime = _doorComponent.OpenProgress * _openAnimation.Length;
|
||||
|
||||
_animationPlayer.Seek(targetTime, true);
|
||||
if (_doorComponent == null || _behavior == null) return;
|
||||
_behavior.UpdateProgress(_doorComponent.OpenProgress, delta);
|
||||
}
|
||||
|
||||
public void SyncToCore(float delta)
|
||||
|
||||
Reference in New Issue
Block a user