Ejemplo n.º 1
0
        public TmxGroup(TmxMap map, XElement xGroup, int width, int height, string tmxDirectory)
        {
            this.map = map;
            Name     = (string)xGroup.Attribute("name") ?? string.Empty;
            Opacity  = (float?)xGroup.Attribute("opacity") ?? 1.0f;
            Visible  = (bool?)xGroup.Attribute("visible") ?? true;
            OffsetX  = (float?)xGroup.Attribute("offsetx") ?? 0.0f;
            OffsetY  = (float?)xGroup.Attribute("offsety") ?? 0.0f;

            Properties = PropertyDict.ParsePropertyDict(xGroup.Element("properties"));

            layers       = new TmxList <ITmxLayer>();
            tileLayers   = new TmxList <TmxLayer>();
            objectGroups = new TmxList <TmxObjectGroup>();
            imageLayers  = new TmxList <TmxImageLayer>();
            groups       = new TmxList <TmxGroup>();
            foreach (var e in xGroup.Elements().Where(x => x.Name == "layer" || x.Name == "objectgroup" || x.Name == "imagelayer" || x.Name == "group"))
            {
                ITmxLayer layer;
                switch (e.Name.LocalName)
                {
                case "layer":
                    var tileLayer = new TmxLayer(map, e, width, height);
                    layer = tileLayer;
                    tileLayers.Add(tileLayer);
                    break;

                case "objectgroup":
                    var objectgroup = new TmxObjectGroup(map, e);
                    layer = objectgroup;
                    objectGroups.Add(objectgroup);
                    break;

                case "imagelayer":
                    var imagelayer = new TmxImageLayer(map, e, tmxDirectory);
                    layer = imagelayer;
                    imageLayers.Add(imagelayer);
                    break;

                case "group":
                    var group = new TmxGroup(map, e, width, height, tmxDirectory);
                    layer = group;
                    groups.Add(group);
                    break;

                default:
                    throw new InvalidOperationException();
                }
                layers.Add(layer);
            }
        }
Ejemplo n.º 2
0
        public static TmxGroup LoadTmxGroup(this TmxGroup group, TmxMap map, XElement xGroup, int width, int height, string tmxDirectory)
        {
            group.map     = map;
            group.Name    = (string)xGroup.Attribute("name") ?? string.Empty;
            group.Opacity = (float?)xGroup.Attribute("opacity") ?? 1.0f;
            group.Visible = (bool?)xGroup.Attribute("visible") ?? true;
            group.OffsetX = (float?)xGroup.Attribute("offsetx") ?? 0.0f;
            group.OffsetY = (float?)xGroup.Attribute("offsety") ?? 0.0f;

            group.Properties = ParsePropertyDict(xGroup.Element("properties"));

            group.Layers       = new TmxList <ITmxLayer>();
            group.TileLayers   = new TmxList <TmxLayer>();
            group.ObjectGroups = new TmxList <TmxObjectGroup>();
            group.ImageLayers  = new TmxList <TmxImageLayer>();
            group.Groups       = new TmxList <TmxGroup>();

            ParseLayers(group, xGroup, map, width, height, tmxDirectory);

            return(group);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// parses all the layers in xEle putting them in the container
        /// </summary>
        public static void ParseLayers(object container, XElement xEle, TmxMap map, int width, int height, string tmxDirectory)
        {
            foreach (var e in xEle.Elements().Where(x => x.Name == "layer" || x.Name == "objectgroup" || x.Name == "imagelayer" || x.Name == "group"))
            {
                ITmxLayer layer;
                switch (e.Name.LocalName)
                {
                case "layer":
                    var tileLayer = new TmxLayer().LoadTmxLayer(map, e, width, height);
                    layer = tileLayer;

                    if (container is TmxMap m)
                    {
                        m.TileLayers.Add(tileLayer);
                    }
                    else if (container is TmxGroup g)
                    {
                        g.TileLayers.Add(tileLayer);
                    }
                    break;

                case "objectgroup":
                    var objectgroup = new TmxObjectGroup().LoadTmxObjectGroup(map, e);
                    layer = objectgroup;

                    if (container is TmxMap mm)
                    {
                        mm.ObjectGroups.Add(objectgroup);
                    }
                    else if (container is TmxGroup gg)
                    {
                        gg.ObjectGroups.Add(objectgroup);
                    }
                    break;

                case "imagelayer":
                    var imagelayer = new TmxImageLayer().LoadTmxImageLayer(map, e, tmxDirectory);
                    layer = imagelayer;

                    if (container is TmxMap mmm)
                    {
                        mmm.ImageLayers.Add(imagelayer);
                    }
                    else if (container is TmxGroup ggg)
                    {
                        ggg.ImageLayers.Add(imagelayer);
                    }
                    break;

                case "group":
                    var newGroup = new TmxGroup().LoadTmxGroup(map, e, width, height, tmxDirectory);
                    layer = newGroup;

                    if (container is TmxMap mmmm)
                    {
                        mmmm.Groups.Add(newGroup);
                    }
                    else if (container is TmxGroup gggg)
                    {
                        gggg.Groups.Add(newGroup);
                    }
                    break;

                default:
                    throw new InvalidOperationException();
                }

                if (container is TmxMap mmmmm)
                {
                    mmmmm.Layers.Add(layer);
                }
                else if (container is TmxGroup g)
                {
                    g.Layers.Add(layer);
                }
            }
        }