Skip to content

Commit

Permalink
feat: change cursor when moving over piece to grab
Browse files Browse the repository at this point in the history
  • Loading branch information
kacperwyczawski committed Jun 22, 2024
1 parent c5c51c4 commit 8aa3267
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class Board {
targetCell.onClick = () => {
// place piece
if (this.#selectedCell && this.#selectedCell.piece) {
HTMLTable.classList.remove("piece-in-hand");
if (targetCell.piece) {
this.nextPlayer.removePiece();
}
Expand All @@ -48,6 +49,7 @@ export class Board {

// grab piece
if (targetCell.piece && targetCell.playerColor === this.currentPlayer.color) {
HTMLTable.classList.add("piece-in-hand");
this.#selectedCell = targetCell;
targetCell.toggleSelected();
return;
Expand Down
2 changes: 2 additions & 0 deletions src/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ export class Cell {
this.#playerColor = piece.color;
this.#HTMLCell.style.backgroundImage = `url('${piece.toString()}-${piece.color}.png')`;
this.#HTMLCell.style.setProperty("--outline", `var(--player-${piece.color})`);
this.#HTMLCell.classList.add("piece-to-move")
}

removePiece() {
this.#HTMLCell.style.backgroundImage = "";
this.#piece = null;
this.#HTMLCell.classList.remove("piece-to-move");
}

toggleSelected() {
Expand Down
6 changes: 4 additions & 2 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* TODO: change cursors */

@import '@fontsource/ibm-plex-mono';

* {
Expand Down Expand Up @@ -66,6 +64,10 @@ main {
border: .3rem dashed var(--border);
outline: .3rem solid var(--outline); /* --outline is injected using JavaScript */
}

&.piece-to-move {
cursor: grab;
}
}

tr:nth-child(odd) td:nth-child(even),
Expand Down

0 comments on commit 8aa3267

Please sign in to comment.