clean click event
This commit is contained in:
parent
758c4f4675
commit
1571094ed5
3 changed files with 7 additions and 38 deletions
|
|
@ -90,26 +90,9 @@ function renderBoardFromState(state, asWhite = null) {
|
|||
|
||||
cell.appendChild(piece);
|
||||
boardEl.appendChild(cell);
|
||||
// click to select/move
|
||||
// clicks on cells should do absolutely nothing (display-only mode)
|
||||
cell.addEventListener('click', () => {
|
||||
// if no game/socket, ignore
|
||||
if (!currentGameId) return;
|
||||
const x = parseInt(cell.dataset.x, 10);
|
||||
const y = parseInt(cell.dataset.y, 10);
|
||||
if (!selected) {
|
||||
selected = { x, y };
|
||||
cell.classList.add('selected');
|
||||
setMeta('Selected ' + x + ',' + y);
|
||||
} else {
|
||||
// send move
|
||||
const from = selected;
|
||||
const to = { x, y };
|
||||
selected = null;
|
||||
// clear previously selected class
|
||||
document.querySelectorAll('.cell.selected').forEach(el => el.classList.remove('selected'));
|
||||
setMeta('Sending move ' + from.x + ',' + from.y + ' -> ' + to.x + ',' + to.y);
|
||||
if (socket && myPlayerId && currentGameId) socket.emit('move', { gameId: currentGameId, playerId: myPlayerId, from, to });
|
||||
}
|
||||
// intentionally empty - no selection, no move, no UI changes
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,26 +60,9 @@ function renderBoardFromState(state) {
|
|||
|
||||
cell.appendChild(piece);
|
||||
boardEl.appendChild(cell);
|
||||
// click to select/move
|
||||
// clicks on cells should do absolutely nothing (display-only mode)
|
||||
cell.addEventListener('click', () => {
|
||||
// if no game/socket, ignore
|
||||
if (!currentGameId) return;
|
||||
const x = parseInt(cell.dataset.x, 10);
|
||||
const y = parseInt(cell.dataset.y, 10);
|
||||
if (!selected) {
|
||||
selected = { x, y };
|
||||
cell.classList.add('selected');
|
||||
setMeta('Selected ' + x + ',' + y);
|
||||
} else {
|
||||
// send move
|
||||
const from = selected;
|
||||
const to = { x, y };
|
||||
selected = null;
|
||||
// clear previously selected class
|
||||
document.querySelectorAll('.cell.selected').forEach(el => el.classList.remove('selected'));
|
||||
setMeta('Sending move ' + from.x + ',' + from.y + ' -> ' + to.x + ',' + to.y);
|
||||
if (socket && myPlayerId && currentGameId) socket.emit('move', { gameId: currentGameId, playerId: myPlayerId, from, to });
|
||||
}
|
||||
// intentionally empty — do not select, do not emit moves, do not change UI
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,3 +19,6 @@ main{padding:16px}
|
|||
.piece{width:48px;height:48px}
|
||||
.game-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}
|
||||
.controls button{margin-left:8px}
|
||||
|
||||
/* Ensure selected cells have no visual effect (display-only mode) */
|
||||
.cell.selected{outline: none !important; box-shadow: none !important; border-color: inherit !important; background: inherit !important}
|
||||
|
|
|
|||
Loading…
Reference in a new issue