Ejemplo n.º 1
0
        public static byte[] Convert(string json)
        {
            var obj = JsonConvert.DeserializeObject <json_dat>(json);
            var dat = ZlibStream.UncompressBuffer(obj.data);

            Dictionary <short, TerrainTile> tileDict = new Dictionary <short, TerrainTile>();

            for (int i = 0; i < obj.dict.Length; i++)
            {
                var o = obj.dict[i];
                tileDict[(short)i] = new TerrainTile()
                {
                    TileId  = o.ground == null ? (short)0xff : XmlDatas.IdToType[o.ground],
                    TileObj = o.objs == null ? null : o.objs[0].id,
                    Name    = o.objs == null ? "" : o.objs[0].name ?? "",
                    Terrain = TerrainType.None,
                    Region  = o.regions == null ? TileRegion.None : (TileRegion)Enum.Parse(typeof(TileRegion), o.regions[0].id.Replace(' ', '_'))
                };
            }

            var tiles = new TerrainTile[obj.width, obj.height];

            using (NReader rdr = new NReader(new MemoryStream(dat)))
                for (int y = 0; y < obj.height; y++)
                {
                    for (int x = 0; x < obj.width; x++)
                    {
                        tiles[x, y] = tileDict[rdr.ReadInt16()];
                    }
                }
            return(WorldMapExporter.Export(tiles));
        }
Ejemplo n.º 2
0
        protected override void OnKeyUp(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                mode = mode + 1;
            }
            if (mode == Mode.MAX)
            {
                mode = 0;
            }
            Text = mode.ToString();

            if (e.KeyCode == Keys.S)
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "WMap files (*.wmap)|*.wmap|All Files (*.*)|*.*";
                if (sfd.ShowDialog() != DialogResult.Cancel)
                {
                    WorldMapExporter.Export(tiles, sfd.FileName);
                }
            }
            else if (e.KeyCode == Keys.R)
            {
                tiles     = (TerrainTile[, ])tilesBak.Clone();
                bmp       = RenderColorBmp(tiles);
                pic.Image = pic2.Image = bmp;
            }
            base.OnKeyUp(e);
        }
Ejemplo n.º 3
0
        public static byte[] ConvertMakeWalls(string json)
        {
            var obj = JsonConvert.DeserializeObject <json_dat>(json);
            var dat = ZlibStream.UncompressBuffer(obj.data);

            Dictionary <short, TerrainTile> tileDict = new Dictionary <short, TerrainTile>();

            for (int i = 0; i < obj.dict.Length; i++)
            {
                var o = obj.dict[i];
                tileDict[(short)i] = new TerrainTile()
                {
                    TileId  = o.ground == null ? (short)0xff : XmlDatas.IdToType[o.ground],
                    TileObj = o.objs == null ? null : o.objs[0].id,
                    Name    = o.objs == null ? "" : o.objs[0].name ?? "",
                    Terrain = TerrainType.None,
                    Region  = o.regions == null ? TileRegion.None : (TileRegion)Enum.Parse(typeof(TileRegion), o.regions[0].id.Replace(' ', '_'))
                };
            }

            var tiles = new TerrainTile[obj.width, obj.height];

            using (NReader rdr = new NReader(new MemoryStream(dat)))
                for (int y = 0; y < obj.height; y++)
                {
                    for (int x = 0; x < obj.width; x++)
                    {
                        tiles[x, y]   = tileDict[rdr.ReadInt16()];
                        tiles[x, y].X = x;
                        tiles[x, y].Y = y;
                    }
                }

            foreach (var i in tiles)
            {
                if (i.TileId == 0xff && i.TileObj == null)
                {
                    bool createWall = false;
                    for (int ty = -1; ty <= 1; ty++)
                    {
                        for (int tx = -1; tx <= 1; tx++)
                        {
                            try
                            {
                                if (tiles[i.X + tx, i.Y + ty].TileId != 0xff)
                                {
                                    createWall = true;
                                }
                            }
                            catch { }
                        }
                    }
                    if (createWall)
                    {
                        tiles[i.X, i.Y].TileObj = "Grey Wall";
                    }
                }
            }

            return(WorldMapExporter.Export(tiles));
        }