2017-04-29 12:56:33 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a single chunk on a plane.
|
|
|
|
* Note that this is the client's representation of the chunk, so it's likely
|
|
|
|
* to be a little different to the server's representation.
|
|
|
|
*/
|
|
|
|
class Chunk
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Creates a new chunk.
|
2017-06-11 20:39:33 +00:00
|
|
|
* @param {ChunkReference} inChunkRef The location of the new chunk.
|
|
|
|
* @param {number} inSize The size of this chunk.
|
2017-04-29 12:56:33 +00:00
|
|
|
*/
|
2017-05-29 20:59:15 +00:00
|
|
|
constructor(inChunkRef, inSize)
|
2017-04-29 12:56:33 +00:00
|
|
|
{
|
|
|
|
this.chunkRef = inChunkRef;
|
2017-05-29 20:59:15 +00:00
|
|
|
this.size = inSize;
|
2017-04-29 12:56:33 +00:00
|
|
|
this.lines = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this chunk is located at the specified chunk reference.
|
|
|
|
* @param {ChunkReference} otherChunkRef The chunk reference to check
|
|
|
|
* ourselves against.
|
|
|
|
* @return {bool} Whether this chunk is located at the
|
|
|
|
* specified chunk reference.
|
|
|
|
*/
|
|
|
|
isAt(otherChunkRef)
|
|
|
|
{
|
|
|
|
if(this.chunkRef.toString() == otherChunkPos.toString())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-30 13:40:53 +00:00
|
|
|
|
|
|
|
update(dt)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
render(canvas, context)
|
|
|
|
{
|
2017-06-11 20:47:38 +00:00
|
|
|
var planeSpaceRef = this.chunkRef.inPlaneSpace(this.size);
|
|
|
|
|
2017-04-30 13:40:53 +00:00
|
|
|
context.save();
|
2017-06-11 20:47:38 +00:00
|
|
|
context.translate(planeSpaceRef.x, planeSpaceRef.y);
|
2017-04-30 13:40:53 +00:00
|
|
|
|
|
|
|
for(let line of this.lines)
|
|
|
|
{
|
|
|
|
context.beginPath();
|
|
|
|
context.moveTo(
|
2017-06-11 20:47:38 +00:00
|
|
|
line.Points[0].x - planeSpaceRef.x,
|
|
|
|
line.Points[0].y - planeSpaceRef.y
|
2017-04-30 13:40:53 +00:00
|
|
|
);
|
|
|
|
for(let i = 1; i < line.Points.length; i++)
|
|
|
|
{
|
|
|
|
context.lineTo(
|
2017-06-11 20:47:38 +00:00
|
|
|
line.Points[i].x - planeSpaceRef.x,
|
|
|
|
line.Points[i].y - planeSpaceRef.y
|
2017-04-30 13:40:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-06-12 17:15:49 +00:00
|
|
|
context.lineCap = "round";
|
2017-06-12 18:53:05 +00:00
|
|
|
context.lineJoin = "round";
|
2017-04-30 13:40:53 +00:00
|
|
|
context.lineWidth = line.Width;
|
|
|
|
context.strokeStyle = line.Colour;
|
|
|
|
context.stroke();
|
|
|
|
}
|
|
|
|
|
|
|
|
context.restore();
|
|
|
|
}
|
2017-04-29 12:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Chunk;
|