Пример #1
0
        public static void Save(TilesMap tilesmap, string path)
        {
            if (tilesmap == null)
            {
                throw new ArgumentException("Argument does not accept null", "tilesmap");
            }
            if (path == null)
            {
                throw new ArgumentException("Argument does not accept null", "path");
            }
            using (XmlTextWriter wr = new XmlTextWriter(path, Encoding.UTF8))
            {
                wr.Formatting = Formatting.Indented;
                wr.WriteStartDocument();
                wr.WriteStartElement("Tilesmap");
                {
                    wr.WriteAttributeString("columns", tilesmap.Columns.ToString());
                    wr.WriteAttributeString("rows", tilesmap.Rows.ToString());

                    wr.WriteStartElement("MatrixIndex");
                    {
                        for (int i = 0; i < tilesmap.Rows; i++)
                        {
                            wr.WriteStartElement("Row");
                            {
                                wr.WriteAttributeString("id", i.ToString());
                                for (int j = 0; j < tilesmap.Columns; j++)
                                {
                                    wr.WriteString(tilesmap[j, i].ToString());
                                    if (j != tilesmap.Columns - 1)
                                    {
                                        wr.WriteString("\t");
                                    }
                                }
                            }
                            wr.WriteEndElement(); // rows
                        }
                    }
                    wr.WriteEndElement();   // Matrixindex
                    if (tilesmap.TileSet != null)
                    {
                        TileSet.Save(wr, tilesmap.TileSet, path);
                    }
                    if (tilesmap.ListObject.Any())
                    {
                        ObjectEditor.Save(wr, tilesmap.ListObject, path);
                    }
                }

                wr.WriteEndElement();       // Tiles map
                wr.WriteEndDocument();
                wr.Close();
                wr.Dispose();
            }
        }
Пример #2
0
        public static TilesMap Load(string path)
        {
            TilesMap tilesmap = null;
            int      columns  = 0;
            int      rows     = 0;

            using (XmlTextReader reader = new XmlTextReader(path))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        if (reader.Name == "Tilesmap")
                        {
                            columns  = Int32.Parse(reader.GetAttribute("columns"));
                            rows     = Int32.Parse(reader.GetAttribute("rows"));
                            tilesmap = new TilesMap(columns, rows);
                        }
                        if (reader.Name == "Row")
                        {
                            int    rownumber = Int32.Parse(reader.GetAttribute("id"));
                            string indexs    = reader.ReadString();
                            var    row       = indexs.Split('\t');
                            for (int i = 0; i < columns; i++)
                            {
                                tilesmap[i, rownumber] = Int32.Parse(row[i]);
                            }
                        }
                        if (reader.Name == "TileSet")
                        {
                            tilesmap.TileSet = TileSet.Load(reader, path);
                        }
                        if (reader.Name == "Objects")
                        {
                            var listobject = ObjectEditor.Load(reader, path);
                            tilesmap.ListObject = new BindingList <GameObject>(listobject);
                        }
                    }
                    if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "Tilesmap")
                    {
                        break;
                    }
                }
            }
            return(tilesmap);
        }
Пример #3
0
 public void InitObjectEditor()
 {
     ObjectEditor = new ObjectEditor(TilesMap.ListObject);
     ObjectEditor.ListItem.ListChanged += ListItem_ListChanged;
     //done
 }