using Encompass;
using KavTest.Components;
using KavTest.Messages;

namespace KavTest.Engines
{
    [Reads(typeof(CameraComponent))]
    [Receives(typeof(MoveCameraMessage))]
    [Sends(typeof(LocalTranslationMessage))]
    public class CameraEngine : Engine
    {
        public override void Update(double dt)
        {
            if (SomeComponent<CameraComponent>())
            {
                var cameraEntity = ReadEntity<CameraComponent>();

                foreach (var moveMessage in ReadMessages<MoveCameraMessage>())
                {
                    SendMessage(new LocalTranslationMessage(cameraEntity, moveMessage.Translation * (float)dt));
                }
            }
        }
    }
}
