From f36b60b2e42c404f03b25065c0c53cd1c823e29f Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 8 Dec 2022 15:07:50 +0100 Subject: [PATCH] Simplify accessability of player names --- src/js/Constants.js | 10 ++++++---- src/js/board.js | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/js/Constants.js b/src/js/Constants.js index fbf90ec..d2681e9 100644 --- a/src/js/Constants.js +++ b/src/js/Constants.js @@ -5,9 +5,11 @@ export class Constants { /** * The IDs of the players. + * + * @type {Partial>} */ - static PLAYER_NAMES = [ - "red", - "blue" - ]; + static PLAYER_NAMES = { + r: "red", + b: "blue" + }; } diff --git a/src/js/board.js b/src/js/board.js index c8dec59..83e5db0 100644 --- a/src/js/board.js +++ b/src/js/board.js @@ -1,3 +1,4 @@ +import { Constants } from "./Constants.js"; import { elt } from "./elt.js"; import { State } from "./State.js"; @@ -10,6 +11,7 @@ import { State } from "./State.js"; export function initializeBoard(id) { let board = document.getElementById(id); + board.innerHTML = ""; for (let i = 0; i < 6; i++) { @@ -24,7 +26,7 @@ export function initializeBoard(id) children.push(elt( "div", { - class: `piece ${playerId === "r" ? "red" : "blue"}` + class: `piece ${Constants.PLAYER_NAMES[playerId]}` })); }