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(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) { } }