using Microsoft.Xna.Framework;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Xml.Linq;

namespace MonoGame.FourEngine.Tiled
{
    public class TiledPolylineObject : TiledObject
    {
        public List<Point> Polyline { get; set; }

        private XElement _xPolyline;

        public TiledPolylineObject(XElement xPolyline)
        {
            _xPolyline = xPolyline;
        }

        protected override void ParseImpl(XElement xElement)
        {
            base.ParseImpl(xElement);
            Polyline = _xPolyline
                .AttributeOrEmpty("points")
                .Value
                .Split(' ')
                .Select(x => x.Split(','))
                .Where(x => x.Count() == 2)
                .Select(x => new Point(
                    (int)float.Parse(x[0], CultureInfo.InvariantCulture),
                    (int)float.Parse(x[1], CultureInfo.InvariantCulture)))
                .ToList();
        }
    }
}