public static TiledMapObjectType GetObjectType(TiledMapObjectContent content)
        {
            if (content.GlobalIdentifier > 0)
            {
                return(TiledMapObjectType.Tile);
            }

            if (content.Ellipse != null)
            {
                return(TiledMapObjectType.Ellipse);
            }

            if (content.Polygon != null)
            {
                return(TiledMapObjectType.Polygon);
            }

            // ReSharper disable once ConvertIfStatementToReturnStatement
            if (content.Polyline != null)
            {
                return(TiledMapObjectType.Polyline);
            }

            return(TiledMapObjectType.Rectangle);
        }
        private static void WriteObject(ContentWriter writer, TiledMapObjectContent @object)
        {
            var type = GetObjectType(@object);

            writer.Write((byte)type);

            writer.Write(@object.Identifier);
            writer.Write(@object.Name ?? string.Empty);
            writer.Write(@object.Type ?? string.Empty);
            writer.Write(@object.X);
            writer.Write(@object.Y);
            writer.Write(@object.Width);
            writer.Write(@object.Height);
            writer.Write(@object.Rotation);
            writer.Write(@object.Visible);

            writer.WriteTiledMapProperties(@object.Properties);

            switch (type)
            {
            case TiledMapObjectType.Rectangle:
            case TiledMapObjectType.Ellipse:
                break;

            case TiledMapObjectType.Tile:
                writer.Write(@object.GlobalIdentifier);
                break;

            case TiledMapObjectType.Polygon:
                WritePolyPoints(writer, @object.Polygon.Points);
                break;

            case TiledMapObjectType.Polyline:
                WritePolyPoints(writer, @object.Polyline.Points);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public static void Process(TiledMapObjectContent obj, ContentProcessorContext context)
        {
            if (!string.IsNullOrWhiteSpace(obj.TemplateSource))
            {
                var externalReference = new ExternalReference <TiledMapObjectLayerContent>(obj.TemplateSource);
                var template          = context.BuildAndLoadAsset <TiledMapObjectLayerContent, TiledMapObjectTemplateContent>(externalReference, "");

                // Nothing says a template can't reference another template.
                // Yay recusion!
                Process(template.Object, context);

                if (!obj._globalIdentifier.HasValue && template.Object._globalIdentifier.HasValue)
                {
                    obj.GlobalIdentifier = template.Object.GlobalIdentifier;
                }

                if (!obj._height.HasValue && template.Object._height.HasValue)
                {
                    obj.Height = template.Object.Height;
                }

                if (!obj._identifier.HasValue && template.Object._identifier.HasValue)
                {
                    obj.Identifier = template.Object.Identifier;
                }

                if (!obj._rotation.HasValue && template.Object._rotation.HasValue)
                {
                    obj.Rotation = template.Object.Rotation;
                }

                if (!obj._visible.HasValue && template.Object._visible.HasValue)
                {
                    obj.Visible = template.Object.Visible;
                }

                if (!obj._width.HasValue && template.Object._width.HasValue)
                {
                    obj.Width = template.Object.Width;
                }

                if (!obj._x.HasValue && template.Object._x.HasValue)
                {
                    obj.X = template.Object.X;
                }

                if (!obj._y.HasValue && template.Object._y.HasValue)
                {
                    obj.Y = template.Object.Y;
                }

                if (obj.Ellipse == null && template.Object.Ellipse != null)
                {
                    obj.Ellipse = template.Object.Ellipse;
                }

                if (string.IsNullOrWhiteSpace(obj.Name) && !string.IsNullOrWhiteSpace(template.Object.Name))
                {
                    obj.Name = template.Object.Name;
                }

                if (obj.Polygon == null && template.Object.Polygon != null)
                {
                    obj.Polygon = template.Object.Polygon;
                }

                if (obj.Polyline == null && template.Object.Polyline != null)
                {
                    obj.Polyline = template.Object.Polyline;
                }

                foreach (var tProperty in template.Object.Properties)
                {
                    if (!obj.Properties.Exists(p => p.Name == tProperty.Name))
                    {
                        obj.Properties.Add(tProperty);
                    }
                }

                if (string.IsNullOrWhiteSpace(obj.Type) && !string.IsNullOrWhiteSpace(template.Object.Type))
                {
                    obj.Type = template.Object.Type;
                }
            }
        }