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

[client] Add continues from/with id support & fix a few bugs, but it still doesn't work yet :-(

This commit is contained in:
Starbeamrainbowlabs 2017-09-29 15:42:42 +01:00
parent 54f5d3bd3f
commit a5adb30364
3 changed files with 19 additions and 11 deletions

View file

@ -274,6 +274,8 @@ class BoardWindow extends EventEmitter
{ {
context.save(); 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) 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)
{ {

View file

@ -20,14 +20,14 @@ class Chunk
} }
/** /**
* Fetches the first line in this chunk by it's id. * Fetches a line in this chunk by it's unique id.
* @param {string} lineId The target line id to search for. * @param {string} uniqueLineId The target unique id to search for.
* @return {object|null} The requested line, or null if it wasn't found. * @return {object|null} The requested line, or null if it wasn't found.
*/ */
getLineById(lineId) getLineByUniqueId(uniqueLineId)
{ {
for (let line of this.lines) { for (let line of this.lines) {
if(line.LineId == lineId) if(line.UniqueId == uniqueLineId)
return line; return line;
} }
return null; return null;
@ -92,7 +92,8 @@ class Chunk
// Fetch all the points on fragments of this line forwards from here // Fetch all the points on fragments of this line forwards from here
if(line.ContinuesIn != null) { 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) { for (let nextLine of nextLines) {
linePoints = linePoints.concat(nextLine.Points); linePoints = linePoints.concat(nextLine.Points);
} }

View file

@ -35,19 +35,18 @@ class ChunkCache
* Walk the currently cached chunks to find all the line fragments for the * Walk the currently cached chunks to find all the line fragments for the
* specified line id, starting at the specified chunk reference. * specified line id, starting at the specified chunk reference.
* @param {ChunkReference} startingChunkRef The reference of hte chunk we should start walking at. * @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. * @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 lineFragments = [];
let currentChunk = this.fetchChunk(startingChunkRef); let currentChunk = this.fetchChunk(startingChunkRef);
let nextUniqueId = lineUniqueId;
while(currentChunk instanceof Chunk) while(currentChunk instanceof Chunk)
{ {
let nextLineFragment = currentChunk.getLineById(lineId); let nextLineFragment = currentChunk.getLineByUniqueId(nextUniqueId);
if(nextLineFragment == null) if(nextLineFragment == null)
break; break;
@ -57,6 +56,7 @@ class ChunkCache
break; break;
currentChunk = this.fetchChunk(nextLineFragment.ContinuesIn); currentChunk = this.fetchChunk(nextLineFragment.ContinuesIn);
nextUniqueId = nextLineFragment.ContinuesWithId;
} }
return lineFragments; return lineFragments;
@ -181,6 +181,11 @@ class ChunkCache
line.ContinuesFrom.X, line.ContinuesFrom.Y line.ContinuesFrom.X, line.ContinuesFrom.Y
); );
} }
line.ContainingChunk = new ChunkReference(
this.boardWindow.currentPlaneName,
line.ContainingChunk.X,
line.ContainingChunk.Y
);
return line; return line;
}); });
newChunk.lines = newChunk.lines.concat(newLines); newChunk.lines = newChunk.lines.concat(newLines);