X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FHex%2Fclass.js;h=b82af417a74311f418e0f631a5fa9f2c46a9f564;hb=eceb02f712e49d6c8b2fa90691c93161ca015248;hp=91a0fe67ce89e3394388d004fc6a6588fca9c33f;hpb=437dfd42748eb2359103fd87a7d0e780121a7865;p=xogo.git diff --git a/variants/Hex/class.js b/variants/Hex/class.js index 91a0fe6..b82af41 100644 --- a/variants/Hex/class.js +++ b/variants/Hex/class.js @@ -1,8 +1,8 @@ -import ChessRules from "/base_rules.js"; +import AbstractClickFillRules from "/variants/_ClickFill/class.js"; import PiPo from "/utils/PiPo.js"; import Move from "/utils/Move.js"; -export default class HexRules extends ChessRules { +export default class HexRules extends AbstractClickFillRules { static get Options() { return { @@ -32,10 +32,12 @@ export default class HexRules extends ChessRules { get hasReserve() { return false; } - get noAnimate() { return true; } + get clickOnly() { + return true; + } doClick(coords) { if ( @@ -72,30 +74,30 @@ export default class HexRules extends ChessRules { return res; } - genRandInitFen() { + genRandInitBaseFen() { // NOTE: size.x == size.y (square boards) const emptyCount = C.FenEmptySquares(this.size.x); - return (emptyCount + "/").repeat(this.size.x).slice(0, -1) + " w 0"; + return { + fen: (emptyCount + "/").repeat(this.size.x).slice(0, -1) + " w 0", + o: {} + }; } - // TODO: enable vertical board (rotate?) getSvgChessboard() { // NOTE: with small margin seems nicer let width = 173.2 * this.size.y + 173.2 * (this.size.y-1) / 2 + 30, height = 50 + Math.floor(150 * this.size.x) + 30, min_x = -86.6 - 15, min_y = -100 - 15; -// if (this.size.ratio < 1) { -// [width, height] = [height, width]; -// [min_x, min_y] = [min_y, min_x]; -// } + if (this.size.ratio < 1) { + // Rotate by 30 degrees to display vertically + [width, height] = [height, width]; + [min_x, min_y] = [min_y, min_x]; + } let board = ` + class="chessboard_SVG"> `; - board += ""; + board += "`; } } - board += ``; + board += ` { - if (e.touches && e.touches.length > 1) - e.preventDefault(); - const cd = this.idToCoords(e.target.id); - if (cd) { - const move = this.doClick(cd); - if (move) - this.playPlusVisual(move); - } - }; - - if ('onmousedown' in window) { - document.addEventListener("mousedown", mousedown); - document.addEventListener("wheel", - (e) => this.rescale(e.deltaY < 0 ? "up" : "down")); - } - if ('ontouchstart' in window) - document.addEventListener("touchstart", mousedown, {passive: false}); - } - - // TODO: enable rotation get size() { - const baseRatio = 1.619191; // 2801.2 / 1730, "widescreen" - const rotate = false; //window.innerWidth < window.innerHeight; //"vertical screen" + const baseRatio = 1.6191907514450865; //2801.2 / 1730, "widescreen" + const rc = + document.getElementById(this.containerId).getBoundingClientRect(); + const rotate = rc.width < rc.height; //"vertical screen" return { x: this.options["bsize"], y: this.options["bsize"], @@ -197,7 +171,7 @@ export default class HexRules extends ChessRules { this.turn = C.GetOppCol(this.turn); } - getCurrentScore(move) { + getCurrentScore() { const oppCol = C.GetOppCol(this.turn); // Search for connecting path of opp color: let explored = {}, component; @@ -241,15 +215,4 @@ export default class HexRules extends ChessRules { return "*"; } - playVisual(move) { - move.vanish.forEach(v => { - let elt = document.getElementById(this.coordsToId({x: v.x, y: v.y})); - elt.classList.remove("bg-" + (v.c == 'w' ? "white" : "black")); - }); - move.appear.forEach(a => { - let elt = document.getElementById(this.coordsToId({x: a.x, y: a.y})); - elt.classList.add("bg-" + (a.c == 'w' ? "white" : "black")); - }); - } - };