Example #1
0
        public static Room Load(string filename)
        {
            Room newRoom;
            if (!File.Exists(filename)) return null;
            using (var stream = File.Open(filename, FileMode.Open))
            using (var reader = new BinaryReader(stream, Encoding.UTF8))
            {

                var hd = Encoding.UTF8.GetBytes(Header);
                var buffer = new byte[hd.Length];
                reader.Read(buffer, 0, buffer.Length);
                var readHeader = Encoding.UTF8.GetString(buffer);
                if (readHeader != Header) return null;

                //writer.Write(hd, 0, hd.Length);
                var posX = reader.ReadDouble();
                //writer.Write(room.Position.X);
                var posY = reader.ReadDouble();
                // writer.Write(room.Position.Y);
                var tilesLength = reader.ReadInt32();
                //writer.Write(room.Tiles.Length);
                newRoom = new Room(new Point(posX, posY))
                {
                    Tiles = new Tile[tilesLength]
                };

                for (var i = 0; i < tilesLength; i++)
                {
                    var tt = (TileTypes)reader.ReadInt32();
                    newRoom.Tiles[i] = new Tile() { TileType = tt };
                }
            }
            return newRoom;

        }
Example #2
0
 public void SetCurrentRoom(Image image)
 {
     CurrentRoom.Selected = false;
     var room = _rooms.FirstOrDefault(a => a.Image == image);
     if (room != null) CurrentRoom = room;
     CurrentRoom.Selected = true;
 }
Example #3
0
 public void AddRoom(Room room)
 {
     if (CurrentRoom != null) CurrentRoom.Selected = false;
     if (room != null) _rooms.Add(room);
     _currentRoomIndex = _rooms.Count - 1;
     if (CurrentRoom != null) CurrentRoom.Selected = true;
 }
Example #4
0
        public static bool Save(Room room, string filename)
        {
            using (var stream = File.Open(filename, FileMode.Create))
            using (var writer = new BinaryWriter(stream, Encoding.UTF8))
            {
                var hd = Encoding.UTF8.GetBytes(Header);
                writer.Write(hd, 0, hd.Length);
                writer.Write(room.Position.X);
                writer.Write(room.Position.Y);
                writer.Write(room.Tiles.Length);
                foreach (var tile in room.Tiles)
                {
                    var tt = (int)tile.TileType;
                    writer.Write(tt);
                }

            }
            return true;

        }
        private void MenuOpenClick(object sender, RoutedEventArgs e)
        {
            var fdg = new OpenFileDialog {Title = "Select room data file", DefaultExt = "*.mkr"};
            fdg.ShowDialog();

            if (string.IsNullOrWhiteSpace(fdg.FileName)) return;
            _room = FileHandler.Load(fdg.FileName);
            if (_room == null) return;
            fdg = new OpenFileDialog {Title = "Select room image file", DefaultExt = "*.png"};
            fdg.ShowDialog();
            if (string.IsNullOrWhiteSpace(fdg.FileName)) return;
            _room.Image.Source = new BitmapImage(new Uri(fdg.FileName));
            UpdateRoomDrawing();
        }