From c292ebb2a014646005b01e27253c162f1d639387 Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Mon, 9 Mar 2020 10:37:30 +0100 Subject: [PATCH] Draft rematch (not working yet) + fix Crazyhouse getPromotedFen() --- client/src/utils/gameStorage.js | 5 +- client/src/variants/Crazyhouse.js | 8 +- client/src/views/Game.vue | 176 +++++++++++++++++++++++++++--- client/src/views/Hall.vue | 66 ++++++----- server/models/Game.js | 12 +- server/routes/games.js | 5 +- server/sockets.js | 21 +++- 7 files changed, 237 insertions(+), 56 deletions(-) diff --git a/client/src/utils/gameStorage.js b/client/src/utils/gameStorage.js index 92db2991..59efb43a 100644 --- a/client/src/utils/gameStorage.js +++ b/client/src/utils/gameStorage.js @@ -43,7 +43,7 @@ export const GameStorage = { // Optional callback to get error status add: function(game, callback) { dbOperation((err,db) => { - if (err) { + if (!!err) { callback("error"); return; } @@ -51,6 +51,9 @@ export const GameStorage = { transaction.oncomplete = function() { callback(); //everything's fine }; + transaction.onerror = function(err) { + callback(err); //duplicate key error (most likely) + }; let objectStore = transaction.objectStore("games"); objectStore.add(game); }); diff --git a/client/src/variants/Crazyhouse.js b/client/src/variants/Crazyhouse.js index 984c902f..d677823d 100644 --- a/client/src/variants/Crazyhouse.js +++ b/client/src/variants/Crazyhouse.js @@ -66,11 +66,11 @@ export const VariantRules = class CrazyhouseRules extends ChessRules { let res = ""; for (let i = 0; i < V.size.x; i++) { for (let j = 0; j < V.size.y; j++) { - if (this.promoted[i][j]) res += V.CoordsToSquare({ x: i, y: j }); + if (this.promoted[i][j]) res += V.CoordsToSquare({ x: i, y: j }) + ","; } } + // Remove last comma: if (res.length > 0) res = res.slice(0, -1); - //remove last comma else res = "-"; return res; } @@ -98,8 +98,8 @@ export const VariantRules = class CrazyhouseRules extends ChessRules { this.promoted = ArrayFun.init(V.size.x, V.size.y, false); if (fenParsed.promoted != "-") { for (let square of fenParsed.promoted.split(",")) { - const [x, y] = V.SquareToCoords(square); - this.promoted[x][y] = true; + const coords = V.SquareToCoords(square); + this.promoted[coords.x][coords.y] = true; } } } diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index d920053a..a7cb6a90 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -1,5 +1,13 @@