diff --git a/dist/bundle.js b/dist/bundle.js index fe62b80..d849a3b 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -95,7 +95,7 @@ var ui = /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Player\", function() { return Player; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Series\", function() { return Series; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Payload\", function() { return Payload; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"EventEnum\", function() { return EventEnum; });\n/* harmony import */ var _services__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./services */ \"./src/services.js\");\n\n\n\n\n/**\n * Logging\n * Set to true to enable console.debug() messages\n */\nconst Logging = true\n\nclass BaseUtils {\n constructor() {}\n getUUID () {\n function s4 () {\n return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1)\n }\n return (s4() + s4() + '-' + s4() + '-4' + s4().slice(1) + '-8' + s4().slice(1) + '-' + s4() + s4() + s4())\n }\n setCookie (cname, cvalue) {\n document.cookie = cname + \"=\" + cvalue + \";path=/\"\n return this\n }\n getCookie (cname) {\n let name = cname + \"=\"\n let decodedCookie = decodeURIComponent(document.cookie)\n let ca = decodedCookie.split(';')\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i]\n while (c.charAt(0) == ' ') {\n c = c.substring(1)\n }\n if (c.indexOf(name) == 0) {\n return c.substring(name.length, c.length)\n }\n }\n return \"\"\n }\n log(msg) {\n if (Logging) {\n if (msg) {\n console.debug(\"Method \" + msg + \"()\", this)\n } else {\n console.debug(this)\n }\n }\n }\n}\n/**\n * Player object\n *\n * @export\n * @class Player\n * @property {string} ID - Unique player identifier\n * @extends {BaseUtils}\n */\nclass Player extends BaseUtils {\n constructor() {\n super()\n this.setId(this.getCookie(\"player_id\") || this.getUUID())\n this.log()\n return this\n }\n getId () {\n return this.ID.toLowerCase()\n }\n setId (id) {\n this.ID = id\n this.setCookie(\"player_id\", id)\n this.log(\"setId\")\n return this\n }\n getName() {\n return this.getCookie(\"player_name\")\n }\n setName(name) {\n this.setCookie(\"player_name\", name)\n }\n}\nclass Series extends BaseUtils {\n constructor() {\n super()\n this.setId((new URLSearchParams(window.location.search)).get('sid') || _services__WEBPACK_IMPORTED_MODULE_0__[\"generateRandom\"](6))\n this.gameMatrix = [\n null, null, null,\n null, null, null,\n null, null, null\n ]\n this.turn = undefined\n this.gameMatrixHistory = []\n this.log()\n return this\n }\n getId () {\n return this.id\n }\n setId (id) {\n if (id)\n history.replaceState(null, \"\", \"?sid=\" + id)\n this.id = id\n this.log(\"setId\")\n return this\n }\n getGameMatrix () {\n return this.gameMatrix\n }\n setGameMatrix (matrix) {\n this.gameMatrix = matrix\n return this\n }\n getGameMatrixHistory() {\n return this.gameMatrixHistory\n }\n setGameMatrixHistory(history) {\n this.gameMatrixHistory = history\n }\n emptyGameMatrix() {\n this.gameMatrix = [\n null, null, null,\n null, null, null,\n null, null, null\n ]\n }\n getTurn() {\n return this.turn\n }\n setTurn(player_id) {\n console.debug(\"Set Player Turn\", player_id)\n this.turn = player_id\n this.log(\"setTurn\")\n return this\n }\n logGame() {\n this.tally.push(this.gameMatrix)\n this.log(\"logGame\")\n }\n}\n\n/**\n * Payload for use with websocket\n * \n * @export\n * @class Payload\n * @extends {BaseUtils}\n * @typedef {string} PlayerID\n * @property {string} SeriesID - Taken from the URL query param ?sid\n * @property {PlayerID} Sender - The sender of the socket payload\n * @property {EventEnum} Event - The payload event type\n * @property {PlayerID[]} Matrix - An array of length 9 containing PlayerIDs or null\n * @property {string} Message - Chat message\n * @property {Object} Data - Any additional payload\n */\nclass Payload extends BaseUtils {\n constructor(series_id, player_id) {\n super()\n if (!series_id || !player_id) {\n throw \"SeriesID and PlayerID are required to create a new WebSocket Payload\"\n }\n this.SeriesID = series_id\n this.Sender = player_id\n this.log()\n return this\n }\n /**\n * Set the payload event type\n * @param {EventType} event - Event type\n * @returns Payload object\n */\n setEventType(event) {\n this.Event = event\n this.log(\"setEventType\")\n return this\n }\n /**\n * Set the payload game matrix array\n * @param {PlayerID[]} matrix - An array of length 9 containing PlayerIDs or null\n * @returns Payload object\n */\n setMatrix(matrix) {\n this.Matrix = matrix\n this.log(\"setMatrix\")\n return this\n }\n /**\n * Set the payload game matrix history array\n * @param {PlayerID[]} history - An array of arrays containing the Game Matrix\n * @returns Payload object\n */\n setMatrixHistory (history) {\n this.MatrixHistory = history\n this.log(\"setMatrixHistory\")\n return this\n }\n /**\n * Set the payload chat message\n * @param {string} message - Chat Message\n * @returns Payload object\n */\n setMessage(message) {\n this.Message = message\n this.log(\"setMessage\")\n return this\n }\n\n /**\n * Exports the payload using JSON.stringify()\n * @returns {string} Serialized payload object\n */\n serialize() {\n return JSON.stringify({\n SeriesID: this.SeriesID,\n Sender: this.Sender,\n Event: this.Event,\n Matrix: this.Matrix,\n Message: this.Message,\n })\n }\n\n}\n\nconst EventEnum = {\n ANYBODYHOME: 1,\n IAMHERE: 2,\n CHAT: 3,\n SNAP: 4,\n MOVE: 5,\n NEW: 6,\n}\n\n//# sourceURL=webpack://ui/./src/classes.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Player\", function() { return Player; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Series\", function() { return Series; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Payload\", function() { return Payload; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"EventEnum\", function() { return EventEnum; });\n/* harmony import */ var _services__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./services */ \"./src/services.js\");\n\n\n\n\n/**\n * Logging\n * Set to true to enable console.debug() messages\n */\nconst Logging = true\n\nclass BaseUtils {\n constructor() {}\n getUUID () {\n function s4 () {\n return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1)\n }\n return (s4() + s4() + '-' + s4() + '-4' + s4().slice(1) + '-8' + s4().slice(1) + '-' + s4() + s4() + s4())\n }\n setCookie (cname, cvalue) {\n document.cookie = cname + \"=\" + cvalue + \";path=/\"\n return this\n }\n getCookie (cname) {\n let name = cname + \"=\"\n let decodedCookie = decodeURIComponent(document.cookie)\n let ca = decodedCookie.split(';')\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i]\n while (c.charAt(0) == ' ') {\n c = c.substring(1)\n }\n if (c.indexOf(name) == 0) {\n return c.substring(name.length, c.length)\n }\n }\n return \"\"\n }\n log(msg) {\n if (Logging) {\n if (msg) {\n console.debug(\"Method \" + msg + \"()\", this)\n } else {\n console.debug(this)\n }\n }\n }\n}\n/**\n * Player object\n *\n * @export\n * @class Player\n * @property {string} ID - Unique player identifier\n * @extends {BaseUtils}\n */\nclass Player extends BaseUtils {\n constructor() {\n super()\n this.setId(this.getCookie(\"player_id\") || this.getUUID())\n this.log()\n return this\n }\n getId () {\n return this.ID.toLowerCase()\n }\n setId (id) {\n this.ID = id\n this.setCookie(\"player_id\", id)\n this.log(\"setId\")\n return this\n }\n getName() {\n return this.getCookie(\"player_name\")\n }\n setName(name) {\n this.setCookie(\"player_name\", name)\n }\n}\nclass Series extends BaseUtils {\n constructor() {\n super()\n this.setId((new URLSearchParams(window.location.search)).get('sid') || _services__WEBPACK_IMPORTED_MODULE_0__[\"generateRandom\"](6))\n this.gameMatrix = [\n null, null, null,\n null, null, null,\n null, null, null\n ]\n this.turn = undefined\n this.gameMatrixHistory = []\n this.log()\n return this\n }\n getId () {\n return this.id\n }\n setId (id) {\n if (id)\n history.replaceState(null, \"\", \"?sid=\" + id)\n this.id = id\n this.log(\"setId\")\n return this\n }\n getGameMatrix () {\n return this.gameMatrix\n }\n setGameMatrix (matrix) {\n this.gameMatrix = matrix\n return this\n }\n getGameMatrixHistory() {\n return this.gameMatrixHistory\n }\n setGameMatrixHistory(history) {\n this.gameMatrixHistory = history\n }\n emptyGameMatrix() {\n this.gameMatrix = [\n null, null, null,\n null, null, null,\n null, null, null\n ]\n }\n getTurn() {\n return this.turn\n }\n setTurn(player_id) {\n console.debug(\"Set Player Turn\", player_id)\n this.turn = player_id\n this.log(\"setTurn\")\n return this\n }\n logGame() {\n this.gameMatrixHistory.push(this.gameMatrix)\n this.log(\"logGame\")\n }\n}\n\n/**\n * Payload for use with websocket\n * \n * @export\n * @class Payload\n * @extends {BaseUtils}\n * @typedef {string} PlayerID\n * @property {string} SeriesID - Taken from the URL query param ?sid\n * @property {PlayerID} Sender - The sender of the socket payload\n * @property {EventEnum} Event - The payload event type\n * @property {PlayerID[]} Matrix - An array of length 9 containing PlayerIDs or null\n * @property {string} Message - Chat message\n * @property {Object} Data - Any additional payload\n */\nclass Payload extends BaseUtils {\n constructor(series_id, player_id) {\n super()\n if (!series_id || !player_id) {\n throw \"SeriesID and PlayerID are required to create a new WebSocket Payload\"\n }\n this.SeriesID = series_id\n this.Sender = player_id\n this.log()\n return this\n }\n /**\n * Set the payload event type\n * @param {EventType} event - Event type\n * @returns Payload object\n */\n setEventType(event) {\n this.Event = event\n this.log(\"setEventType\")\n return this\n }\n /**\n * Set the payload game matrix array\n * @param {PlayerID[]} matrix - An array of length 9 containing PlayerIDs or null\n * @returns Payload object\n */\n setMatrix(matrix) {\n this.Matrix = matrix\n this.log(\"setMatrix\")\n return this\n }\n /**\n * Set the payload game matrix history array\n * @param {PlayerID[]} history - An array of arrays containing the Game Matrix\n * @returns Payload object\n */\n setMatrixHistory (history) {\n this.MatrixHistory = history\n this.log(\"setMatrixHistory\")\n return this\n }\n /**\n * Set the payload chat message\n * @param {string} message - Chat Message\n * @returns Payload object\n */\n setMessage(message) {\n this.Message = message\n this.log(\"setMessage\")\n return this\n }\n\n /**\n * Exports the payload using JSON.stringify()\n * @returns {string} Serialized payload object\n */\n serialize() {\n return JSON.stringify({\n SeriesID: this.SeriesID,\n Sender: this.Sender,\n Event: this.Event,\n Matrix: this.Matrix,\n Message: this.Message,\n })\n }\n\n}\n\nconst EventEnum = {\n ANYBODYHOME: 1,\n IAMHERE: 2,\n CHAT: 3,\n SNAP: 4,\n MOVE: 5,\n NEW: 6,\n}\n\n//# sourceURL=webpack://ui/./src/classes.js?"); /***/ }), diff --git a/src/classes.js b/src/classes.js index 487d2b0..3fa736e 100644 --- a/src/classes.js +++ b/src/classes.js @@ -130,7 +130,7 @@ export class Series extends BaseUtils { return this } logGame() { - this.tally.push(this.gameMatrix) + this.gameMatrixHistory.push(this.gameMatrix) this.log("logGame") } }