Beispiel #1
0
        public void WriteChunk(SaveChunk chunk)
        {
            if (chunk == null)
            {
                throw new ArgumentException("Unable to save chunk from null.", nameof(chunk));
            }
            string dim      = ToValidFileName(chunk.Dimension);
            string fileName = $"{chunk.Coordinates.X};{chunk.Coordinates.Y}.json";
            string dimPath  = System.IO.Path.Combine(this.Path, "Dimensions", dim);

            Directory.CreateDirectory(dimPath);
            string filePath = System.IO.Path.Combine(this.Path, "Dimensions", dim, fileName);

            File.WriteAllText(filePath, JsonConvert.SerializeObject(chunk));
        }
Beispiel #2
0
        public static Chunk GetOrCreateChunk(SaveChunk saveChunk)
        {
            int dimIndex = Dimensions.IndexOf(GetOrCreateDimension(saveChunk.Dimension));

            Chunk[] dimChunks = null;
            lock (ChunksLocker)
            {
                dimChunks = Chunks[dimIndex].ToArray();
            }

            Chunk chunk = dimChunks.FirstOrDefault(c => c.Coordinates == saveChunk.Coordinates);

            if (!chunk)
            {
                return(CreateChunk(saveChunk.Coordinates, dimIndex, saveChunk.LoadBlocks()));
            }
            else
            {
                return(chunk);
            }
        }