Beispiel #1
0
 public static MetaData CreateFromWorld(WorldManager World)
 {
     return(new MetaData
     {
         OverworldFile = Overworld.Name,
         WorldOrigin = World.WorldOrigin,
         WorldScale = World.WorldScale,
         TimeOfDay = World.Sky.TimeOfDay,
         GameID = World.GameID,
         Time = World.Time,
         Slice = (int)World.Master.MaxViewingLevel,
         NumChunks = World.ChunkManager.WorldSize,
         Version = Program.Version,
         Commit = Program.Commit,
         VoxelTypeMap = VoxelLibrary.GetVoxelTypeMap()
     });
 }
Beispiel #2
0
        public bool ReadChunks(string filePath)
        {
            if (Metadata == null)
            {
                throw new InvalidProgramException("MetaData must be loaded before chunk data.");
            }

            ChunkData = new List <ChunkFile>();

            var chunkDirs = System.IO.Directory.GetDirectories(filePath, "Chunks");

            if (chunkDirs.Length > 0)
            {
                foreach (string chunk in Directory.GetFiles(chunkDirs[0], "*." + (DwarfGame.COMPRESSED_BINARY_SAVES ? ChunkFile.CompressedExtension : ChunkFile.Extension)))
                {
                    if (DwarfGame.COMPRESSED_BINARY_SAVES)
                    {
                        ChunkData.Add(FileUtils.LoadBinary <ChunkFile>(chunk));
                    }
                    else
                    {
                        ChunkData.Add(FileUtils.LoadJsonFromAbsolutePath <ChunkFile>(chunk));
                    }
                }
            }
            else
            {
                Console.Error.WriteLine("Can't load chunks {0}, no chunks found", filePath);
                return(false);
            }

            // Remap the saved voxel ids to the ids of the currently loaded voxels.
            if (Metadata.VoxelTypeMap != null)
            {
                // First build a replacement mapping.

                var newVoxelMap   = VoxelLibrary.GetVoxelTypeMap();
                var newReverseMap = new Dictionary <String, int>();
                foreach (var mapping in newVoxelMap)
                {
                    newReverseMap.Add(mapping.Value, mapping.Key);
                }

                var replacementMap = new Dictionary <int, int>();
                foreach (var mapping in Metadata.VoxelTypeMap)
                {
                    if (newReverseMap.ContainsKey(mapping.Value))
                    {
                        var newId = newReverseMap[mapping.Value];
                        if (mapping.Key != newId)
                        {
                            replacementMap.Add(mapping.Key, newId);
                        }
                    }
                }

                // If there are no changes, skip the expensive iteration.
                if (replacementMap.Count != 0)
                {
                    foreach (var chunk in ChunkData)
                    {
                        for (var i = 0; i < chunk.Types.Length; ++i)
                        {
                            if (replacementMap.ContainsKey(chunk.Types[i]))
                            {
                                chunk.Types[i] = (byte)replacementMap[chunk.Types[i]];
                            }
                        }
                    }
                }
            }

            return(true);
        }