From a5adb30364106f481e2d32d6adc47d0e9d338dd2 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Fri, 29 Sep 2017 15:42:42 +0100 Subject: [PATCH] [client] Add continues from/with id support & fix a few bugs, but it still doesn't work yet :-( --- Nibriboard/ClientFiles/BoardWindow.js | 2 ++ Nibriboard/ClientFiles/Chunk.js | 13 +++++++------ Nibriboard/ClientFiles/ChunkCache.js | 15 ++++++++++----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Nibriboard/ClientFiles/BoardWindow.js b/Nibriboard/ClientFiles/BoardWindow.js index 2989272..bff5379 100644 --- a/Nibriboard/ClientFiles/BoardWindow.js +++ b/Nibriboard/ClientFiles/BoardWindow.js @@ -274,6 +274,8 @@ class BoardWindow extends EventEmitter { context.save(); + if(this.gridSize <= 0) + return false; for(let ax = (this.viewport.x + (this.gridSize - (this.viewport.x % this.gridSize))) - this.gridSize; ax < (this.viewport.x + this.viewport.width); ax += this.gridSize) { diff --git a/Nibriboard/ClientFiles/Chunk.js b/Nibriboard/ClientFiles/Chunk.js index 4beed85..13734fc 100644 --- a/Nibriboard/ClientFiles/Chunk.js +++ b/Nibriboard/ClientFiles/Chunk.js @@ -20,14 +20,14 @@ class Chunk } /** - * Fetches the first line in this chunk by it's id. - * @param {string} lineId The target line id to search for. - * @return {object|null} The requested line, or null if it wasn't found. + * Fetches a line in this chunk by it's unique id. + * @param {string} uniqueLineId The target unique id to search for. + * @return {object|null} The requested line, or null if it wasn't found. */ - getLineById(lineId) + getLineByUniqueId(uniqueLineId) { for (let line of this.lines) { - if(line.LineId == lineId) + if(line.UniqueId == uniqueLineId) return line; } return null; @@ -92,7 +92,8 @@ class Chunk // Fetch all the points on fragments of this line forwards from here if(line.ContinuesIn != null) { - let nextLines = chunkCache.fetchLineFragments(line.ContinuesIn, line.LineId); + let nextLines = chunkCache.fetchLineFragments(line.ContainingChunk, line.UniqueId).Points; + linePoints = []; for (let nextLine of nextLines) { linePoints = linePoints.concat(nextLine.Points); } diff --git a/Nibriboard/ClientFiles/ChunkCache.js b/Nibriboard/ClientFiles/ChunkCache.js index 5590f7a..d9ce5ed 100644 --- a/Nibriboard/ClientFiles/ChunkCache.js +++ b/Nibriboard/ClientFiles/ChunkCache.js @@ -35,19 +35,18 @@ class ChunkCache * Walk the currently cached chunks to find all the line fragments for the * specified line id, starting at the specified chunk reference. * @param {ChunkReference} startingChunkRef The reference of hte chunk we should start walking at. - * @param {string} lineId The id of the line we should fetch the fragments for. + * @param {string} lineId The unique id of the first line fragment we should include in the list. * @return {object[]} A list of line fragments found. */ - fetchLineFragments(startingChunkRef, lineId) + fetchLineFragments(startingChunkRef, lineUniqueId) { - throw new Error("Set up the ContinuesIn/From system to use a new UniqueLineId identifier"); - let lineFragments = []; let currentChunk = this.fetchChunk(startingChunkRef); + let nextUniqueId = lineUniqueId; while(currentChunk instanceof Chunk) { - let nextLineFragment = currentChunk.getLineById(lineId); + let nextLineFragment = currentChunk.getLineByUniqueId(nextUniqueId); if(nextLineFragment == null) break; @@ -57,6 +56,7 @@ class ChunkCache break; currentChunk = this.fetchChunk(nextLineFragment.ContinuesIn); + nextUniqueId = nextLineFragment.ContinuesWithId; } return lineFragments; @@ -181,6 +181,11 @@ class ChunkCache line.ContinuesFrom.X, line.ContinuesFrom.Y ); } + line.ContainingChunk = new ChunkReference( + this.boardWindow.currentPlaneName, + line.ContainingChunk.X, + line.ContainingChunk.Y + ); return line; }); newChunk.lines = newChunk.lines.concat(newLines);