using Microsoft.Xna.Framework;
using MonoGame.FourEngine.Entities;
using MonoGame.FourEngine.Resources;
using MonoGame.FourEngine.Sample.Win32.Scenes;
using static MonoGame.FourEngine.Components.AnimationComponent;

namespace MonoGame.FourEngine.Sample.Win32.Entities
{
    public class HeroEntity : BasicEntity
    {
        protected override SpriteDefinition SpriteDefinition
            => new SpriteDefinition
            {
                FileName = Resources.Sprites.HeroSprite,
                Size = new Point(40),
                Margin = new Point(1)
            };

        public HeroEntity()
        {
            AnimationComponent.StartAnimation(
                FramedAnimation.GenerateRange(new Range(0, 4), 2, 100, true));
        }

        public override void OnAttach(Scene scene)
        {
            base.OnAttach(scene);
            if (scene is TestScene testScene)
                AttachScene(testScene);
        }

        public override void OnUpdate(UpdateEventArgs args)
        {
            base.OnUpdate(args);
            Position = new Point(Position.X + 1, Position.Y);
        }

        private void AttachScene(TestScene scene)
        {
            Transformations.Add(scene.Camera.Transform);
        }
    }
}