示例#1
0
        public bool ReadFile(string filePath, bool isCompressed, bool isBinary)
        {
            if (!isBinary)
            {
                ChunkFile chunkFile = FileUtils.LoadJson <ChunkFile>(filePath, isCompressed);

                if (chunkFile == null)
                {
                    return(false);
                }
                CopyFrom(chunkFile);
                return(true);
            }
            else
            {
                ChunkFile chunkFile = FileUtils.LoadBinary <ChunkFile>(filePath);

                if (chunkFile == null)
                {
                    return(false);
                }
                CopyFrom(chunkFile);
                return(true);
            }
        }
示例#2
0
        public bool ReadFile(string filePath, bool isCompressed, bool isBinary)
        {
            if (!isBinary)
            {
                OverworldFile file = FileUtils.LoadJson <OverworldFile>(filePath, isCompressed);

                if (file == null)
                {
                    return(false);
                }
                else
                {
                    CopyFrom(file);
                    return(true);
                }
            }
            else
            {
                OverworldFile file = FileUtils.LoadBinary <OverworldFile>(filePath);

                if (file == null)
                {
                    return(false);
                }
                else
                {
                    CopyFrom(file);
                    return(true);
                }
            }
        }
示例#3
0
        public ChunkFile(string fileName, bool binary)
        {
            ChunkFile chunkFile = null;

            if (!binary)
            {
                chunkFile = FileUtils.LoadJsonFromAbsolutePath <ChunkFile>(fileName);
            }
            else
            {
                chunkFile = FileUtils.LoadBinary <ChunkFile>(fileName);
            }

            if (chunkFile != null)
            {
                CopyFrom(chunkFile);
            }
        }
示例#4
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);
        }