Skip to content

Commit

Permalink
isScoringPlay -> formatScoringSummaryEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmatter committed Apr 15, 2024
1 parent 58b9574 commit b145eef
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 30 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ indicator of if trade will be accepted
allow undoing a trade

shootouts
- isScoringPlay -> formatScoringSummaryEvent
- confirm for all sports
- check what fast-forward options are shown during shootout
- show shootout result somewhere
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import type {
PlayByPlayEvent,
PlayByPlayEventInputScore,
PlayByPlayEventScore,
} from "../worker/core/GameSim.football/PlayByPlayLogger";

export const isScoringPlay = (
export const formatScoringSummaryEvent = (
event: PlayByPlayEvent,
): event is PlayByPlayEventInputScore => {
return (
period: number,
): PlayByPlayEventScore | undefined => {
if (
(event as any).safety ||
(event as any).td ||
event.type === "extraPoint" ||
event.type === "twoPointConversionFailed" ||
// Include missed FGs
event.type === "fieldGoal" ||
event.type === "shootoutShot"
);
) {
const scoringSummaryEvent = {
...event,
quarter: period,
} as PlayByPlayEventScore;

return scoringSummaryEvent;
}
};
12 changes: 12 additions & 0 deletions src/common/formatScoringSummaryEvent.hockey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type {
PlayByPlayEvent,
PlayByPlayEventScore,
} from "../worker/core/GameSim.hockey/PlayByPlayLogger";

export const formatScoringSummaryEvent = (
event: PlayByPlayEvent,
): PlayByPlayEventScore | undefined => {
if (event.type === "goal" || event.type === "shootoutShot") {
return event;
}
};
20 changes: 6 additions & 14 deletions src/ui/util/processLiveGameEvents.football.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPeriodName } from "../../common";
import { isScoringPlay } from "../../common/isScoringPlay.football";
import { formatScoringSummaryEvent } from "../../common/formatScoringSummaryEvent.football";
import { helpers, local } from ".";
import type { PlayByPlayEvent } from "../../worker/core/GameSim.football/PlayByPlayLogger";
import type { ReactNode } from "react";
Expand Down Expand Up @@ -515,7 +515,7 @@ const processLiveGameEvents = ({
const actualT = eAny.t === 0 ? 1 : eAny.t === 1 ? 0 : undefined;
const otherT = actualT === 0 ? 1 : 0;

const scoringSummary = isScoringPlay(e);
const scoringSummaryEvent = formatScoringSummaryEvent(e, quarters.length);

let quarterText;
if (quarters.length === 0) {
Expand Down Expand Up @@ -957,14 +957,9 @@ const processLiveGameEvents = ({
}

// Extra fieldGoal check is to include missed field goals
if (scoringSummary) {
if (scoringSummaryEvent) {
const scoreInfo = getScoreInfo(e);
if (
scoreInfo &&
(scoreInfo.points > 0 ||
scoreInfo.type === "FG" ||
scoreInfo.type === "SH")
) {
if (scoreInfo) {
play.scoreInfo = scoreInfo;
}
}
Expand Down Expand Up @@ -1004,11 +999,8 @@ const processLiveGameEvents = ({
}
}

if (scoringSummary) {
boxScore.scoringSummary.push({
...e,
quarter: quarters.length,
});
if (scoringSummaryEvent) {
boxScore.scoringSummary.push(scoringSummaryEvent);
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/worker/core/GameSim.football/PlayByPlayLogger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isScoringPlay } from "../../../common/isScoringPlay.football";
import { formatScoringSummaryEvent } from "../../../common/formatScoringSummaryEvent.football";
import type { TeamNum } from "./types";

export type PlayByPlayEventInputScore =
Expand Down Expand Up @@ -109,7 +109,7 @@ export type PlayByPlayEventInputScore =
clock: number;
};

type PlayByPlayEventInput =
export type PlayByPlayEventInput =
| PlayByPlayEventInputScore
| {
type: "quarter";
Expand Down Expand Up @@ -313,11 +313,9 @@ class PlayByPlayLogger {
});
}

if (isScoringPlay(event)) {
this.scoringSummary.push({
...event,
quarter: this.quarter,
});
const scoringSummaryEvent = formatScoringSummaryEvent(event, this.quarter);
if (scoringSummaryEvent) {
this.scoringSummary.push(scoringSummaryEvent);
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/worker/views/playoffs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ const updatePlayoffs = async (
series = result.series;
playIns = result.playIns;
}
console.log(1, structuredClone(series));

await helpers.augmentSeries(series, inputs.season);
console.log(2, structuredClone(series));

if (playIns) {
await helpers.augmentSeries(playIns, inputs.season);
Expand All @@ -114,7 +112,6 @@ const updatePlayoffs = async (
away?: SeriesTeam;
}[][];
const playIns2 = playIns as PlayIns;
console.log(2, structuredClone(series2));

// Formatting for the table in playoffs.html
const matchups: {
Expand Down

0 comments on commit b145eef

Please sign in to comment.