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:
parent
54f5d3bd3f
commit
a5adb30364
3 changed files with 19 additions and 11 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue