X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=base_rules.js;h=dac7bb4f91f6b5c9e208a6c748ff47fe407f5263;hb=8f57fbf250093488064401d503f1c621b122e95a;hp=0d7b703f2de907ad08f7aff0af360f5c4d5d279f;hpb=f77da909dea9da0992a23a92b48d8f08703b4f72;p=xogo.git diff --git a/base_rules.js b/base_rules.js index 0d7b703..dac7bb4 100644 --- a/base_rules.js +++ b/base_rules.js @@ -29,16 +29,18 @@ export default class ChessRules { {label: "Asymmetric random", value: 2} ] }], - check: [ + input: [ { label: "Capture king", - defaut: false, - variable: "taking" + variable: "taking", + type: "checkbox", + defaut: false }, { label: "Falling pawn", - defaut: false, - variable: "pawnfall" + variable: "pawnfall", + type: "checkbox", + defaut: false } ], // Game modifiers (using "elementary variants"). Default: false @@ -173,8 +175,6 @@ export default class ChessRules { // Setup the initial random-or-not (asymmetric-or-not) position genRandInitFen(seed) { - Random.setSeed(seed); - let fen, flags = "0707"; if (!this.options.randomness) // Deterministic: @@ -182,7 +182,8 @@ export default class ChessRules { else { // Randomize - let pieces = { w: new Array(8), b: new Array(8) }; + Random.setSeed(seed); + let pieces = {w: new Array(8), b: new Array(8)}; flags = ""; // Shuffle pieces on first (and last rank if randomness == 2) for (let c of ["w", "b"]) { @@ -370,13 +371,16 @@ export default class ChessRules { ////////////////// // INITIALIZATION - constructor(o) { + constructor(o, genFenOnly) { this.options = o.options; // Fill missing options (always the case if random challenge) (V.Options.select || []).concat(V.Options.input || []).forEach(opt => { if (this.options[opt.variable] === undefined) this.options[opt.variable] = opt.defaut; }); + if (genFenOnly) + // This object will be used only for initial FEN generation + return; this.playerColor = o.color; this.afterPlay = o.afterPlay; //trigger some actions after playing a move @@ -943,11 +947,6 @@ export default class ChessRules { }; const mouseup = (e) => { - const newR = chessboard.getBoundingClientRect(); - if (newR.width != r.width || newR.height != r.height) { - this.rescale(); - return; - } if (!start) return; const [x, y] = [start.x, start.y]; @@ -972,15 +971,12 @@ export default class ChessRules { curPiece.remove(); }; - const wheelResize = (e) => { - this.rescale(e.deltaY < 0 ? "up" : "down"); - }; - if ('onmousedown' in window) { document.addEventListener("mousedown", mousedown); document.addEventListener("mousemove", mousemove); document.addEventListener("mouseup", mouseup); - document.addEventListener("wheel", wheelResize); + document.addEventListener("wheel", + (e) => this.rescale(e.deltaY < 0 ? "up" : "down")); } if ('ontouchstart' in window) { // https://stackoverflow.com/a/42509310/12660887