1
0
Fork 0

[client] Port the server's DrawnLine class to the client

This commit is contained in:
Starbeamrainbowlabs 2017-03-28 21:02:59 +01:00
parent 4350d53723
commit 7d4c521877
1 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,60 @@
"use strict";
import { ChunkReference } from '../References';
var cuid = require("cuid");
var Color = require("color");
/**
* Represents a line drawn on the screen.
*/
class DrawnLine
{
constructor(lineId = "")
{
/**
* The id of this line.
* @type {string}
*/
this.LineId = lineId.length == 0 ? lineId : cuid();
/**
* The width of this line.
* @type {Number}
*/
this.LineWidth = 3;
/**
* The colour of this line.
* @type {Color}
*/
this.Colour = new Color("#333333");
/**
* A list of points in this line.
* @type {Vector[]}
*/
this.Points = [];
}
SplitOnChunks(chunkSize)
{
var results = [];
var nextLine = new DrawnLine(),
currentChunk = null;
for(let point of this.points)
{
if(currentChunk != null &&
!point.ContainingChunk(chunkSize).is(currentChunk))
{
// We're heading into a new chunk! Split the line up here.
// TODO: Add connecting lines to each DrawnLine instance to prevent gaps
results.push(nextLine);
nextLine = new DrawnLine(this.LineId);
}
nextLine.Points.push(point);
}
return results;
}
}