2017-01-21 17:06:19 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// npm modules
|
2017-11-09 21:35:56 +00:00
|
|
|
import EventEmitter from "event-emitter-es6";
|
|
|
|
import FaviconNotification from "favicon-notification";
|
|
|
|
import panzoom from "pan-zoom";
|
2017-01-21 17:06:19 +00:00
|
|
|
|
|
|
|
// Our files
|
|
|
|
import RippleLink from './RippleLink';
|
2017-04-29 12:43:19 +00:00
|
|
|
import CursorSyncer from './CursorSyncer';
|
2017-07-01 12:29:45 +00:00
|
|
|
import ClientManager from './ClientManager';
|
2017-04-15 15:20:30 +00:00
|
|
|
import Pencil from './Pencil';
|
2017-06-26 16:53:18 +00:00
|
|
|
import { get, clamp } from './Utilities';
|
2017-04-15 12:13:07 +00:00
|
|
|
import Keyboard from './Utilities/Keyboard';
|
2017-04-27 17:36:45 +00:00
|
|
|
import Interface from './Interface';
|
2017-05-01 13:40:05 +00:00
|
|
|
import ChunkCache from './ChunkCache';
|
2017-01-21 17:06:19 +00:00
|
|
|
|
|
|
|
class BoardWindow extends EventEmitter
|
|
|
|
{
|
|
|
|
constructor(canvas)
|
|
|
|
{
|
|
|
|
super(); // Run the parent constructor
|
|
|
|
|
2017-02-04 21:26:48 +00:00
|
|
|
// The maximum target fps.
|
2017-01-22 13:05:59 +00:00
|
|
|
this.maxFps = 60;
|
2017-03-02 20:36:27 +00:00
|
|
|
// The target fps at which we should send cursor updates.
|
2017-02-07 21:29:17 +00:00
|
|
|
this.cursorUpdateFrequency = 5;
|
2017-02-19 15:55:22 +00:00
|
|
|
|
|
|
|
// The radius of other clients' cursors.
|
|
|
|
this.otherCursorRadius = 10;
|
|
|
|
// The width of the lines in other clients' cursors.
|
|
|
|
this.otherCursorWidth = 2;
|
|
|
|
|
2017-04-24 19:12:14 +00:00
|
|
|
this.currentPlaneName = "(You haven't landed yet!)";
|
|
|
|
// Whether to display the chunk grid or not
|
|
|
|
this.displayGrid = false;
|
|
|
|
|
|
|
|
this.gridLineWidth = 2;
|
|
|
|
this.gridLineColour = "rgba(22, 123, 228, 0.53)";
|
2017-04-24 20:42:31 +00:00
|
|
|
this.primaryGridLineWidth = 4;
|
|
|
|
this.primaryGridLineColour = "rgba(31, 223, 4, 0.68)";
|
2017-04-24 19:12:14 +00:00
|
|
|
|
2017-02-19 15:55:22 +00:00
|
|
|
// --~~~--
|
|
|
|
|
2017-02-07 21:29:17 +00:00
|
|
|
// Setup the fps indicator in the top right corner
|
2017-01-22 13:05:59 +00:00
|
|
|
this.renderTimeIndicator = document.createElement("span");
|
|
|
|
this.renderTimeIndicator.innerHTML = "0ms";
|
|
|
|
document.querySelector(".fps").appendChild(this.renderTimeIndicator);
|
|
|
|
|
2017-02-19 13:22:35 +00:00
|
|
|
// --~~~--
|
|
|
|
|
|
|
|
// Our unique id
|
|
|
|
this.Id = -1;
|
|
|
|
// Our colour
|
|
|
|
this.Colour = "rgba(255, 255, 255, 0.3)";
|
|
|
|
|
2017-04-14 20:08:36 +00:00
|
|
|
// The current state of the viewport.
|
2017-07-29 19:42:07 +00:00
|
|
|
this.lastViewportUpdate = +new Date();
|
2017-04-14 20:08:36 +00:00
|
|
|
this.viewport = {
|
|
|
|
// The x coordinate of the viewport.
|
|
|
|
x: 0,
|
|
|
|
// The y coordinate of the viewport.
|
|
|
|
y: 0,
|
2017-04-24 20:42:31 +00:00
|
|
|
// The width of the viewport
|
|
|
|
get width() {
|
2017-06-15 16:20:22 +00:00
|
|
|
return canvas.width * (1/this.zoomLevel)
|
2017-04-24 20:42:31 +00:00
|
|
|
},
|
|
|
|
// The height of the viewport
|
|
|
|
get height() {
|
2017-06-15 16:20:22 +00:00
|
|
|
return canvas.height * (1/this.zoomLevel)
|
2017-04-24 20:42:31 +00:00
|
|
|
},
|
2017-04-14 20:08:36 +00:00
|
|
|
// The zoom level of the viewport. 1 = normal.
|
2017-06-15 12:12:30 +00:00
|
|
|
zoomLevel: 1,
|
|
|
|
|
|
|
|
toString() {
|
2017-06-26 16:53:18 +00:00
|
|
|
return `${+this.width.toFixed(2)}x${+this.height.toFixed(2)} @ (${+this.x.toFixed(2)}, ${+this.y.toFixed(2)}) @ ${+this.zoomLevel.toFixed(2)}x`
|
2017-06-15 12:12:30 +00:00
|
|
|
}
|
2017-04-14 20:08:36 +00:00
|
|
|
};
|
2017-04-24 19:12:14 +00:00
|
|
|
|
|
|
|
// The current grid size
|
|
|
|
this.gridSize = -1;
|
2017-04-14 20:08:36 +00:00
|
|
|
|
2017-02-19 13:22:35 +00:00
|
|
|
// --~~~--
|
|
|
|
|
2017-02-04 21:26:48 +00:00
|
|
|
// Setup the canvas
|
2017-01-21 17:06:19 +00:00
|
|
|
this.canvas = canvas;
|
|
|
|
this.context = canvas.getContext("2d");
|
2017-02-04 21:26:48 +00:00
|
|
|
|
2017-04-24 19:12:14 +00:00
|
|
|
/**
|
2017-06-22 20:00:59 +00:00
|
|
|
* The current state of the keyboard.
|
2017-04-24 19:12:14 +00:00
|
|
|
* @type {Keyboard}
|
|
|
|
*/
|
|
|
|
this.keyboard = new Keyboard();
|
|
|
|
// Toggle the grid display when the g key is released
|
|
|
|
this.keyboard.on("keyup-g", (function(event) {
|
|
|
|
this.displayGrid = this.displayGrid ? false : true;
|
|
|
|
console.info(`[BoardWindow/KeyboardHandler] Grid display set to ${this.displayGrid ? "on" : "off"}`);
|
2017-04-28 17:13:41 +00:00
|
|
|
}).bind(this));
|
|
|
|
this.keyboard.on("keyup-left", (function(event) {
|
|
|
|
this.interface.seekColour("backwards");
|
|
|
|
}).bind(this));
|
|
|
|
this.keyboard.on("keyup-right", (function(event) {
|
|
|
|
this.interface.seekColour("forwards");
|
|
|
|
}).bind(this));
|
|
|
|
this.keyboard.on("keyup-up", (function(event) {
|
2017-10-29 11:29:40 +00:00
|
|
|
this.interface.updateBrushWidth(this.interface.brushIndicator.width + 2, true);
|
2017-04-28 17:13:41 +00:00
|
|
|
}).bind(this));
|
|
|
|
this.keyboard.on("keyup-down", (function(event) {
|
2017-10-29 11:29:40 +00:00
|
|
|
this.interface.updateBrushWidth(this.interface.brushIndicator.width - 2, true);
|
2017-04-28 17:13:41 +00:00
|
|
|
}).bind(this));
|
2017-06-22 20:00:59 +00:00
|
|
|
this.keyboard.on("keyup-c", (function(event) {
|
|
|
|
this.chunkCache.showRenderedChunks = !this.chunkCache.showRenderedChunks;
|
|
|
|
}).bind(this));
|
2017-07-30 21:23:19 +00:00
|
|
|
// Stop the document from scrolling around on some devices
|
|
|
|
document.addEventListener("keyup", function(event) {
|
|
|
|
if(event.keyCode >= 37 && event.keyCode <= 40) {
|
|
|
|
event.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
})
|
2017-04-15 12:13:07 +00:00
|
|
|
|
2017-06-26 17:04:42 +00:00
|
|
|
// Grab a reference to the sidebar and wrap it in an Interface class instance
|
|
|
|
this.interface = new Interface(
|
|
|
|
this,
|
|
|
|
document.getElementById("sidebar"),
|
|
|
|
document.getElementById("debuginfo")
|
|
|
|
);
|
|
|
|
this.interface.on("toolchange", (function({oldTool, newTool}) {
|
|
|
|
this.canvas.classList.remove(oldTool);
|
|
|
|
this.canvas.classList.add(newTool);
|
|
|
|
}).bind(this));
|
|
|
|
|
2017-02-04 21:26:48 +00:00
|
|
|
// --~~~--
|
|
|
|
|
|
|
|
// Setup the favicon thingy
|
|
|
|
|
2017-01-21 17:06:19 +00:00
|
|
|
FaviconNotification.init({
|
|
|
|
color: '#ff6333'
|
|
|
|
});
|
|
|
|
FaviconNotification.add();
|
|
|
|
|
2017-02-04 21:26:48 +00:00
|
|
|
// Setup the input controls
|
2017-11-09 21:35:56 +00:00
|
|
|
panzoom(canvas, this.handleCanvasMovement.bind(this));
|
2017-02-04 21:26:48 +00:00
|
|
|
|
2017-02-19 11:57:42 +00:00
|
|
|
// --~~~--
|
|
|
|
|
2017-02-04 21:26:48 +00:00
|
|
|
// Fetch the RippleLink connection information and other settings from
|
|
|
|
// the server
|
2017-01-21 17:06:19 +00:00
|
|
|
get("/Settings.json").then(JSON.parse).then((function(settings) {
|
2017-01-21 18:38:52 +00:00
|
|
|
console.info("[setup]", "Obtained settings from server:", settings);
|
2017-01-21 17:06:19 +00:00
|
|
|
this.settings = settings;
|
|
|
|
this.setup();
|
|
|
|
}).bind(this), function(errorMessage) {
|
|
|
|
console.error(`Error: Failed to fetch settings from server! Response: ${errorMessage}`);
|
|
|
|
});
|
|
|
|
|
2017-02-19 11:57:42 +00:00
|
|
|
// --~~~--
|
|
|
|
|
2017-02-04 21:26:48 +00:00
|
|
|
// Make the canvas track the window size
|
2017-01-21 17:06:19 +00:00
|
|
|
this.trackWindowSize();
|
|
|
|
}
|
|
|
|
|
2017-02-04 21:26:48 +00:00
|
|
|
/**
|
|
|
|
* Setup ready for user input.
|
|
|
|
* This mainly consists of establishing the RippleLink connection to the server.
|
|
|
|
*/
|
2017-01-21 18:38:52 +00:00
|
|
|
setup() {
|
2017-05-04 20:38:03 +00:00
|
|
|
this.rippleLink = new RippleLink(`ws${this.settings.SecureWebSocket ? "s" : ""}://${location.host}${this.settings.WebSocketPath}`, this);
|
2017-02-04 21:26:48 +00:00
|
|
|
this.rippleLink.on("connect", (function(event) {
|
2017-05-01 13:40:05 +00:00
|
|
|
|
2017-02-04 21:26:48 +00:00
|
|
|
// Send the handshake request
|
|
|
|
this.rippleLink.send({
|
2017-02-19 13:22:35 +00:00
|
|
|
Event: "HandshakeRequest",
|
2017-02-04 21:26:48 +00:00
|
|
|
InitialViewport: { // TODO: Add support for persisting this between sessions
|
|
|
|
X: 0,
|
|
|
|
Y: 0,
|
|
|
|
Width: window.innerWidth,
|
|
|
|
Height: window.innerHeight
|
|
|
|
},
|
2017-07-29 17:49:56 +00:00
|
|
|
InitialAbsCursorPosition: this.cursorSyncer.cursorPosition
|
2017-02-04 21:26:48 +00:00
|
|
|
});
|
|
|
|
}).bind(this));
|
2017-04-28 17:13:41 +00:00
|
|
|
this.rippleLink.on("disconnect", (function(event) {
|
|
|
|
this.interface.setConnectedStatus(false);
|
|
|
|
}).bind(this))
|
2017-02-04 21:26:48 +00:00
|
|
|
|
2017-02-19 11:57:42 +00:00
|
|
|
// Keep the server up to date on our viewport and cursor position
|
2017-04-29 12:43:19 +00:00
|
|
|
this.cursorSyncer = new CursorSyncer(this.rippleLink, this.cursorUpdateFrequency)
|
2017-02-07 21:29:17 +00:00
|
|
|
|
2017-02-04 21:26:48 +00:00
|
|
|
// RippleLink message bindings
|
|
|
|
|
2017-02-19 13:22:35 +00:00
|
|
|
// Handle the HandshakeResponse when it comes in
|
|
|
|
this.rippleLink.on("HandshakeResponse", this.handleHandshakeResponse.bind(this));
|
2017-04-24 19:12:14 +00:00
|
|
|
// Handle the plane change confirmations
|
|
|
|
this.rippleLink.on("PlaneChangeOk", this.handlePlaneChangeOk.bind(this));
|
2017-01-21 18:38:52 +00:00
|
|
|
}
|
|
|
|
|
2017-02-04 21:26:48 +00:00
|
|
|
/**
|
|
|
|
* Renders the next frame.
|
|
|
|
*/
|
2017-01-21 17:06:19 +00:00
|
|
|
nextFrame()
|
|
|
|
{
|
2017-01-22 13:05:59 +00:00
|
|
|
// The time at which the current frame started rendering.
|
|
|
|
let frameStart = +new Date();
|
|
|
|
|
|
|
|
if(frameStart - this.lastFrameStart >= (1 / this.maxFps) * 1000)
|
|
|
|
{
|
2017-06-24 19:24:56 +00:00
|
|
|
this.update(frameStart - this.lastFrameStart);
|
2017-01-22 13:05:59 +00:00
|
|
|
this.render(this.canvas, this.context);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the time the last frame started rendering
|
|
|
|
this.lastFrameStart = frameStart;
|
|
|
|
// Update the time we took rendering the last frame
|
|
|
|
this.lastFrameTime = +new Date() - frameStart;
|
|
|
|
|
|
|
|
this.renderTimeIndicator.innerHTML = `${this.lastFrameTime}ms`;
|
|
|
|
|
|
|
|
// Limit the maximum fps
|
2017-01-21 17:06:19 +00:00
|
|
|
requestAnimationFrame(this.nextFrame.bind(this));
|
|
|
|
}
|
|
|
|
|
2017-02-04 21:26:48 +00:00
|
|
|
/**
|
|
|
|
* Updates everything ready for the next frame to be rendered.
|
|
|
|
*/
|
2017-06-24 19:24:56 +00:00
|
|
|
update(dt)
|
2017-01-21 17:06:19 +00:00
|
|
|
{
|
2017-06-24 19:24:56 +00:00
|
|
|
if(typeof this.chunkCache != "undefined" && this.gridSize != -1)
|
|
|
|
this.chunkCache.update(dt, this.viewport);
|
|
|
|
|
2017-06-26 17:04:42 +00:00
|
|
|
this.interface.updateDebugInfo(dt);
|
2017-01-21 17:06:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-04 21:26:48 +00:00
|
|
|
/**
|
|
|
|
* Renders the next frame.
|
|
|
|
*/
|
2017-01-21 17:06:19 +00:00
|
|
|
render(canvas, context)
|
|
|
|
{
|
|
|
|
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
|
2017-04-24 19:12:14 +00:00
|
|
|
context.save();
|
2017-06-11 21:01:12 +00:00
|
|
|
context.scale(this.viewport.zoomLevel, this.viewport.zoomLevel);
|
2017-04-24 19:12:14 +00:00
|
|
|
|
|
|
|
// Draw the grid if it's enabled
|
|
|
|
if(this.displayGrid)
|
|
|
|
this.renderGrid(canvas, context);
|
|
|
|
|
2017-06-12 19:46:50 +00:00
|
|
|
|
|
|
|
context.save();
|
|
|
|
context.translate(
|
|
|
|
-this.viewport.x,
|
|
|
|
-this.viewport.y
|
|
|
|
);
|
|
|
|
|
2017-05-01 13:40:05 +00:00
|
|
|
// Only render the visible chunks if the chunk cache has been created
|
|
|
|
// The chunk cache is only created once the ripple link connects successfully
|
|
|
|
// to the nibriboard server.
|
|
|
|
if(typeof this.chunkCache != "undefined" && this.gridSize != -1)
|
|
|
|
this.chunkCache.renderVisible(this.viewport, canvas, context);
|
|
|
|
|
2017-07-01 12:29:45 +00:00
|
|
|
if(typeof this.otherClients != "undefined")
|
|
|
|
this.otherClients.render(canvas, context);
|
|
|
|
|
2017-04-16 15:18:45 +00:00
|
|
|
// Render the currently active line
|
|
|
|
if(typeof this.pencil !== "undefined")
|
2017-06-12 19:46:50 +00:00
|
|
|
this.pencil.render(canvas, context);
|
|
|
|
|
|
|
|
context.restore();
|
2017-04-24 19:12:14 +00:00
|
|
|
|
|
|
|
context.restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
renderGrid(canvas, context)
|
|
|
|
{
|
|
|
|
context.save();
|
|
|
|
|
2017-09-29 14:42:42 +00:00
|
|
|
if(this.gridSize <= 0)
|
|
|
|
return false;
|
2017-04-24 20:42:31 +00:00
|
|
|
|
|
|
|
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)
|
2017-04-24 19:12:14 +00:00
|
|
|
{
|
2017-04-24 20:42:31 +00:00
|
|
|
context.beginPath();
|
2017-04-24 19:12:14 +00:00
|
|
|
context.moveTo(ax - this.viewport.x, 0);
|
2017-04-24 20:42:31 +00:00
|
|
|
context.lineTo(ax - this.viewport.x, this.viewport.height);
|
|
|
|
|
|
|
|
if(Math.round(ax) == 0) {
|
|
|
|
context.lineWidth = this.primaryGridLineWidth;
|
|
|
|
context.strokeStyle = this.primaryGridLineColour;
|
|
|
|
} else {
|
|
|
|
context.lineWidth = this.gridLineWidth;
|
|
|
|
context.strokeStyle = this.gridLineColour;
|
|
|
|
}
|
|
|
|
context.stroke();
|
2017-04-24 19:12:14 +00:00
|
|
|
}
|
2017-04-24 20:42:31 +00:00
|
|
|
for(let ay = (this.viewport.y + (this.gridSize - (this.viewport.y % this.gridSize))) - this.gridSize; ay < (this.viewport.y + this.viewport.height); ay += this.gridSize)
|
2017-04-24 19:12:14 +00:00
|
|
|
{
|
2017-04-24 20:42:31 +00:00
|
|
|
context.beginPath();
|
2017-04-24 19:12:14 +00:00
|
|
|
context.moveTo(0, ay - this.viewport.y);
|
2017-04-24 20:42:31 +00:00
|
|
|
context.lineTo(this.viewport.width, ay - this.viewport.y);
|
|
|
|
|
|
|
|
if(Math.round(ay) == 0) {
|
|
|
|
context.lineWidth = this.primaryGridLineWidth;
|
|
|
|
context.strokeStyle = this.primaryGridLineColour;
|
|
|
|
} else {
|
|
|
|
context.lineWidth = this.gridLineWidth;
|
|
|
|
context.strokeStyle = this.gridLineColour;
|
|
|
|
}
|
|
|
|
context.stroke();
|
2017-04-24 19:12:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
context.restore();
|
2017-02-19 15:55:22 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 17:06:19 +00:00
|
|
|
/**
|
|
|
|
* Updates the canvas size to match the current viewport size.
|
|
|
|
*/
|
|
|
|
matchWindowSize() {
|
|
|
|
this.canvas.width = window.innerWidth;
|
|
|
|
this.canvas.height = window.innerHeight;
|
|
|
|
|
|
|
|
this.render(this.canvas, this.context);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes the canvas size track the window size.
|
|
|
|
*/
|
|
|
|
trackWindowSize() {
|
|
|
|
this.matchWindowSize();
|
|
|
|
window.addEventListener("resize", this.matchWindowSize.bind(this));
|
|
|
|
}
|
2017-02-04 21:26:48 +00:00
|
|
|
|
2017-07-29 20:26:06 +00:00
|
|
|
/**
|
|
|
|
* Sends the current viewport to the server.
|
|
|
|
*/
|
|
|
|
sendViewport() {
|
|
|
|
this.rippleLink.send({
|
|
|
|
Event: "ViewportUpdate",
|
|
|
|
NewViewport: {
|
|
|
|
X: parseInt(this.viewport.x),
|
|
|
|
Y: parseInt(this.viewport.y),
|
|
|
|
Width: parseInt(this.viewport.width),
|
|
|
|
Height: parseInt(this.viewport.height)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.lastViewportUpdate = +new Date();
|
|
|
|
}
|
|
|
|
|
2017-02-04 21:26:48 +00:00
|
|
|
/**
|
|
|
|
* Handles events generated by pan-zoom, the package that handles the
|
|
|
|
* dragging and zooming of the whiteboard.
|
|
|
|
*/
|
|
|
|
handleCanvasMovement(event) {
|
2017-04-15 12:13:07 +00:00
|
|
|
// Don't bother processing it if it's a mouse / touch interaction and
|
|
|
|
// the control key isn't pressed
|
2017-06-26 15:57:26 +00:00
|
|
|
if([ "mouse", "touch" ].includes(event.type) &&
|
|
|
|
!this.keyboard.DownKeys.includes(17) &&
|
|
|
|
this.interface.currentTool !== "pan")
|
2017-04-15 12:13:07 +00:00
|
|
|
return;
|
2017-04-14 19:22:01 +00:00
|
|
|
// Store the viewport information for later
|
|
|
|
this.viewportState = event;
|
2017-04-14 20:08:36 +00:00
|
|
|
|
2017-04-24 20:43:52 +00:00
|
|
|
this.viewport.x -= event.dx * 1/this.viewport.zoomLevel;
|
|
|
|
this.viewport.y -= event.dy * 1/this.viewport.zoomLevel;
|
2017-04-24 20:42:31 +00:00
|
|
|
this.viewport.zoomLevel += event.dz / 1000;
|
2017-06-26 16:53:18 +00:00
|
|
|
this.viewport.zoomLevel = clamp(this.viewport.zoomLevel, 0.1, 10000);
|
2017-07-29 19:42:07 +00:00
|
|
|
|
|
|
|
// Update the server on the new size of our viewport
|
|
|
|
|
|
|
|
setTimeout((function() {
|
|
|
|
if(+new Date() - this.lastViewportUpdate < (1 / this.cursorSyncer.cursorUpdateFrequency) * 1000)
|
|
|
|
return false;
|
|
|
|
|
2017-07-29 20:26:06 +00:00
|
|
|
this.sendViewport();
|
2017-07-29 19:42:07 +00:00
|
|
|
}).bind(this));
|
2017-02-04 21:26:48 +00:00
|
|
|
}
|
2017-02-19 11:57:42 +00:00
|
|
|
|
2017-04-15 15:20:30 +00:00
|
|
|
/**
|
|
|
|
* Handles the server's response to our handshake request
|
|
|
|
* @param {object} message The server's response to our handshake request.
|
|
|
|
*/
|
2017-02-19 13:22:35 +00:00
|
|
|
handleHandshakeResponse(message) {
|
|
|
|
console.log("Received handshake response");
|
|
|
|
|
|
|
|
// Store the information send by the server
|
|
|
|
this.Id = message.Id;
|
|
|
|
this.Colour = message.Colour;
|
|
|
|
|
2017-04-27 17:36:45 +00:00
|
|
|
this.interface.OurColour = this.Colour;
|
|
|
|
this.interface.setConnectedStatus(true);
|
2017-04-15 15:20:30 +00:00
|
|
|
|
|
|
|
// The pencil that draws the lines
|
2017-04-16 15:10:27 +00:00
|
|
|
this.pencil = new Pencil(this.rippleLink, this, this.canvas);
|
2017-05-01 13:40:05 +00:00
|
|
|
// The cache for the chunks
|
|
|
|
this.chunkCache = new ChunkCache(this);
|
2017-07-01 12:29:45 +00:00
|
|
|
// Create a new data structure to store client information in
|
|
|
|
this.otherClients = new ClientManager(this.rippleLink);
|
2017-04-23 16:40:41 +00:00
|
|
|
|
|
|
|
// Land on a default plane
|
|
|
|
// future ask the user which plane they want to join
|
|
|
|
this.rippleLink.send({
|
|
|
|
"Event": "PlaneChange",
|
|
|
|
"NewPlaneName": "default-plane"
|
|
|
|
});
|
2017-02-19 13:22:35 +00:00
|
|
|
}
|
|
|
|
|
2017-04-24 19:12:14 +00:00
|
|
|
/**
|
|
|
|
* Store the details about the new plane we've landed on that the server
|
|
|
|
* sends us.
|
|
|
|
* @param {object} message The plane change confirmation message to handle.
|
|
|
|
*/
|
|
|
|
handlePlaneChangeOk(message) {
|
|
|
|
this.currentPlaneName = message.NewPlaneName;
|
|
|
|
this.gridSize = message.GridSize;
|
|
|
|
console.info(`Plane changed to ${this.currentPlaneName} with a grid size of ${this.gridSize} successfully.`);
|
|
|
|
}
|
2017-01-21 17:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default BoardWindow;
|