ISSUE-031 - Progress checkpoint.

A lot of work going on here.
* Moved WorkspaceControls component to a new sub directory
* Renamed overlay images
* Started a static ChyronDriverBasic component (using Hamilton as an example)
* Created a fancy DriverNumber rendering system
* Defined DriverNumber style for Mercedes and no one else yet
* A bunch of new states for the grid: cars, drivers, teams, etc
* Defined a bunch of data for the drivers and teams
* Created another string utility function to generate repeat strings; unit tests included
This commit is contained in:
Kyle Geib committed 2022-01-21 14:14:45 -05:00
1 parent 1c38137480
commit db14bf902f
21 files changed
+787 -41

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
import { drivers, teams, teamNumberStyles, NumberStyle } from "../domain/data/teams";
import { Driver, DriverId, Team, TeamId } from "../types/state";
/**
* Prefer getting data from teams.ts through these simple getter functions.
* Why? Because we cannot use type literals (such as TeamId) as keys in an
* object in TypeScript. This allows me to enforce some type checking in a
* situation I wouldn't be able to normally
*/
export function getDriver(driverId: DriverId): Driver {
return drivers[driverId];
}
export function getTeam(teamId: TeamId): Team {
return teams[teamId];
}
export function getTeamNumberStyle(teamId: TeamId): NumberStyle {
return teamNumberStyles[teamId];
}
+49 -2
View File
@@ -1,4 +1,4 @@
import { findPrefixCount } from "./strings";
import { findPrefixCount, repeater } from "./strings";
describe("strings", () => {
describe("findPrefixCount", () => {
@@ -41,7 +41,7 @@ describe("strings", () => {
"Hello",
], true)).toBe(1);
});
it("is correctly case-insensitive", () => {
it("is case-insensitive", () => {
expect(findPrefixCount([
"Hello",
"HELLO",
@@ -50,4 +50,51 @@ describe("strings", () => {
});
});
});
describe("repeater", () => {
describe("repeats correctly", () => {
it("repeats 1 time", () => {
expect(repeater(
"A",
1,
",",
)).toBe("A");
});
it("repeats 3 times", () => {
expect(repeater(
"A",
3,
",",
)).toBe("A,A,A");
});
it("correctly handles 0", () => {
expect(repeater(
"A",
0,
",",
)).toBe("");
});
it("correctly handles -1", () => {
expect(repeater(
"A",
-1,
",",
)).toBe("");
});
it("correctly handles blank delimiter", () => {
expect(repeater(
"A",
3,
"",
)).toBe("AAA");
});
it("correctly handles different delimiter", () => {
expect(repeater(
"A",
3,
" + ",
)).toBe("A + A + A");
});
});
});
});
+19
View File
@@ -23,3 +23,22 @@ export function findPrefixCount(strings: Array<string>, caseSensitive = true): n
}
return maskLength;
}
/**
* Basic function repeats the given string a set number of times and allows for
* a delimiter.
* @param value the string to repeat
* @param count the number of times to repeat
* @param delimiter the string to place between repeated strings
* @returns
*/
export function repeater(value: string, count: number, delimiter = ", "): string {
let output = "";
for (let x = 0; x < count; ++x) {
output += value;
if (delimiter.length !== 0 && x < count - 1) {
output += delimiter;
}
}
return output;
}