Add door interaction system with requirements and HUD integration
This commit is contained in:
54
Code/Presenters/DoorPresenter.cs
Normal file
54
Code/Presenters/DoorPresenter.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using GameCore.ECS;
|
||||
using GameCore.ECS.Interfaces;
|
||||
using GameCore.Interaction;
|
||||
using Godot;
|
||||
|
||||
namespace CryptonymThunder.Code.Presenters;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class DoorPresenter : AnimatableBody3D, IEntityPresenter, IPresenterComponent
|
||||
{
|
||||
[Export] private AnimationPlayer _animationPlayer;
|
||||
[Export] private string _openAnimationName = "Open";
|
||||
|
||||
private DoorComponent _doorComponent;
|
||||
private Animation _openAnimation;
|
||||
|
||||
public Entity CoreEntity { get; set; }
|
||||
|
||||
public void Initialize(Entity coreEntity, World world)
|
||||
{
|
||||
CoreEntity = coreEntity;
|
||||
_doorComponent = world.GetComponent<DoorComponent>(CoreEntity);
|
||||
|
||||
if (_animationPlayer == 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}'");
|
||||
return;
|
||||
}
|
||||
|
||||
_openAnimation = _animationPlayer.GetAnimation(_openAnimationName);
|
||||
_animationPlayer.Play(_openAnimationName);
|
||||
_animationPlayer.Pause();
|
||||
SyncToPresentation(0f);
|
||||
}
|
||||
|
||||
public void SyncToPresentation(float delta)
|
||||
{
|
||||
if (_doorComponent == null || _openAnimation == null) return;
|
||||
|
||||
var targetTime = _doorComponent.OpenProgress * _openAnimation.Length;
|
||||
|
||||
_animationPlayer.Seek(targetTime, true);
|
||||
}
|
||||
|
||||
public void SyncToCore(float delta)
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user