From 3300df38674fe6772b8fd92223b32e6fbc134932 Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Sat, 8 Dec 2018 03:06:14 +0100
Subject: [PATCH] Better squares highlighting

---
 public/javascripts/components/game.js | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js
index 11f99b01..a78f3231 100644
--- a/public/javascripts/components/game.js
+++ b/public/javascripts/components/game.js
@@ -202,17 +202,18 @@ Vue.component('my-game', {
 								);
 							}
 							const lm = this.vr.lastMove;
-							const highlight = !!lm && _.isMatch(lm.end, {x:ci,y:cj});
+							const showLight = !this.expert &&
+								(this.mode!="idle" || this.cursor==this.vr.moves.length);
 							return h(
 								'div',
 								{
 									'class': {
 										'board': true,
 										['board'+sizeY]: true,
-										'light-square': (i+j)%2==0 && (this.expert || !highlight),
-										'dark-square': (i+j)%2==1 && (this.expert || !highlight),
-										'highlight': !this.expert && highlight,
-										'incheck': !this.expert && incheckSq[ci][cj],
+										'light-square': (i+j)%2==0,
+										'dark-square': (i+j)%2==1,
+										'highlight': showLight && !!lm && _.isMatch(lm.end, {x:ci,y:cj}),
+										'incheck': showLight && incheckSq[ci][cj],
 									},
 									attrs: {
 										id: this.getSquareId({x:ci,y:cj}),
@@ -919,15 +920,20 @@ Vue.component('my-game', {
 				this.animateMove(move);
 				return;
 			}
-			this.incheck = this.vr.getCheckSquares(move); //is opponent in check?
 			// Not programmatic, or animation is over
 			if (this.mode == "human" && this.vr.turn == this.mycolor)
 				this.conn.send(JSON.stringify({code:"newmove", move:move, oppid:this.oppid}));
 			new Audio("/sounds/chessmove1.mp3").play().then(() => {}).catch(err => {});
 			if (this.mode != "idle")
+			{
+				this.incheck = this.vr.getCheckSquares(move); //is opponent in check?
 				this.vr.play(move, "ingame");
+			}
 			else
+			{
 				VariantRules.PlayOnBoard(this.vr.board, move);
+				this.$forceUpdate(); //TODO: ?!
+			}
 			if (this.mode == "human")
 				this.updateStorage(); //after our moves and opponent moves
 			if (this.mode != "idle")
@@ -943,6 +949,8 @@ Vue.component('my-game', {
 			// Navigate after game is over
 			if (this.cursor == 0)
 				return; //already at the beginning
+			if (this.cursor == this.vr.moves.length)
+				this.incheck = []; //in case of...
 			const move = this.vr.moves[--this.cursor];
 			VariantRules.UndoOnBoard(this.vr.board, move);
 			this.$forceUpdate(); //TODO: ?!
-- 
2.48.1