Simplify accessability of player names

This commit is contained in:
Manuel Thalmann 2022-12-08 15:07:50 +01:00
parent 480a77ff86
commit f36b60b2e4
No known key found for this signature in database
GPG key ID: 5FD9AD3CCDDBD27B
2 changed files with 9 additions and 5 deletions

View file

@ -5,9 +5,11 @@ export class Constants
{
/**
* The IDs of the players.
*
* @type {Partial<Record<CellOwner, string>>}
*/
static PLAYER_NAMES = [
"red",
"blue"
];
static PLAYER_NAMES = {
r: "red",
b: "blue"
};
}

View file

@ -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]}`
}));
}