Exemple #1
0
        /// <summary>
        ///  The effective anchor point, if not defined otherwise
        ///  will be aligned to the bottom edge of the graphic and
        ///  centred horizontally.
        /// </summary>
        /// <param name="tile"></param>
        /// <returns></returns>
        public IntPoint ComputeEffectiveAnchorPoint(TextureTile tile)
        {
            var tileSize     = EffectiveTileSize;
            var size         = EffectiveCellSize;
            var anchorPointX = tile.AnchorX ?? AnchorX ?? size.Width / 2;
            var anchorPointY = tile.AnchorY ?? AnchorY ?? size.Height - tileSize.Height / 2;

            return(new IntPoint(anchorPointX, anchorPointY));
        }
Exemple #2
0
        public TextureGrid WithTextureTile([JetBrains.Annotations.NotNull] TextureTile t)
        {
            if (t == null)
            {
                throw new ArgumentNullException(nameof(t));
            }

            Tiles.Add(t);
            return(this);
        }
Exemple #3
0
        public static TextureTile ReadTiles(XElement tile)
        {
            var x       = (int?)tile.AttributeLocal("x") ?? throw new XmlParseException("Required attribute 'y' not found", tile);
            var y       = (int?)tile.AttributeLocal("y") ?? throw new XmlParseException("Required attribute 'y' not found", tile);
            var anchorX = (int?)tile.AttributeLocal("anchor-x");
            var anchorY = (int?)tile.AttributeLocal("anchor-y");
            var name    = (string?)tile.ElementLocal("name");

            var tags =
                from e in tile.Elements()
                where e.Name.LocalName == "tag"
                select(string) e;

            var tagsAsList = tags.ToList();

            if (name != null && tagsAsList.Count == 0)
            {
                tagsAsList.Add(name);
            }

            var tag = (string?)tile.AttributeLocal("tag");

            var autoGenerated = (bool?)tile.ElementLocal("metadata")?.Attribute("auto-generated") ?? false;
            var selectorHint  = (string?)tile.ElementLocal("metadata")?.Attribute("selector-hint");

            var tileValue = new TextureTile(autoGenerated)
            {
                X            = x,
                Y            = y,
                AnchorX      = anchorX,
                AnchorY      = anchorY,
                SelectorHint = selectorHint
            };

            if (!string.IsNullOrWhiteSpace(tag) && !tagsAsList.Contains(tag))
            {
                tileValue.Tags.Add(tag);
            }

            tileValue.Tags.AddRange(tagsAsList);
            return(tileValue);
        }
Exemple #4
0
        public static XElement GenerateTile(TextureTile tile)
        {
            var tileElement = new XElement(Namespace + "tile");

            tileElement.Add(new XAttribute("x", tile.X));
            tileElement.Add(new XAttribute("y", tile.Y));
            tile.AnchorX.ForNonNull(a => tileElement.Add(new XAttribute("anchor-x", a)));
            tile.AnchorY.ForNonNull(a => tileElement.Add(new XAttribute("anchor-y", a)));

            var md = new XElement(Namespace + "metadata");

            if (tile.AutoGenerated)
            {
                md.Add(new XAttribute("auto-generated", tile.AutoGenerated));
            }
            if (!string.IsNullOrEmpty(tile.SelectorHint))
            {
                md.Add(new XAttribute("selector-hint", tile.SelectorHint));
            }

            if (md.HasElements || md.HasAttributes)
            {
                tileElement.Add(md);
            }

            var filteredTags = tile.Tags.Where(tn => !string.IsNullOrEmpty(tn)).ToList();

            if (filteredTags.Count == 1)
            {
                tileElement.Add(new XAttribute("tag", filteredTags[0]));
            }
            else
            {
                tileElement.AddRange(filteredTags.Select(t => new XElement(Namespace + "tag", t)));
            }


            return(tileElement);
        }