Skip to content
Source
Sign inSign up
samwillis/one-million-boxes
Open History to see the last commit

teams.ts

63 lines1.2 KB

1/**
2 * Team names in order of team ID.
3 */
4export const TEAMS = [`RED`, `BLUE`, `GREEN`, `YELLOW`] as const
5​
6/**
7 * Type for team names.
8 */
9export type TeamName = (typeof TEAMS)[number]
10​
11/**
12 * Team colors with primary (stroke) and fill (box) variants.
13 */
14export const TEAM_COLORS = {
15 RED: {
16 primary: `#E53935`,
17 fill: `rgba(229, 57, 53, 0.5)`,
18 },
19 BLUE: {
20 primary: `#1E88E5`,
21 fill: `rgba(30, 136, 229, 0.5)`,
22 },
23 GREEN: {
24 primary: `#43A047`,
25 fill: `rgba(67, 160, 71, 0.5)`,
26 },
27 YELLOW: {
28 primary: `#FDD835`,
29 fill: `rgba(253, 216, 53, 0.5)`,
30 },
31} as const
32​
33/**
34 * Convert a team ID (0-3) to a team name.
35 */
36export function teamIdToName(teamId: number): TeamName {
37 if (teamId < 0 || teamId >= TEAMS.length) {
38 throw new Error(`Invalid team ID: ${teamId}`)
39 }
40 return TEAMS[teamId]
42​
43/**
44 * Convert a team name to a team ID (0-3).
45 */
46export function teamNameToId(name: TeamName): number {
47 const id = TEAMS.indexOf(name)
48 if (id === -1) {
49 throw new Error(`Invalid team name: ${name}`)
50 }
51 return id
53​
54/**
55 * Get the colors for a team by ID.
56 */
57export function getTeamColor(teamId: number): {
58 primary: string
59 fill: string
60} {
61 const name = teamIdToName(teamId)
62 return TEAM_COLORS[name]