From 0ead354e628e8131c97f4f48216b055ce454c0c7 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 6 May 2021 03:55:20 +0100 Subject: [PATCH] piece drawer yanno --- client/public/scrabble/game.js | 4 +- client/public/scrabble/network.js | 75 +++++++++++++++++++++++++++++-- client/public/scrabble/pieces.js | 22 +++++++++ 3 files changed, 96 insertions(+), 5 deletions(-) diff --git a/client/public/scrabble/game.js b/client/public/scrabble/game.js index 1c9381f..76738b8 100644 --- a/client/public/scrabble/game.js +++ b/client/public/scrabble/game.js @@ -7,7 +7,7 @@ function computeTurn() } -function initGame(boardstate, players, tiles) +function initGame(boardstate, myplayer, players) { - + } diff --git a/client/public/scrabble/network.js b/client/public/scrabble/network.js index c057464..f39f43d 100644 --- a/client/public/scrabble/network.js +++ b/client/public/scrabble/network.js @@ -103,6 +103,62 @@ function onDisconnect() } +/* +GAME OBJECT +{ + // Reference UID (of lobby) + uid: uid, + locale: en, + players: [{ + uid: uid, + name: username, + activetiles: [tile: { + letter: letter, + score: int + }], + score: int + }], + // Index of players whos turn it is + turn: int, + // Array of GAMESTATEs, latest at head of array + gamestates: [], + tilebag: [], + tileset: [] +} +GAMESTATE OBJECT +{ + // UID of the player that played the turn + playeruid: uid, + turn: int, + // Generated after turn is processed + outcome: { + valid: bool, + points: pointsgained, + words: [{ + word: word, + points: points, + tiles: [{ + pos: {x: x, y: y}, + modifier: modifier, + letter: letter, + score: int + }] + }], + } + oldboardtiles: [{ + pos: {x: x, y: y}, + modifier: modifier, + letter: letter, + score: int + }] + boardtiles: [{ + pos: {x: x, y: y}, + modifier: modifier, + letter: letter, + score: int + }] +} +*/ function onGameBegin(socket, args) { if (!args) @@ -117,10 +173,23 @@ function onGameBegin(socket, args) return; } - console.log(args); + const boardstate = args.game.gamestates[args.game.gamestates.length]; + const myplayer = args.gameuser; + const players = args.game.players; - - + if (!boardstate || !myplayer || !players) + { + ConnectionState.innerHTML = localeString('error-game-begin'); + return; + } + + const status = initGame(boardstate, myplayer, players); + + if (!status) + { + ConnectionState.innerHTML = localeString('error-game-begin'); + return; + } } function onStartTurn(socket, args) diff --git a/client/public/scrabble/pieces.js b/client/public/scrabble/pieces.js index f44e6c3..1a74247 100644 --- a/client/public/scrabble/pieces.js +++ b/client/public/scrabble/pieces.js @@ -17,6 +17,28 @@ Number.prototype.clamp = function(min, max) { return Math.min(Math.max(this, min), max); }; + +/* +TILE OBJECT +{ + +} +*/ +let PiecesDrawer = []; + +// Returns array of tile IDs that were added +function addPiecesToDrawer(pieces) +{ + +} + +// Removes regardless of vadility +function removePiecesFromDrawer(pieces) +{ + +} + + function updateBoardCoords() { BOARD_X = document.querySelector('#game-container').getBoundingClientRect().left + window.scrollX;