//##################################################################################### public void SaveAll() { m_tempBoard = null; m_currentSaveChunk = null; while (this.SaveNext()) { ; } }
/// <summary> /// 현재 선택된 청크를 저장하고 다음 청크를 선택한다. /// </summary> /// <returns>다음 청크의 유무</returns> public bool SaveNext() { // 저장할 청크가 없으면 바로 종료 if (m_board.ChunkCount <= 0) { return(false); } // 임시 보드에 실제 보드를 얕은 복사 if (m_tempBoard == null) { m_tempBoard = new ChunkBoard <Tile>(m_board.ChunkSize); foreach (var chunkInformation in m_board.GetEnumerable()) { m_tempBoard.SetChunkAt(chunkInformation.X, chunkInformation.Y, chunkInformation.Chunk); } } // 열거자 얻기 if (m_currentSaveChunk == null) { m_currentSaveChunk = m_tempBoard.GetEnumerable().GetEnumerator(); if (m_currentSaveChunk.MoveNext() == false) { m_tempBoard.Clear(); m_tempBoard = null; m_currentSaveChunk = null; return(false); } } // 열거자가 현재 가르키는 청크 저장 var chunkInfo = m_currentSaveChunk.Current; var chunk = chunkInfo.Chunk; string fileName = string.Format("{0}_{1}.dat", chunkInfo.X, chunkInfo.Y); using (BinaryWriter bw = new BinaryWriter(new FileStream(this.BoardPath + fileName, FileMode.Create))) { // 파일 버전 bw.Write(Application.ProductVersion.ToString()); // 청크 위치 bw.Write(chunkInfo.X); bw.Write(chunkInfo.Y); // 청크 크기 bw.Write(this.Board.ChunkSize); // 타일 정보 for (int x = 0; x < chunk.GetLength(0); ++x) { for (int y = 0; y < chunk.GetLength(1); ++y) { var tile = chunk[x, y]; tile.WriteToStream(bw); } } } // 다음 청크로 넘어가고 없으면 종료 if (m_currentSaveChunk.MoveNext()) { return(true); } else { m_tempBoard.Clear(); m_tempBoard = null; m_currentSaveChunk = null; return(false); } }