projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Some fixes
[vchess.git]
/
client
/
src
/
components
/
Board.vue
diff --git
a/client/src/components/Board.vue
b/client/src/components/Board.vue
index
ff50b12
..
914b3c3
100644
(file)
--- a/
client/src/components/Board.vue
+++ b/
client/src/components/Board.vue
@@
-1,6
+1,4
@@
<script>
<script>
-// TODO: for 3 or 4 players, write a "board3.js" (board4.js)
-
import { getSquareId, getSquareFromId } from "@/utils/squareId";
import { ArrayFun } from "@/utils/array";
import { getSquareId, getSquareFromId } from "@/utils/squareId";
import { ArrayFun } from "@/utils/array";
@@
-8,7
+6,7
@@
export default {
name: 'my-board',
// Last move cannot be guessed from here, and is required to highlight squares
// vr: object to check moves, print board...
name: 'my-board',
// Last move cannot be guessed from here, and is required to highlight squares
// vr: object to check moves, print board...
- // userColor
: for mode HH or HC
+ // userColor
is left undefined for an external observer
props: ["vr","lastMove","analyze","orientation","userColor","vname"],
data: function () {
return {
props: ["vr","lastMove","analyze","orientation","userColor","vname"],
data: function () {
return {
@@
-31,15
+29,19
@@
export default {
// Also precompute in-check squares
let incheckSq = ArrayFun.init(sizeX, sizeY, false);
this.incheck.forEach(sq => { incheckSq[sq[0]][sq[1]] = true; });
// Also precompute in-check squares
let incheckSq = ArrayFun.init(sizeX, sizeY, false);
this.incheck.forEach(sq => { incheckSq[sq[0]][sq[1]] = true; });
- const squareWidth = 40; //TODO: compute this
+
+ let firstRow = document.querySelector(".game > .row");
+ const squareWidth = (!!firstRow
+ ? document.querySelector(".game > .row").offsetWidth / sizeY
+ : 40); //arbitrary value (not relevant)
const choices = h(
'div',
{
attrs: { "id": "choices" },
'class': { 'row': true },
style: {
const choices = h(
'div',
{
attrs: { "id": "choices" },
'class': { 'row': true },
style: {
- "display":
this.choices.length>0?"block":"none"
,
- "top":
"-" +
((sizeY/2)*squareWidth+squareWidth/2) + "px",
+ "display":
(this.choices.length > 0 ? "block" : "none")
,
+ "top": ((sizeY/2)*squareWidth+squareWidth/2) + "px",
"width": (this.choices.length * squareWidth) + "px",
"height": squareWidth + "px",
},
"width": (this.choices.length * squareWidth) + "px",
"height": squareWidth + "px",
},
@@
-96,8
+98,8
@@
export default {
let cj = (this.orientation=='w' ? j : sizeY-j-1);
let elems = [];
if (this.vr.board[ci][cj] != V.EMPTY && (this.vname!="Dark"
let cj = (this.orientation=='w' ? j : sizeY-j-1);
let elems = [];
if (this.vr.board[ci][cj] != V.EMPTY && (this.vname!="Dark"
- || this.
gameOver || this.analyze
-
|| this.vr.enlightened[this.userColor][ci][cj]
))
+ || this.
analyze || (!!this.userColor
+
&& this.vr.enlightened[this.userColor][ci][cj])
))
{
elems.push(
h(
{
elems.push(
h(
@@
-141,8
+143,9
@@
export default {
'light-square': (i+j)%2==0,
'dark-square': (i+j)%2==1,
[this.bcolor]: true,
'light-square': (i+j)%2==0,
'dark-square': (i+j)%2==1,
[this.bcolor]: true,
- 'in-shadow': this.vname=="Dark" && !this.gameOver
- && !this.analyze && !this.vr.enlightened[this.userColor][ci][cj],
+ 'in-shadow': this.vname=="Dark" && !this.analyze
+ && (!this.userColor
+ || !this.vr.enlightened[this.userColor][ci][cj]),
'highlight': showLight && !!lm && lm.end.x == ci && lm.end.y == cj,
'incheck': showLight && incheckSq[ci][cj],
},
'highlight': showLight && !!lm && lm.end.x == ci && lm.end.y == cj,
'incheck': showLight && incheckSq[ci][cj],
},
@@
-156,10
+159,11
@@
export default {
);
})
);
);
})
);
+ const playingColor = this.userColor || "w"; //default for an observer
let elementArray = [choices, gameDiv];
if (!!this.vr.reserve)
{
let elementArray = [choices, gameDiv];
if (!!this.vr.reserve)
{
- const shiftIdx = (
this.user
Color=="w" ? 0 : 1);
+ const shiftIdx = (
playing
Color=="w" ? 0 : 1);
let myReservePiecesArray = [];
for (let i=0; i<V.RESERVE_PIECES.length; i++)
{
let myReservePiecesArray = [];
for (let i=0; i<V.RESERVE_PIECES.length; i++)
{
@@
-174,17
+178,17
@@
export default {
'class': {"piece":true, "reserve":true},
attrs: {
"src": "/images/pieces/" +
'class': {"piece":true, "reserve":true},
attrs: {
"src": "/images/pieces/" +
- this.vr.getReservePpath(
this.user
Color,i) + ".svg",
+ this.vr.getReservePpath(
playing
Color,i) + ".svg",
}
}),
h('sup',
{"class": { "reserve-count": true } },
}
}),
h('sup',
{"class": { "reserve-count": true } },
- [ this.vr.reserve[
this.user
Color][V.RESERVE_PIECES[i]] ]
+ [ this.vr.reserve[
playing
Color][V.RESERVE_PIECES[i]] ]
)
]));
}
let oppReservePiecesArray = [];
)
]));
}
let oppReservePiecesArray = [];
- const oppCol = V.GetOppCol(
this.user
Color);
+ const oppCol = V.GetOppCol(
playing
Color);
for (let i=0; i<V.RESERVE_PIECES.length; i++)
{
oppReservePiecesArray.push(h('div',
for (let i=0; i<V.RESERVE_PIECES.length; i++)
{
oppReservePiecesArray.push(h('div',
@@
-235,13
+239,6
@@
export default {
return h(
'div',
{
return h(
'div',
{
- 'class': {
- "col-sm-12": true,
- "col-md-10": true,
- "col-md-offset-1": true,
- "col-lg-8": true,
- "col-lg-offset-2": true,
- },
// NOTE: click = mousedown + mouseup
on: {
mousedown: this.mousedown,
// NOTE: click = mousedown + mouseup
on: {
mousedown: this.mousedown,
@@
-288,7
+285,7
@@
export default {
this.selectedPiece.style.zIndex = 3000;
const startSquare = getSquareFromId(e.target.parentNode.id);
this.possibleMoves = [];
this.selectedPiece.style.zIndex = 3000;
const startSquare = getSquareFromId(e.target.parentNode.id);
this.possibleMoves = [];
- const color = (this.analyze
|| this.gameOver
? this.vr.turn : this.userColor);
+ const color = (this.analyze ? this.vr.turn : this.userColor);
if (this.vr.canIplay(color,startSquare))
this.possibleMoves = this.vr.getPossibleMovesFrom(startSquare);
// Next line add moving piece just after current image
if (this.vr.canIplay(color,startSquare))
this.possibleMoves = this.vr.getPossibleMovesFrom(startSquare);
// Next line add moving piece just after current image
@@
-368,6
+365,8
@@
export default {
.reserve-row-1
margin-bottom: 15px
.reserve-row-1
margin-bottom: 15px
+// NOTE: no variants with reserve of size != 8
+
div.board
float: left
height: 0
div.board
float: left
height: 0
@@
-386,10
+385,8
@@
div.board11
width: 9.09%
padding-bottom: 9.1%
width: 9.09%
padding-bottom: 9.1%
-// NOTE: no variants with reserve of size != 8
-
.game
.game
- width:
80vh
+ width:
#{'min(80vw, 500px)'}
margin: 0 auto
.board
cursor: pointer
margin: 0 auto
.board
cursor: pointer