"use strict"; import Vector from './Utilities/Vector'; import Rectangle from './Utilities/Rectangle'; class OtherClient { constructor() { // The unique id of this client. this.Id = -1; // The name of this client. this.Name = ""; // The colour the server assigned to this client. this.Colour = "green"; // The position of this clients' cursor. this.CursorPosition = new Vector(0, 0); // The position and dimensions of this client's viewport. this.Viewport = Rectangle.Zero.clone(); // The time this other client's information was last updated. this.LastUpdated = new Date(); // The lines that this client is currently drawing. this.currentLines = {}; } update(data) { // Update our local copy of this clients' name and colour (just in case) this.Name = data.Name; this.Colour = data.Colour; // Update the cursor position this.CursorPosition.x = data.CursorPosition.X; this.CursorPosition.y = data.CursorPosition.Y; // Update the viewport this.Viewport.x = data.Viewport.X; this.Viewport.y = data.Viewport.X; this.Viewport.width = data.Viewport.Width; this.Viewport.height = data.Viewport.Height; } /** * Fetches a line that is currently being drawn by this client with the specified id * @param {[type]} lineId [description] * @return {[type]} [description] */ fetchLine(lineId) { if(!this.currentLines.hasOwnProperty(lineId)) throw new Exception(`Error: A client with the id ${lineId} does not appear to be attached to the OtherClient with the id ${this.Id}`); return this.currentLines[lineId]; } } /** * Converts raw NibriClient data sent from the server into an instance of OtherClient. * @param {object} raw The raw data to convert. * @return {OtherClient} The converted data. */ OtherClient.FromRaw = function(raw) { let newOtherClient = new OtherClient(); newOtherClient.Id = raw.Id; newOtherClient.CursorPosition = new Vector( raw.CursorPosition.X, raw.CursorPosition.Y ); newOtherClient.Viewport = new Rectangle( raw.Viewport.X, raw.Viewport.Y, raw.Viewport.Width, raw.Viewport.Height ); newOtherClient.Colour = raw.Colour; newOtherClient.LastUpdated = new Date(); return newOtherClient; } export default OtherClient;