Exemple #1
0
 private void ParseImageLayerXml(XElement xml)
 {
     if (xml.Element("image") == null)
     {
         Logger.WriteWarning("Image Layer '{0}' is being ignored since it has no image.", base.Name);
         base.Ignore = IgnoreSettings.True;
     }
     else
     {
         Width  = 1;
         Height = 1;
         string  imagePath = TmxHelper.GetAttributeAsFullPath(xml.Element("image"), "source");
         TmxTile value     = base.ParentMap.Tiles.First((KeyValuePair <uint, TmxTile> t) => t.Value.TmxImage.AbsolutePath.ToLower() == imagePath.ToLower()).Value;
         Data = new TmxData(this);
         TmxChunk tmxChunk = new TmxChunk(Data);
         tmxChunk.X      = 0;
         tmxChunk.Y      = 0;
         tmxChunk.Width  = 1;
         tmxChunk.Height = 1;
         tmxChunk.TileIds.Add(value.GlobalId);
         Data.Chunks.Add(tmxChunk);
         PointF offset = base.Offset;
         offset.Y -= (float)base.ParentMap.TileHeight;
         offset.Y += (float)value.TmxImage.Size.Height;
         PointF pointF = TmxMath.TileCornerInScreenCoordinates(base.ParentMap, 0, 0);
         offset.X   -= pointF.X;
         offset.Y   -= pointF.Y;
         offset.X   += TmxHelper.GetAttributeAsFloat(xml, "x", 0f);
         offset.Y   += TmxHelper.GetAttributeAsFloat(xml, "y", 0f);
         base.Offset = offset;
     }
 }
Exemple #2
0
 public static List <TmxChunk> ListFromDataXml(XElement xml, TmxData parentData)
 {
     if (xml.Element("chunk") == null)
     {
         return(ListFromDataXml_Finite(xml, parentData));
     }
     return(ListFromDataXml_Infinite(xml, parentData));
 }
Exemple #3
0
 public TmxLayer(TmxLayerNode parent, TmxMap map)
     : base(parent, map)
 {
     base.Visible    = true;
     base.Opacity    = 1f;
     Data            = new TmxData(this);
     CollisionLayers = new List <TmxLayer>();
 }
Exemple #4
0
        public static TmxData FromDataXml(XElement xml, TmxLayer parentLayer)
        {
            TmxData tmxData = new TmxData(parentLayer);

            tmxData.Encoding    = TmxHelper.GetAttributeAsEnum(xml, "encoding", DataEncoding.Xml);
            tmxData.Compression = TmxHelper.GetAttributeAsEnum(xml, "compression", DataCompression.None);
            tmxData.Chunks      = TmxChunk.ListFromDataXml(xml, tmxData);
            return(tmxData);
        }
Exemple #5
0
        public TmxData MakeEmptyCopy(TmxLayer parent)
        {
            TmxData data = new TmxData(parent);

            data.Encoding    = Encoding;
            data.Compression = Compression;
            data.Chunks      = (from c in Chunks
                                select c.MakeEmptyCopy(data)).ToList();
            return(data);
        }
Exemple #6
0
        private static List <TmxChunk> ListFromDataXml_Finite(XElement xml, TmxData parentData)
        {
            TmxChunk tmxChunk = new TmxChunk(parentData);

            tmxChunk.X      = 0;
            tmxChunk.Y      = 0;
            tmxChunk.Width  = parentData.ParentLayer.Width;
            tmxChunk.Height = parentData.ParentLayer.Height;
            tmxChunk.ReadTileIds(xml);
            return(tmxChunk.ToEnumerable().ToList());
        }
Exemple #7
0
 public TmxChunk MakeEmptyCopy(TmxData parentData)
 {
     return(new TmxChunk(parentData)
     {
         X = X,
         Y = Y,
         Width = Width,
         Height = Height,
         TileIds = Enumerable.Repeat(0u, TileIds.Count).ToList()
     });
 }
Exemple #8
0
        private static List <TmxChunk> ListFromDataXml_Infinite(XElement xml, TmxData parentData)
        {
            List <TmxChunk> list = new List <TmxChunk>();

            foreach (XElement item in xml.Elements("chunk"))
            {
                TmxChunk tmxChunk = new TmxChunk(parentData);
                tmxChunk.X      = TmxHelper.GetAttributeAsInt(item, "x", 0);
                tmxChunk.Y      = TmxHelper.GetAttributeAsInt(item, "y", 0);
                tmxChunk.Width  = TmxHelper.GetAttributeAsInt(item, "width", 0);
                tmxChunk.Height = TmxHelper.GetAttributeAsInt(item, "height", 0);
                tmxChunk.ReadTileIds(item);
                list.Add(tmxChunk);
            }
            return(list);
        }
Exemple #9
0
 public TmxChunk(TmxData parentData)
 {
     ParentData = parentData;
     TileIds    = new List <uint>();
 }
Exemple #10
0
 private void ParseData(XElement elem)
 {
     Logger.WriteVerbose("Parse {0} layer data ...", base.Name);
     Data = TmxData.FromDataXml(elem, this);
 }