Compare commits

...

2 commits

Author SHA1 Message Date
Manuel Thalmann 191ae2113c Add style for disabled button
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-12-23 16:37:24 +01:00
Manuel Thalmann 7ba310c7ca Execute the publish task only on the main branch 2022-12-23 16:14:16 +01:00
4 changed files with 32 additions and 3 deletions

View file

@ -25,3 +25,5 @@ pipeline:
github_sshkey github_sshkey
target_branch: gh-pages target_branch: gh-pages
pages_directory: ./lib/static pages_directory: ./lib/static
when:
branch: main

View file

@ -94,7 +94,7 @@ export function App()
`Player ${Constants.PLAYER_NAMES[game.winner]} wins!` : `Player ${Constants.PLAYER_NAMES[game.winner]} wins!` :
`It's player "${Constants.PLAYER_NAMES[game.currentPlayer]}"s turn` `It's player "${Constants.PLAYER_NAMES[game.currentPlayer]}"s turn`
], ],
[MenuBar] [MenuBar, { game }]
]; ];
} }
@ -153,10 +153,13 @@ export function Field({ field })
/** /**
* Renders a menu bar. * Renders a menu bar.
* *
* @param {{ game: Game }} game
* The game to represent.
*
* @returns {NodeDescriptor} * @returns {NodeDescriptor}
* The rendered element. * The rendered element.
*/ */
export function MenuBar() export function MenuBar({ game })
{ {
return [ return [
"div", "div",
@ -164,7 +167,18 @@ export function MenuBar()
[Button, { content: ["New Game", { className: newGameClass }] }], [Button, { content: ["New Game", { className: newGameClass }] }],
[Button, { content: ["Save Game", { className: saveGameClass }] }], [Button, { content: ["Save Game", { className: saveGameClass }] }],
[Button, { content: ["Load Game", { className: loadGameClass }] }], [Button, { content: ["Load Game", { className: loadGameClass }] }],
[Button, { content: ["Undo Last Move", { className: undoClass }] }] [
Button,
{
content: [
"Undo Last Move",
{
className: undoClass,
...(game.undoStackCount > 0 ? {} : { disabled: true })
}
]
}
]
]; ];
} }

View file

@ -68,6 +68,14 @@ export class Game
return this.state.turnCount % 2 === 0 ? "r" : "b"; return this.state.turnCount % 2 === 0 ? "r" : "b";
} }
/**
* Gets the number of entries in the undo stack.
*/
get undoStackCount()
{
return this.#previousStates.length;
}
/** /**
* Gets the id of the player that is winning. * Gets the id of the player that is winning.
* *

View file

@ -19,6 +19,11 @@ button:active {
background-color: rgb(96, 190, 221); background-color: rgb(96, 190, 221);
} }
button:disabled {
background-color: whitesmoke;
border-color: lightgray;
}
div { div {
box-sizing: border-box; box-sizing: border-box;
} }