Beispiel #1
0
 public int GetObjectCount(int groupID)
 {
     if (groupID >= 0 && groupID < objectGroups.Count)
     {
         TMXTileGroup grp = objectGroups[groupID];
         return(grp.objects.Count);
     }
     return(-1);
 }
Beispiel #2
0
 public int GetObjectHeight(int groupID, int objectID)
 {
     if (groupID >= 0 && groupID < objectGroups.Count)
     {
         TMXTileGroup grp = objectGroups[groupID];
         if (objectID >= 0 && objectID < grp.objects.Count)
         {
             TMXTile obj0 = grp.objects[objectID];
             return(obj0.height);
         }
     }
     return(-1);
 }
Beispiel #3
0
 public string GetObjectType(int groupID, int objectID)
 {
     if (groupID >= 0 && groupID < objectGroups.Count)
     {
         TMXTileGroup grp = objectGroups[groupID];
         if (objectID >= 0 && objectID < grp.objects.Count)
         {
             TMXTile obj0 = grp.objects[objectID];
             return(obj0.type);
         }
     }
     return(null);
 }
Beispiel #4
0
 public int GetObjectWidth(int groupID, int objectID)
 {
     if (groupID >= 0 && groupID < objectGroups.Count)
     {
         TMXTileGroup grp = (TMXTileGroup)objectGroups[groupID];
         if (objectID >= 0 && objectID < grp.objects.Count)
         {
             TMXTile obj0 = (TMXTile)grp.objects[objectID];
             return(obj0.width);
         }
     }
     return(-1);
 }
Beispiel #5
0
 public string GetObjectName(int groupID, int objectID)
 {
     if (groupID >= 0 && groupID < objectGroups.Count)
     {
         TMXTileGroup grp = (TMXTileGroup)objectGroups[groupID];
         if (objectID >= 0 && objectID < grp.objects.Count)
         {
             TMXTile obj0 = (TMXTile)grp.objects[objectID];
             return(obj0.name);
         }
     }
     return(null);
 }
Beispiel #6
0
        public string GetObjectProperty(int groupID, int objectID,
                                        string propertyName, string def)
        {
            if (groupID >= 0 && groupID < objectGroups.Count)
            {
                TMXTileGroup grp = objectGroups[groupID];
                if (objectID >= 0 && objectID < grp.objects.Count)
                {
                    TMXTile obj0 = grp.objects[objectID];

                    if (obj0 == null)
                    {
                        return(def);
                    }
                    if (obj0.props == null)
                    {
                        return(def);
                    }

                    return(obj0.props.GetProperty(propertyName, def));
                }
            }
            return(def);
        }
        private void Load(Stream ins0, string tileSetsLocation)
        {
            screenRect = LSystem.screenRect;

            tilesLocation = tileSetsLocation;

            try
            {
                XMLDocument doc = XMLParser.Parse(ins0);
                XMLElement docElement = doc.GetRoot();

                string orient = docElement.GetAttribute("orientation", "");
                if (!"orthogonal".Equals(orient))
                {
                    throw new Exception(
                            "Only orthogonal maps supported, found " + orient);
                }

                width = docElement.GetIntAttribute("width", 0);
                height = docElement.GetIntAttribute("height", 0);
                tileWidth = docElement.GetIntAttribute("tilewidth", 0);
                tileHeight = docElement.GetIntAttribute("tileheight", 0);

                XMLElement propsElement = (XMLElement)docElement
                        .GetChildrenByName("properties");
                if (propsElement != null)
                {
                    props = new TMXProperty();
                    List<XMLElement> property = propsElement.List("property");
                    for (int i = 0; i < property.Count; i++)
                    {
                        XMLElement propElement = property[i];
                        string name = propElement.GetAttribute("name", null);
                        string value_ren = propElement.GetAttribute("value", null);
                        props.SetProperty(name, value_ren);
                    }
                }

                if (loadTileSets)
                {
                    TMXTileSet tileSet = null;
                    TMXTileSet lastSet = null;

                    List<XMLElement> setNodes = docElement.List("tileset");
                    for (int i_0 = 0; i_0 < setNodes.Count; i_0++)
                    {
                        XMLElement current = setNodes[i_0];

                        tileSet = new TMXTileSet(this, current, true);
                        tileSet.index = i_0;

                        if (lastSet != null)
                        {
                            lastSet.SetLimit(tileSet.firstGID - 1);
                        }
                        lastSet = tileSet;

                        CollectionUtils.Add(tileSets, tileSet);
                    }
                }

                List<XMLElement> layerNodes = docElement.List("layer");
                for (int i_1 = 0; i_1 < layerNodes.Count; i_1++)
                {
                    XMLElement current_2 = layerNodes[i_1];
                    TMXLayer layer = new TMXLayer(this, current_2);
                    layer.index = i_1;

                    CollectionUtils.Add(layers, layer);
                }

                List<XMLElement> objectGroupNodes = docElement
                        .List("objectgroup");

                for (int i_3 = 0; i_3 < objectGroupNodes.Count; i_3++)
                {
                    XMLElement current_4 = objectGroupNodes[i_3];
                    TMXTileGroup objectGroup = new TMXTileGroup(current_4);
                    objectGroup.index = i_3;

                    CollectionUtils.Add(objectGroups, objectGroup);
                }

                defWidth = (int)(screenRect.GetWidth() / tileWidth);
                defHeight = (int)(screenRect.GetHeight() / tileHeight);

            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.StackTrace);
                throw new Exception("Failed to parse map", ex);
            }
        }
Beispiel #8
0
        private void Load(Stream ins, string tileSetsLocation)
        {
            screenRect = LSystem.screenRect;

            tilesLocation = tileSetsLocation;

            try
            {
                XMLDocument doc        = XMLParser.Parse(ins);
                XMLElement  docElement = doc.GetRoot();

                string orient = docElement.GetAttribute("orientation", "");
                if (!"orthogonal".Equals(orient))
                {
                    throw new Exception(
                              "Only orthogonal maps supported, found " + orient);
                }

                width      = docElement.GetIntAttribute("width", 0);
                height     = docElement.GetIntAttribute("height", 0);
                tileWidth  = docElement.GetIntAttribute("tilewidth", 0);
                tileHeight = docElement.GetIntAttribute("tileheight", 0);

                XMLElement propsElement = docElement
                                          .GetChildrenByName("properties");
                if (propsElement != null)
                {
                    props = new TMXProperty();
                    List <XMLElement> property = propsElement.List("property");
                    for (int i = 0; i < property.Count; i++)
                    {
                        XMLElement propElement = property[i];
                        string     name        = propElement.GetAttribute("name", null);
                        string     value_ren   = propElement.GetAttribute("value", null);
                        props.SetProperty(name, value_ren);
                    }
                }

                if (loadTileSets)
                {
                    TMXTileSet tileSet = null;
                    TMXTileSet lastSet = null;

                    List <XMLElement> setNodes = docElement.List("tileset");
                    for (int i_0 = 0; i_0 < setNodes.Count; i_0++)
                    {
                        XMLElement current = setNodes[i_0];

                        tileSet       = new TMXTileSet(this, current, true);
                        tileSet.index = i_0;

                        if (lastSet != null)
                        {
                            lastSet.SetLimit(tileSet.firstGID - 1);
                        }
                        lastSet = tileSet;

                        CollectionUtils.Add(tileSets, tileSet);
                    }
                }

                List <XMLElement> layerNodes = docElement.List("layer");
                for (int i_1 = 0; i_1 < layerNodes.Count; i_1++)
                {
                    XMLElement current_2 = layerNodes[i_1];
                    TMXLayer   layer     = new TMXLayer(this, current_2);
                    layer.index = i_1;

                    CollectionUtils.Add(layers, layer);
                }

                List <XMLElement> objectGroupNodes = docElement
                                                     .List("objectgroup");

                for (int i_3 = 0; i_3 < objectGroupNodes.Count; i_3++)
                {
                    XMLElement   current_4   = objectGroupNodes[i_3];
                    TMXTileGroup objectGroup = new TMXTileGroup(current_4);
                    objectGroup.index = i_3;

                    CollectionUtils.Add(objectGroups, objectGroup);
                }

                defWidth  = (int)(screenRect.GetWidth() / tileWidth);
                defHeight = (int)(screenRect.GetHeight() / tileHeight);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.StackTrace);
                throw new Exception("Failed to parse map", ex);
            }
        }