mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
[client] Port the server's DrawnLine class to the client
This commit is contained in:
parent
4350d53723
commit
7d4c521877
1 changed files with 60 additions and 0 deletions
60
Nibriboard/ClientFiles/RippleSpace/DrawnLine.js
Normal file
60
Nibriboard/ClientFiles/RippleSpace/DrawnLine.js
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue