From 7239c95f02ae59082d748be786fa3ac9cf0147fb Mon Sep 17 00:00:00 2001 From: Didictateur Date: Wed, 3 Dec 2025 23:48:03 +0100 Subject: [PATCH] =?UTF-8?q?n'affiche=20pas=20les=20mouvements=20faits=20pa?= =?UTF-8?q?r=20une=20pi=C3=A8ce=20invisible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/game.html | 106 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 84 insertions(+), 22 deletions(-) diff --git a/public/game.html b/public/game.html index d0e991a..b878852 100644 --- a/public/game.html +++ b/public/game.html @@ -404,14 +404,25 @@ logs... x && x.square === lm.to); + } + if (showDest && dest) { + dest.classList.add("last-move-dest"); + } + } catch (_) {} const fromEl = boardEl.querySelector(`.square[data-square="${lm.from}"]`); - if (fromEl) fromEl.classList.add("last-move-source"); + try { + let showSource = false; + if (currentBoardState && Array.isArray(currentBoardState.pieces)) { + showSource = currentBoardState.pieces.some((x) => x && x.square === lm.from); + } + if (showSource && fromEl) { + fromEl.classList.add("last-move-source"); + } + } catch (_) {} } } } @@ -736,9 +747,24 @@ logs... { try { log("recv move:moved", data && { from: data.from, to: data.to }); - // clear any local selection (move completed) before re-render + const prevBoardState = currentBoardState; + let hasPieceFromBefore = false; + let hasPieceToBefore = false; + try { + const fromBeforeEl = + boardEl && boardEl.querySelector && + boardEl.querySelector(`.square[data-square="${data && data.from}"]`); + if (fromBeforeEl && fromBeforeEl.querySelector && fromBeforeEl.querySelector('img.piece')) + hasPieceFromBefore = true; + } catch (_) {} + try { + const toBeforeEl = + boardEl && boardEl.querySelector && + boardEl.querySelector(`.square[data-square="${data && data.to}"]`); + if (toBeforeEl && toBeforeEl.querySelector && toBeforeEl.querySelector('img.piece')) + hasPieceToBefore = true; + } catch (_) {} clearSelection(false); - // remove any previous visual markers (circle or highlight) everywhere try { const prevHighlights = boardEl.querySelectorAll(".last-move-dest, .last-move-source"); prevHighlights.forEach((el) => { @@ -755,23 +781,59 @@ logs... x && x.square === data.from); + } + } catch (_) { + showSource = false; } - // persist last move per room so a refresh can restore highlights - try { - if (roomId) { - const key = `cn:lastMove:${roomId}`; - localStorage.setItem(key, JSON.stringify({ from: data.from, to: data.to, ts: Date.now() })); - } - } catch (e) {} + if (!showSource) showSource = !!hasPieceFromBefore; + + let showDest = false; + try { + if (currentBoardState && Array.isArray(currentBoardState.pieces)) { + showDest = currentBoardState.pieces.some((x) => x && x.square === data.to); + } + } catch (_) { + showDest = false; + } + if (!showDest) showDest = !!hasPieceToBefore; + + try { + if (!showDest && dest && dest.querySelector && dest.querySelector('img.piece')) showDest = true; + } catch (_) {} + try { + if (!showSource && dest && dest.querySelector && dest.querySelector('img.piece')) showSource = true; + } catch (_) {} + + try { + if (showDest && dest) { + dest.classList.add("last-move-dest"); + const circle = document.createElement("div"); + circle.className = "last-move-circle"; + dest.appendChild(circle); + } + } catch (_) {} + try { + if (showSource && fromEl) { + fromEl.classList.add("last-move-source"); + const circle = document.createElement("div"); + circle.className = "last-move-circle"; + fromEl.appendChild(circle); + } + } catch (_) {} + + try { + if (roomId) { + const key = `cn:lastMove:${roomId}`; + localStorage.setItem(key, JSON.stringify({ from: data.from, to: data.to, ts: Date.now() })); + } + } catch (e) {} } } catch (_) {} } catch (e) {