+ if (!!this.vr.reserve) {
+ const playingColor = this.userColor || "w"; //default for an observer
+ const shiftIdx = playingColor == "w" ? 0 : 1;
+ let myReservePiecesArray = [];
+ for (let i = 0; i < V.RESERVE_PIECES.length; i++) {
+ const qty = this.vr.reserve[playingColor][V.RESERVE_PIECES[i]];
+ myReservePiecesArray.push(
+ h(
+ "div",
+ {
+ "class": { board: true, ["board" + sizeY]: true },
+ attrs: { id: getSquareId({ x: sizeX + shiftIdx, y: i }) },
+ style: { opacity: qty > 0 ? 1 : 0.35 }
+ },
+ [
+ h("img", {
+ "class": { piece: true, reserve: true },
+ attrs: {
+ src:
+ "/images/pieces/" +
+ this.vr.getReservePpath(i, playingColor) +
+ ".svg"
+ }
+ }),
+ h("sup", { "class": { "reserve-count": true } }, [ qty ])
+ ]
+ )
+ );
+ }
+ let oppReservePiecesArray = [];
+ const oppCol = V.GetOppCol(playingColor);
+ for (let i = 0; i < V.RESERVE_PIECES.length; i++) {
+ const qty = this.vr.reserve[oppCol][V.RESERVE_PIECES[i]];
+ oppReservePiecesArray.push(
+ h(
+ "div",
+ {
+ "class": { board: true, ["board" + sizeY]: true },
+ attrs: { id: getSquareId({ x: sizeX + (1 - shiftIdx), y: i }) },
+ style: { opacity: qty > 0 ? 1 : 0.35 }
+ },
+ [
+ h("img", {
+ "class": { piece: true, reserve: true },
+ attrs: {
+ src:
+ "/images/pieces/" +
+ this.vr.getReservePpath(i, oppCol) +
+ ".svg"
+ }
+ }),
+ h("sup", { "class": { "reserve-count": true } }, [ qty ])
+ ]
+ )
+ );
+ }
+ const myReserveTop = (
+ (playingColor == 'w' && orientation == 'b') ||
+ (playingColor == 'b' && orientation == 'w')
+ );
+ // Center reserves, assuming same number of pieces for each side:
+ const nbReservePieces = myReservePiecesArray.length;
+ const marginLeft = ((100 - nbReservePieces * (100 / sizeY)) / 2) + "%";
+ const reserveTop =
+ h(
+ "div",
+ {
+ "class": {
+ game: true,
+ "reserve-div": true
+ },
+ style: {
+ "margin-left": marginLeft
+ }
+ },
+ [
+ h(
+ "div",
+ {
+ "class": {
+ row: true,
+ "reserve-row": true
+ }
+ },
+ myReserveTop ? myReservePiecesArray : oppReservePiecesArray
+ )
+ ]
+ );
+ var reserveBottom =
+ h(
+ "div",
+ {
+ "class": {
+ game: true,
+ "reserve-div": true
+ },
+ style: {
+ "margin-left": marginLeft
+ }
+ },
+ [
+ h(
+ "div",
+ {
+ "class": {
+ row: true,
+ "reserve-row": true
+ }
+ },
+ myReserveTop ? oppReservePiecesArray : myReservePiecesArray
+ )
+ ]
+ );
+ elementArray.push(reserveTop);
+ }
+ elementArray.push(gameDiv);
+ if (!!this.vr.reserve) elementArray.push(reserveBottom);
+ const boardElt = document.querySelector(".game");
+ // boardElt might be undefine (at first drawing),
+ // but it won't be used in this case.
+ const squareWidth = (!!boardElt ? boardElt.offsetWidth / sizeY : 42);
+ if (this.choices.length > 0 && !!boardElt) {
+ // No choices to show at first drawing
+ const offset = [boardElt.offsetTop, boardElt.offsetLeft];
+ const maxNbeltsPerRow = Math.min(this.choices.length, sizeY);
+ let topOffset = offset[0] + (sizeY / 2) * squareWidth - squareWidth / 2;
+ let choicesHeight = squareWidth;
+ if (this.choices.length >= sizeY) {
+ // A second row is required (Eightpieces variant)
+ topOffset -= squareWidth / 2;
+ choicesHeight *= 2;
+ }