public void Import(Stream MatFile, int TileSize, TileSet TileSet) { Burntime.Platform.IO.File file = new Burntime.Platform.IO.File(MatFile); Burntime.Data.BurnGfx.Map map = new Burntime.Data.BurnGfx.Map(file); Size = new Size(map.width, map.height); this.TileSize = TileSize; Title = "unnamed"; Saved = false; tiles = new Tile[Size.Width, Size.Height]; for (int y = 0; y < Size.Height; y++) { for (int x = 0; x < Size.Width; x++) { Tile tile = TileSet.Find((byte)(map.data[x + y * Size.Width] & 0xff), (byte)(map.data[x + y * Size.Width] >> 8)); tiles[x, y] = tile; } } foreach (Burntime.Data.BurnGfx.Door d in map.Doors) { Entrance e = new Entrance(); e.Rect = new Rectangle(d.Area.Left, d.Area.Top, d.Area.Width, d.Area.Height); entrances.Add(e); } file.Close(); AttachedView.UpdateMap(); AttachedView.UpdateTitle(); }
public bool Export(String File) { Burntime.Platform.IO.File file = new Burntime.Platform.IO.File(new FileStream(File, FileMode.Open, FileAccess.ReadWrite)); Burntime.Data.BurnGfx.Map map = new Burntime.Data.BurnGfx.Map(file); map.width = Size.Width; map.height = Size.Height; // check size map.data = new ushort[Size.Width * Size.Height]; for (int y = 0; y < Size.Height; y++) { for (int x = 0; x < Size.Width; x++) { map.data[x + y * Size.Width] = (ushort)(tiles[x, y].SubSet + (((ushort)tiles[x, y].ID) << 8)); } } // check door count if (map.Doors.Count != entrances.Count) { MessageBox.Show("Entrance count must be the same as the original.", "Export", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } for (int i = 0; i < map.Doors.Count; i++) { map.Doors[i].Area = new Burntime.Platform.Rect(entrances[i].Rect.Left, entrances[i].Rect.Top, entrances[i].Rect.Width, entrances[i].Rect.Height); } file.Seek(0, Burntime.Platform.IO.SeekPosition.Begin); map.SaveToRaw(file); file.Flush(); file.Close(); return(true); }