Ejemplo n.º 1
0
 public static void SaveChunk(Chunk chunk)
 {
     using (var str = new FileStream(
                WorldRepository.GetChunkSavePath(chunk),
                FileMode.Create,
                FileAccess.Write,
                FileShare.None))
     {
         var formatter = new BinaryFormatter();
         formatter.Serialize(str, chunk.Blocks);
     }
 }
Ejemplo n.º 2
0
        public static bool LoadChunk(Chunk chunk)
        {
            var path = WorldRepository.GetChunkSavePath(chunk);

            if (!File.Exists(path))
            {
                return(false);
            }

            using (var str = new FileStream(path, FileMode.Open))
            {
                var formatter = new BinaryFormatter();
                var save      = (Block[, , ])formatter.Deserialize(str);
                chunk.Blocks = save;
            }

            return(true);
        }
Ejemplo n.º 3
0
        public static string GetChunkSavePath(Chunk chunk)
        {
            var saveFile = WorldRepository.GetSaveLocation(chunk.World.Title);

            return(Path.Combine(saveFile, WorldRepository.GetFileName(chunk.Position)));
        }