Skip to content

Commit

Permalink
feat: animations for player bars
Browse files Browse the repository at this point in the history
  • Loading branch information
kacperwyczawski committed Aug 19, 2024
1 parent 8ba687b commit b4ae03a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
21 changes: 20 additions & 1 deletion play.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ span.no-touch {
}
}

@keyframes blink {
0% {
opacity: 1;
}

50% {
opacity: 0;
}

100% {
opacity: 1;
}
}

#white,
#black {
position: absolute;
Expand All @@ -115,6 +129,11 @@ span.no-touch {

&.active .name {
text-decoration: underline;
animation: blink .2s;
}

& span {
display: inline-block;
}
}

Expand Down Expand Up @@ -343,4 +362,4 @@ a.button {
& p {
margin-top: 0;
}
}
}
25 changes: 17 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,24 @@ function allTableCells() {
return [...table.rows].flatMap((row) => [...row.cells]);
}

function updateValue(element: HTMLElement, newValue: string) {
if (newValue !== element.textContent) {
element.textContent = newValue
element.animate([
{ opacity: 1 },
{ opacity: 0 },
{ opacity: 1 }
], {
duration: 200,
});
}
}

function renderGame() {
q(`#${game.previousPlayer.color} .pieces`).textContent =
game.previousPlayer.pieces.toString();
q(`#${game.previousPlayer.color} .gold`).textContent =
game.previousPlayer.gold.toString();
q(`#${game.previousPlayer.color} .gold-per-turn`).textContent =
game.previousPlayer.goldPerTurn.toString();
q(`#${game.previousPlayer.color} .max-pieces`).textContent =
game.previousPlayer.maxPieces.toString();
updateValue(q(`#${game.previousPlayer.color} .pieces`), game.previousPlayer.pieces.toString());
updateValue(q(`#${game.previousPlayer.color} .gold`), game.previousPlayer.gold.toString());
updateValue(q(`#${game.previousPlayer.color} .gold-per-turn`), game.previousPlayer.goldPerTurn.toString());
updateValue(q(`#${game.previousPlayer.color} .max-pieces`), game.previousPlayer.maxPieces.toString());

if (!firstRender) {
q("#player-buttons").classList.toggle("white");
Expand Down

0 comments on commit b4ae03a

Please sign in to comment.