From: Benjamin Auder Date: Mon, 9 Mar 2020 09:37:30 +0000 (+0100) Subject: Draft rematch (not working yet) + fix Crazyhouse getPromotedFen() X-Git-Url: https://git.auder.net/variants/Bario/js/vendor/current/git-logo.png?a=commitdiff_plain;h=c292ebb2a014646005b01e27253c162f1d639387;p=vchess.git Draft rematch (not working yet) + fix Crazyhouse getPromotedFen() --- 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 @@