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

[client] Update chunk cache

This commit is contained in:
Starbeamrainbowlabs 2017-05-29 21:59:15 +01:00
parent a7132d344d
commit 6ca05e8d44
2 changed files with 14 additions and 6 deletions

View file

@ -11,9 +11,10 @@ class Chunk
* Creates a new chunk. * Creates a new chunk.
* @param {ChunkReference} inChunkRef The location of the new chunk. * @param {ChunkReference} inChunkRef The location of the new chunk.
*/ */
constructor(inChunkRef) constructor(inChunkRef, inSize)
{ {
this.chunkRef = inChunkRef; this.chunkRef = inChunkRef;
this.size = inSize;
this.lines = []; this.lines = [];
} }

View file

@ -18,9 +18,9 @@ class ChunkCache
* Adds the given chunk to the chunk cache. * Adds the given chunk to the chunk cache.
* @param {Chunk} chunkData The chunk to add to the cache. * @param {Chunk} chunkData The chunk to add to the cache.
*/ */
add(chunkData) add(chunkData, override = false)
{ {
if(this.cache.contains(chunkData.chunkRef.toString())) if(!override && this.cache.contains(chunkData.chunkRef.toString()))
throw new Error("Error: We already have a chunk at that location stored."); throw new Error("Error: We already have a chunk at that location stored.");
this.cache.set(chunkData.chunkRef.toString(), chunkData); this.cache.set(chunkData.chunkRef.toString(), chunkData);
@ -69,10 +69,17 @@ class ChunkCache
handleChunkUpdate(message) handleChunkUpdate(message)
{ {
for (let chunk of message.Chunks) { for (let chunkData of message.Chunks) {
//let newChunkRef = new ChunkReference(); let newChunkRef = new ChunkReference(
let newChunk = new Chunk(chunk.Location); chunkData.Location.PlaneName,
chunkData.Location.X,
chunkData.Location.Y
);
let newChunk = new Chunk(newChunkRef, chunkData.Size);
newChunk.lines = newChunk.lines.concat(chunkData.lines);
this.add(newChunk);
} }
} }
} }