From: Benjamin Auder Date: Wed, 19 Feb 2020 14:15:20 +0000 (+0100) Subject: Avoid direct references to (Dark) variant name in BaseGame, Analyse and Board X-Git-Url: https://git.auder.net/variants/Chakart/pieces/img/doc/scripts/%3C?a=commitdiff_plain;h=20620465247585ed4e845885c4d9fee8cd6920c1;p=vchess.git Avoid direct references to (Dark) variant name in BaseGame, Analyse and Board --- diff --git a/client/src/base_rules.js b/client/src/base_rules.js index 42d9bdc8..5ebe4997 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -32,13 +32,26 @@ export const ChessRules = class ChessRules { ////////////// // MISC UTILS + // Some variants don't have flags: static get HasFlags() { return true; - } //some variants don't have flags + } + // Some variants don't have en-passant static get HasEnpassant() { return true; - } //some variants don't have ep. + } + + // Some variants cannot have analyse mode + static get CanAnalyse() { + return true; + } + + // Some variants show incomplete information, + // and thus show only a partial moves list or no list at all. + static get ShowMoves() { + return "all"; + } // Path to pieces static getPpath(b) { diff --git a/client/src/components/BaseGame.vue b/client/src/components/BaseGame.vue index 2f49169a..07d62cf7 100644 --- a/client/src/components/BaseGame.vue +++ b/client/src/components/BaseGame.vue @@ -33,14 +33,15 @@ div#baseGame( Board( :vr="vr" :last-move="lastMove" - :analyze="analyze" + :analyze="game.mode=='analyze'" + :score="game.score" :user-color="game.mycolor" :orientation="orientation" :vname="game.vname" :incheck="incheck" @play-move="play" ) - #turnIndicator(v-if="game.vname=='Dark' && game.score=='*'") {{ turn }} + #turnIndicator(v-if="showTurn") {{ turn }} #controls button(@click="gotoBegin()") << button(@click="undo()") < @@ -48,16 +49,16 @@ div#baseGame( button(@click="play()") > button(@click="gotoEnd()") >> #belowControls - #downloadDiv(v-if="game.vname!='Dark' || game.score!='*'") + #downloadDiv(v-if="allowDownloadPGN") a#download(href="#") button(@click="download()") {{ st.tr["Download"] }} PGN button(onClick="window.doClick('modalAdjust')") ⤢ button( - v-if="game.vname!='Dark' && game.mode!='analyze'" + v-if="canAnalyze" @click="analyzePosition()" ) | {{ st.tr["Analyse"] }} - // NOTE: rather ugly hack to avoid showing twice "rules" link... + // NOTE: variants pages already have a "Rules" link on top button( v-if="!$route.path.match('/variants/')" @click="showRules()" @@ -122,17 +123,19 @@ export default { }, computed: { showMoves: function() { - return this.game.vname != "Dark" || this.game.score != "*"; + return this.game.score != "*" || (window.V && V.ShowMoves == "all"); + }, + showTurn: function() { + return this.game.score == '*' && window.V && V.ShowMoves != "all"; }, turn: function() { return this.st.tr[(this.vr.turn == 'w' ? "White" : "Black") + " to move"]; }, - analyze: function() { - return ( - this.game.mode == "analyze" || - // From Board viewpoint, a finished Dark game == analyze (TODO: unclear) - (this.game.vname == "Dark" && this.game.score != "*") - ); + canAnalyze: function() { + return this.game.mode != "analyze" && window.V && V.CanAnalyze; + }, + allowDownloadPGN: function() { + return this.game.score != "*" || (window.V && V.ShowMoves == "all"); } }, created: function() { @@ -381,7 +384,7 @@ export default { if (!navigate && this.game.mode != "analyze") this.$emit("newmove", move); //post-processing (e.g. computer play) }; - if (!!receive && this.game.vname != "Dark") + if (!!receive && V.ShowMoves == "all") this.animateMove(move, doPlayMove); else doPlayMove(); }, diff --git a/client/src/components/Board.vue b/client/src/components/Board.vue index 45c7293b..bd2612d8 100644 --- a/client/src/components/Board.vue +++ b/client/src/components/Board.vue @@ -11,6 +11,7 @@ export default { "vr", "lastMove", "analyze", + "score", "incheck", "orientation", "userColor", @@ -46,9 +47,9 @@ export default { incheckSq[sq[0]][sq[1]] = true; }); - // Create board element (+ reserves if needed by variant or mode) + // Create board element (+ reserves if needed by variant) const lm = this.lastMove; - const showLight = this.settings.highlight && this.vname != "Dark"; + const showLight = this.settings.highlight && V.ShowMoves == "all"; const gameDiv = h( "div", { @@ -72,8 +73,7 @@ export default { let elems = []; if ( this.vr.board[ci][cj] != V.EMPTY && - (this.vname != "Dark" || - this.analyze || + (!this.vr.enlightened || this.analyze || this.score != "*" || (!!this.userColor && this.vr.enlightened[this.userColor][ci][cj])) ) { @@ -116,8 +116,9 @@ export default { "dark-square": (i + j) % 2 == 1, [this.settings.bcolor]: true, "in-shadow": - this.vname == "Dark" && !this.analyze && + this.score == "*" && + this.vr.enlightened && (!this.userColor || !this.vr.enlightened[this.userColor][ci][cj]), highlight: diff --git a/client/src/components/ComputerGame.vue b/client/src/components/ComputerGame.vue index 4d354713..0d566a81 100644 --- a/client/src/components/ComputerGame.vue +++ b/client/src/components/ComputerGame.vue @@ -57,8 +57,8 @@ export default { const delay = Math.max(500 - (Date.now() - this.timeStart), 0); setTimeout(() => { if (this.currentUrl != document.location.href) return; //page change - // NOTE: Dark and 2-moves are incompatible - const animate = this.gameInfo.vname != "Dark"; + // NOTE: do not animate move if special display (ShowMoves != "all") + const animate = V.ShowMoves == "all"; const animDelay = animate ? 250 : 0; let moveIdx = 0; let self = this; diff --git a/client/src/translations/en.js b/client/src/translations/en.js index 94be8f8a..5afbc59a 100644 --- a/client/src/translations/en.js +++ b/client/src/translations/en.js @@ -4,8 +4,6 @@ export const translations = { "Accept draw?": "Accept draw?", All: "All", Analyse: "Analyse", - "Analyse in Dark mode makes no sense!": - "Analyse in Dark mode makes no sense!", "Any player": "Any player", "Are you sure?": "Are you sure?", "Authentication successful!": "Authentication successful!", diff --git a/client/src/translations/es.js b/client/src/translations/es.js index 56c6733b..fd9f28ea 100644 --- a/client/src/translations/es.js +++ b/client/src/translations/es.js @@ -4,8 +4,6 @@ export const translations = { "Accept draw?": "¿Acceptar tablas?", All: "Todos", Analyse: "Analizar", - "Analyse in Dark mode makes no sense!": - "¡Analizar en modo Dark no tiene sentido!", "Any player": "Cualquier jugador", Apply: "Aplicar", "Are you sure?": "¿Está usted seguro?", diff --git a/client/src/translations/fr.js b/client/src/translations/fr.js index 3e9aa6ab..0d776b4e 100644 --- a/client/src/translations/fr.js +++ b/client/src/translations/fr.js @@ -4,8 +4,6 @@ export const translations = { "Accept draw?": "Accepter la nulle ?", All: "Tous", Analyse: "Analyser", - "Analyse in Dark mode makes no sense!": - "Analyser en mode Dark n'a pas de sens !", "Any player": "N'importe qui", Apply: "Appliquer", "Authentication successful!": "Authentification réussie !", diff --git a/client/src/variants/Dark.js b/client/src/variants/Dark.js index 358362c7..cdacf9d2 100644 --- a/client/src/variants/Dark.js +++ b/client/src/variants/Dark.js @@ -3,7 +3,16 @@ import { ArrayFun } from "@/utils/array"; import { randInt } from "@/utils/alea"; export const VariantRules = class DarkRules extends ChessRules { - // Standard rules, in the shadow + // Analyse in Dark mode makes no sense + static get CanAnalyse() { + return false; + } + + // Moves are revealed only when game ends + static get ShowMoves() { + return "none"; + } + setOtherVariables(fen) { super.setOtherVariables(fen); const [sizeX, sizeY] = [V.size.x, V.size.y]; diff --git a/client/src/views/Analyse.vue b/client/src/views/Analyse.vue index 7259632c..d1c6d593 100644 --- a/client/src/views/Analyse.vue +++ b/client/src/views/Analyse.vue @@ -37,7 +37,6 @@ export default { }, vr: null, //"variant rules" object initialized from FEN curFen: "" - //people: [], //players + observers //TODO later: interactive analyze... }; }, watch: { @@ -50,13 +49,8 @@ export default { }, created: function() { this.gameRef.vname = this.$route.params["vname"]; - if (this.gameRef.vname == "Dark") { - alert(this.st.tr["Analyse in Dark mode makes no sense!"]); - history.back(); //or this.$router.go(-1) - } else { - this.gameRef.fen = this.$route.query["fen"].replace(/_/g, " "); - this.initialize(); - } + this.gameRef.fen = this.$route.query["fen"].replace(/_/g, " "); + this.initialize(); }, methods: { initialize: async function() { diff --git a/client/src/views/Rules.vue b/client/src/views/Rules.vue index 55564ffd..8ac03a91 100644 --- a/client/src/views/Rules.vue +++ b/client/src/views/Rules.vue @@ -20,7 +20,7 @@ main ) | {{ st.tr["Stop game"] }} button( - v-if="display=='rules' && gameInfo.vname!='Dark'" + v-if="showAnalyzeBtn" @click="gotoAnalyze()" ) | {{ st.tr["Analyse"] }} @@ -69,6 +69,9 @@ export default { this.re_setVariant(this.$route.params["vname"]); }, computed: { + showAnalyzeBtn: function() { + return (this.display=='rules' && (!window.V || V.CanAnalyse)); + }, content: function() { if (!this.gameInfo.vname) return ""; //variant not set yet // (AJAX) Request to get rules content (plain text, HTML)