Skip to content

Commit

Permalink
Some baseball
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmatter committed Nov 29, 2023
1 parent 8a80bea commit 591286e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 34 deletions.
5 changes: 2 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
better play by play log
- test other sports
- baseball
- pitch events logo
- showScore in LiveGame
- textOnly
- bold = false
- output.bold
- does this UI make sense?
- benchmark
- make text JSX, get rid of any processing in LiveGame
- test performance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ export const getText = (
getName: (pid: number) => string,
) => {
let text;
let t: 0 | 1 | undefined;
let textOnly = false;

let bold = false;

Expand Down Expand Up @@ -463,7 +461,8 @@ const processLiveGameEvents = ({
}
let stop = false;
let text;
let bold = false;
let t: 0 | 1 | undefined;
let textOnly = false;

while (!stop && events.length > 0) {
const e = events.shift();
Expand Down Expand Up @@ -564,21 +563,24 @@ const processLiveGameEvents = ({
}

const output = getText(e, getName);
text = output.text;
text = output.bold ? <b>{output.text}</b> : output.text;
t = actualT;
bold = output.bold;
textOnly =
e.type === "sideStart" ||
e.type === "sideOver" ||
e.type === "gameOver";

stop = true;
}
}

return {
bold,
overtimes,
quarters,
sportState,
t,
text,
textOnly,
};
};

Expand Down
33 changes: 8 additions & 25 deletions src/ui/views/LiveGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export const LiveGame = (props: View<"liveGame">) => {
sportState.current = output.sportState;

if (text !== undefined) {
if (isSport("baseball")) {
/*if (isSport("baseball")) {
if (showOuts) {
let endWithPeriod = true;
if (!text.endsWith("!") && !text.endsWith(".")) {
Expand All @@ -286,31 +286,9 @@ export const LiveGame = (props: View<"liveGame">) => {
endWithPeriod ? "." : ""
}`;
}

if (isSport("baseball") && showScore) {
if (!text.endsWith("!") && !text.endsWith(".")) {
text += ",";
}

const tied =
boxScore.current.teams[0].pts === boxScore.current.teams[1].pts;
const leader =
boxScore.current.teams[0].pts > boxScore.current.teams[1].pts
? 0
: 1;
const other = leader === 0 ? 1 : 0;

if (tied) {
text += " The game is tied ";
} else {
text += ` ${boxScore.current.teams[leader].abbrev} leads `;
}

text += `${boxScore.current.teams[leader].pts}-${boxScore.current.teams[other].pts}.`;
}
}
/*const p = document.createElement("p");
const p = document.createElement("p");
if (isSport("football") && text.startsWith("Penalty")) {
p.innerHTML = text
.replace("accepted", "<b>accepted</b>")
Expand Down Expand Up @@ -359,7 +337,12 @@ export const LiveGame = (props: View<"liveGame">) => {
t: output.t,
text,
textOnly: output.textOnly,
time: isSport("football") ? undefined : boxScore.current.time,

// Baseball has no time, football it's displayed with down/distance before play. In both cases, skip showing time for individual entries.
time:
isSport("football") || isSport("baseball")
? undefined
: boxScore.current.time,
});
}

Expand Down

0 comments on commit 591286e

Please sign in to comment.