1
0
Fork 0
mirror of https://github.com/sbrl/Nibriboard.git synced 2018-01-10 21:33:49 +00:00

Start creating logic for saving planes & chunks

This commit is contained in:
Starbeamrainbowlabs 2017-07-20 13:27:13 +01:00
parent d79a89423c
commit 3d013e208c
2 changed files with 35 additions and 0 deletions

View file

@ -227,6 +227,11 @@ namespace Nibriboard.RippleSpace
return loadedChunk; return loadedChunk;
} }
public async Task SaveTo(Stream destination)
{
throw new NotImplementedException("Error: Chunk saving hasn't been implemented yet!");
}
public void OnDeserialization(object sender) public void OnDeserialization(object sender)
{ {
UpdateAccessTime(); UpdateAccessTime();

View file

@ -164,6 +164,34 @@ namespace Nibriboard.RippleSpace
return loadedChunk; return loadedChunk;
} }
/// <summary>
/// Works out whether a chunk currently exists.
/// </summary>
/// <param name="chunkLocation">The chunk location to check.</param>
/// <returns>Whether the chunk at specified location exists or not.</returns>
public bool HasChunk(ChunkReference chunkLocation)
{
if(loadedChunkspace.ContainsKey(chunkLocation))
return true;
string chunkFilePath = Path.Combine(StorageDirectory, chunkLocation.AsFilename());
if(File.Exists(chunkFilePath))
return true;
return false;
}
public async Task SaveChunk(ChunkReference chunkLocation)
{
// It doesn't exist, so we can't save it :P
if(!loadedChunkspace.ContainsKey(chunkLocation))
return;
Chunk chunk = loadedChunkspace[chunkLocation];
string chunkFilePath = Path.Combine(StorageDirectory, chunkLocation.AsFilename());
await chunk.SaveTo(File.OpenWrite(chunkFilePath));
}
public async Task AddLine(DrawnLine newLine) public async Task AddLine(DrawnLine newLine)
{ {
List<DrawnLine> chunkedLineParts; List<DrawnLine> chunkedLineParts;
@ -216,6 +244,8 @@ namespace Nibriboard.RippleSpace
public void Save(Stream destination) public void Save(Stream destination)
{ {
WriterOptions packingOptions = new WriterOptions(CompressionType.GZip); WriterOptions packingOptions = new WriterOptions(CompressionType.GZip);
IEnumerable<string> chunkFiles = Directory.GetFiles(StorageDirectory); IEnumerable<string> chunkFiles = Directory.GetFiles(StorageDirectory);