Exemple #1
0
        public void NewMap()
        {
            if (ConfirmClose())
            {
                TileSet tileSet = TileSet.Load(@"Data\Simple.mdts");

                if (tileSet == null)
                {
                    return;
                }

                NewMap(tileSet);
                form.SetStatusText("New map created.");
                form.UpdateInterface();
                UpdateTitlebar();
            }
        }
Exemple #2
0
        private void MapForm_Load(object sender, EventArgs e)
        {
            BorderKind.MakeCompatible(BorderKind.Wall, BorderKind.Wall2);
            BorderKind.MakeCompatible(BorderKind.Wall, BorderKind.Water);

            try
            {
                TileSet tileSet = TileSet.Load(@"Data\Simple.mdts");
                Debug.Assert(tileSet != null);

                document.NewMap(tileSet);

                document.FillTerrainList(tileSet);
            }
            catch (FileNotFoundException exception)
            {
                MessageBox.Show("There was an error loading the default tileset. Please ensure you have the .NET Framework version 3.5 installed.\n" + exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;
            }
        }
Exemple #3
0
        public static Map DeserializeFrom(StreamReader stream)
        {
            XmlReader xml = XmlReader.Create(stream);

            xml.ReadStartElement("Map");

            String tilesetName = xml.ReadElementString("Tileset");

            if (tilesetName != "Linedraw")
            {
                throw new NotImplementedException();
            }

            TileSet tileSet = TileSet.Load(@"Data\Simple.mdts");

            int width  = int.Parse(xml.ReadElementString("Width"));
            int height = int.Parse(xml.ReadElementString("Height"));

            Map      map   = new Map(tileSet, width, height);
            MapState state = map.state;

            xml.ReadStartElement("Terrain");
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int tileId = int.Parse(xml.ReadElementString("Square"));
                    state.SetSquareKind(x, y, tileSet.TerrainByIndex[tileId]);
                }
            }
            xml.ReadEndElement(); /* Terrain */

            xml.ReadStartElement("Tiles");
            while (xml.IsStartElement("Tile"))
            {
                xml.ReadStartElement("Tile");

                int layer = int.Parse(xml.ReadElementString("Layer"));
                int x     = int.Parse(xml.ReadElementString("X"));
                int y     = int.Parse(xml.ReadElementString("Y"));
                int value = int.Parse(xml.ReadElementString("Value"));

                Tile tile = tileSet.TileList[value];
                if (tile.IsLarge)
                {
                    for (int subX = 0; subX < tile.Width; subX++)
                    {
                        for (int subY = 0; subY < tile.Height; subY++)
                        {
                            state.SetTile(layer, x + subX, y + subY, tile.GetSubtile(subX, subY));
                        }
                    }
                }
                else
                {
                    state.SetTile(layer, x, y, tile);
                }

                xml.ReadEndElement(); /* Tile */
            }

            xml.ReadEndElement(); /* Tiles */

            xml.ReadEndElement(); /* Map */

            // TODO: Verify that map is correct
            map.ClearHoverTerrain();
            return(map);
        }