import { store } from "@/store";
export default {
name: "my-board",
- // Last move cannot be guessed from here, and is required to highlight squares
+ // Last move cannot be guessed from here, and is required for highlights.
// vr: object to check moves, print board...
// userColor is left undefined for an external observer
props: [
this.settings.highlight &&
["all","highlight"].includes(V.ShowMoves)
);
+ const showCheck = (
+ this.settings.highlight &&
+ ["all","highlight","byrow"].includes(V.ShowMoves)
+ );
const orientation = !V.CanFlip ? "w" : this.orientation;
// Ensure that squares colors do not change when board is flipped
const lightSquareMod = (sizeX + sizeY) % 2;
const gameDiv = h(
"div",
{
- class: {
+ "class": {
game: true,
clearer: true
}
return h(
"div",
{
- class: {
+ "class": {
row: true
},
style: { opacity: this.choices.length > 0 ? "0.5" : "1" }
if (showPiece(ci, cj)) {
elems.push(
h("img", {
- class: {
+ "class": {
piece: true,
ghost:
!!this.selectedPiece &&
if (this.settings.hints && hintSquares[ci][cj]) {
elems.push(
h("img", {
- class: {
+ "class": {
"mark-square": true
},
attrs: {
return h(
"div",
{
- class: {
+ "class": {
board: true,
["board" + sizeY]: true,
"light-square": lightSquare,
"in-shadow": inShadow(ci, cj),
"highlight-light": inHighlight(ci, cj) && lightSquare,
"highlight-dark": inHighlight(ci, cj) && !lightSquare,
- "incheck-light": showLight && lightSquare && incheckSq[ci][cj],
- "incheck-dark": showLight && !lightSquare && incheckSq[ci][cj]
+ "incheck-light":
+ showCheck && lightSquare && incheckSq[ci][cj],
+ "incheck-dark":
+ showCheck && !lightSquare && incheckSq[ci][cj]
},
attrs: {
id: getSquareId({ x: ci, y: cj })
h(
"div",
{
- class: { board: true, ["board" + sizeY]: true },
+ "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 },
+ "class": { piece: true, reserve: true },
attrs: {
src:
"/images/pieces/" +
".svg"
}
}),
- h("sup", { class: { "reserve-count": true } }, [ qty ])
+ h("sup", { "class": { "reserve-count": true } }, [ qty ])
]
)
);
h(
"div",
{
- class: { board: true, ["board" + sizeY]: true },
+ "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 },
+ "class": { piece: true, reserve: true },
attrs: {
src:
"/images/pieces/" +
".svg"
}
}),
- h("sup", { class: { "reserve-count": true } }, [ qty ])
+ h("sup", { "class": { "reserve-count": true } }, [ qty ])
]
)
);
h(
"div",
{
- class: {
+ "class": {
game: true,
"reserve-div": true
},
h(
"div",
{
- class: {
+ "class": {
row: true,
"reserve-row": true
}
h(
"div",
{
- class: {
+ "class": {
game: true,
"reserve-div": true
},
h(
"div",
{
- class: {
+ "class": {
row: true,
"reserve-row": true
}
"div",
{
attrs: { id: "choices" },
- class: { row: true },
+ "class": { row: true },
style: {
top: topOffset + "px",
left:
},
[ h(
"div",
- { },
+ {
+ "class": { "full-width": true }
+ },
this.choices.map(m => {
// A "choice" is a move
const applyMove = (e) => {
// Force a delay between move is shown and clicked
// (otherwise a "double-click" bug might occur)
if (Date.now() - this.clickTime < 200) return;
- this.play(m);
this.choices = [];
+ this.play(m);
};
const onClick =
this.mobileBrowser
return h(
"div",
{
- class: {
+ "class": {
board: true,
["board" + sizeY]: true
},
attrs: {
src:
"/images/pieces/" +
- this.vr.getPPpath(
- m.appear[0].c + m.appear[0].p,
- // Extra arg useful for some variants:
- this.orientation) +
+ // orientation: extra arg useful for some variants:
+ this.vr.getPPpath(m, this.orientation) +
V.IMAGE_EXTENSION
},
- class: { "choice-piece": true },
+ "class": { "choice-piece": true },
on: onClick
})
]
mousedown: function(e) {
e.preventDefault();
if (!this.start) {
- // Start square must contain a piece.
// NOTE: classList[0] is enough: 'piece' is the first assigned class
- if (e.target.classList[0] != "piece") return;
+ const withPiece = e.target.classList[0] == "piece";
+ // Emit the click event which could be used by some variants
+ this.$emit(
+ "click-square",
+ getSquareFromId(withPiece ? e.target.parentNode.id : e.target.id)
+ );
+ // Start square must contain a piece.
+ if (!withPiece) return;
let parent = e.target.parentNode; //surrounding square
// Show possible moves if current player allowed to play
const startSquare = getSquareFromId(parent.id);
</script>
<style lang="sass" scoped>
+// NOTE: no variants with reserve of size != 8
.game.reserve-div
margin-bottom: 18px
-
.reserve-count
padding-left: 40%
-
.reserve-row
margin-bottom: 15px
-// NOTE: no variants with reserve of size != 8
+.full-width
+ width: 100%
.game
user-select: none