From: Benjamin Auder Date: Wed, 6 Feb 2019 18:16:12 +0000 (+0100) Subject: Seemingly failed attempt at 'componentifying VariantRules' X-Git-Url: https://git.auder.net/game/doc/html/current/%24%7BgetWhatsApp%28link%29%7D?a=commitdiff_plain;h=42eb4eaf62becc9260897277e1cfe5882eba2017;p=vchess.git Seemingly failed attempt at 'componentifying VariantRules' --- diff --git a/client/package-lock.json b/client/package-lock.json index 020d47e0..76d6211d 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -8837,6 +8837,17 @@ "pug-walk": "^1.1.7" } }, + "pug-loader": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/pug-loader/-/pug-loader-2.4.0.tgz", + "integrity": "sha512-cD4bU2wmkZ1EEVyu0IfKOsh1F26KPva5oglO1Doc3knx8VpBIXmFHw16k9sITYIjQMCnRv1vb4vfQgy7VdR6eg==", + "dev": true, + "requires": { + "loader-utils": "^1.1.0", + "pug-walk": "^1.0.0", + "resolve": "^1.1.7" + } + }, "pug-parser": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/pug-parser/-/pug-parser-5.0.0.tgz", @@ -9005,9 +9016,9 @@ }, "dependencies": { "ajv-keywords": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.2.0.tgz", - "integrity": "sha1-6GuBnGAs+IIa1jdBNpjx3sAhhHo=", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.3.0.tgz", + "integrity": "sha512-CMzN9S62ZOO4sA/mJZIO4S++ZM7KFWzH3PPWkveLhy4OZ9i1/VatgwWMD46w/XbGCBy7Ye0gCk+Za6mmyfKK7g==", "dev": true }, "schema-utils": { diff --git a/client/package.json b/client/package.json index 62781668..6f8f270a 100644 --- a/client/package.json +++ b/client/package.json @@ -21,6 +21,7 @@ "lint-staged": "^8.1.0", "node-sass": "^4.9.0", "pug": "^2.0.3", + "pug-loader": "^2.4.0", "pug-plain-loader": "^1.0.0", "raw-loader": "^1.0.0", "sass-loader": "^7.0.1", diff --git a/client/src/components/Diagrammer.vue b/client/src/components/Diagrammer.vue new file mode 100644 index 00000000..04767dfe --- /dev/null +++ b/client/src/components/Diagrammer.vue @@ -0,0 +1,181 @@ + diff --git a/client/src/components/VariantRules.vue b/client/src/components/VariantRules.vue new file mode 100644 index 00000000..a2c89e32 --- /dev/null +++ b/client/src/components/VariantRules.vue @@ -0,0 +1,48 @@ + + + + + + + diff --git a/client/src/rules/Alice/en.pug b/client/src/rules/Alice/en.pug index be97d1b4..6bba6407 100644 --- a/client/src/rules/Alice/en.pug +++ b/client/src/rules/Alice/en.pug @@ -21,8 +21,8 @@ ul figure.diagram-container // TODO: sub-component + use pug-loader instead of raw-loader - Diagram(:fen="rnbqkbnr/ppp1pppp/8/8/2p5/5O2/PP1PPPPP/RNBQKB1R") - .diagram + Diagram(fen="rnbqkbnr/ppp1pppp/8/8/2p5/5O2/PP1PPPPP/RNBQKB1R" vname="Alice") + //.diagram | fen:rnbqkbnr/ppp1pppp/8/8/2p5/5O2/PP1PPPPP/RNBQKB1R: figcaption After the moves 1.Nf3 Pd5 2.Pc4 Sxc4 diff --git a/client/src/rules/Chess960/fr.pug b/client/src/rules/Chess960/fr.pug index 9b62de16..3325f810 100644 --- a/client/src/rules/Chess960/fr.pug +++ b/client/src/rules/Chess960/fr.pug @@ -16,8 +16,7 @@ p. en arrivant sur une case occupée (avec une seule exception, détaillée plus bas). figure.diagram-container - .diagram - | fen:rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR: + Diagrammer(fen="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR" vname="Chess960") figcaption Position de départ habituelle. p. diff --git a/client/src/utils/printDiagram.js b/client/src/utils/printDiagram.js deleted file mode 100644 index 7ae23228..00000000 --- a/client/src/utils/printDiagram.js +++ /dev/null @@ -1,110 +0,0 @@ -import { ArrayFun } from "@/utils/array"; - -// Turn (human) marks into coordinates -function getMarkArray(marks) -{ - if (!marks || marks == "-") - return []; - let markArray = ArrayFun.init(V.size.x, V.size.y, false); - const squares = marks.split(","); - for (let i=0; i= 0) - { - // Shadow a range of squares, horizontally or vertically - const firstLastSq = squares[i].split("-"); - const range = - [ - V.SquareToCoords(firstLastSq[0]), - V.SquareToCoords(firstLastSq[1]) - ]; - const step = - [ - range[1].x == range[0].x - ? 0 - : (range[1].x - range[0].x) / Math.abs(range[1].x - range[0].x), - range[1].y == range[0].y - ? 0 - : (range[1].y - range[0].y) / Math.abs(range[1].y - range[0].y) - ]; - // Convention: range always from smaller to larger number - for (let x=range[0].x, y=range[0].y; x <= range[1].x && y <= range[1].y; - x += step[0], y += step[1]) - { - shadowArray[x][y] = true; - } - continue; - } - // Shadow just one square: - const coords = V.SquareToCoords(squares[i]); - shadowArray[coords.x][coords.y] = true; - } - return shadowArray; -} - -// args: object with position (mandatory), and -// orientation, marks, shadow (optional) -export function getDiagram(args) -{ - // Obtain the array of pieces images names: - const board = V.GetBoard(args.position); - const orientation = args.orientation || "w"; - const markArray = getMarkArray(args.marks); - const shadowArray = getShadowArray(args.shadow); - let boardDiv = ""; - const [startX,startY,inc] = orientation == 'w' - ? [0, 0, 1] - : [V.size.x-1, V.size.y-1, -1]; - for (let i=startX; i>=0 && i=0 && j 0 && shadowArray[i][j] ? " in-shadow" : "") + - "'>"; - if (board[i][j] != V.EMPTY) - { - boardDiv += ""; - } - if (markArray.length > 0 && markArray[i][j]) - boardDiv += ""; - boardDiv += ""; - } - boardDiv += ""; - } - return boardDiv; -} diff --git a/client/src/views/Rules.vue b/client/src/views/Rules.vue index fd26f16b..fd668462 100644 --- a/client/src/views/Rules.vue +++ b/client/src/views/Rules.vue @@ -9,7 +9,7 @@ | Beat the computer! button(v-show="gameInProgress" @click="stopGame") | Stop game - div(v-show="display=='rules'" v-html="content" class="section-content") + VariantRules(v-show="display=='rules'" :vname="variant.name") Game(v-show="display=='computer'" :gid-or-fen="fen" :mode="mode" :sub-mode="subMode" :variant="variant" @computer-think="gameInProgress=false" @game-over="stopGame") @@ -18,17 +18,17 @@