Skip to content

Commit

Permalink
Track numPlays
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmatter committed Nov 8, 2023
1 parent 5bc7e58 commit bf30259
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
4 changes: 1 addition & 3 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ FBGM show field during game
- somewhere show text of last event, so you can just look at the field and see everything
- for missed FG, treat it for tag as turnover, and also show score tag in red
- glitches
- fg scrimmage weirdness makes play look like negative
- "Start of 3rd quarter" and similar should clear drive
- unify logic with kickoffAfterEndOfPeriod
- punt/kick out of back of endzone - cap bar width
- also make sure logic for a kick in the endzone is correct
- how to update numPlays
- accepted penalties only count as a play if they are added on to the end of the play. this means we sometimes need to decrease numPlays when a penalty gets accepted, but not always
- penalty yardage is not being assessed correctly in UI for width of play bar yards. it's just being added to end of play, when it could be either from the spot of the foul or a tack on at the end. penalty event should have enough info to handle this.
- need to set scrimmage and toGo for extra points/2pt, currently they are weird
- extra point or 2 point conversion should be treated as a separate play bar?
- don't count towards numPlays
Expand Down
15 changes: 12 additions & 3 deletions src/ui/components/BoxScore.football.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -614,16 +614,25 @@ const FieldAndDrive = ({
const t = sportState.t;
const t2 = t === 0 ? 1 : 0;

const yards = sportState.scrimmage - sportState.initialScrimmage;
let yards = 0;
let numPlays = 0;
for (const play of sportState.plays) {
if (play.countsTowardsYards) {
yards += play.yards;
}
if (play.countsTowardsNumPlays) {
numPlays += 1;
}
}

return (
<div className="mb-3">
<div className="d-flex mb-1">
{sportState.text}
{!sportState.awaitingKickoff ? (
<div className="ms-auto">
Drive: {sportState.numPlays} play
{sportState.numPlays === 1 ? "" : "s"}, {yards} yard
Drive: {numPlays} play
{numPlays === 1 ? "" : "s"}, {yards} yard
{yards === 1 ? "" : "s"}
</div>
) : null}
Expand Down
23 changes: 16 additions & 7 deletions src/ui/util/processLiveGameEvents.football.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import type { PlayByPlayEvent } from "../../worker/core/GameSim.football/PlayByP
export type SportState = {
awaitingKickoff: boolean;
t: 0 | 1;
numPlays: number;
initialScrimmage: number;
scrimmage: number;
toGo: number;
plays: {
Expand All @@ -20,6 +18,8 @@ export type SportState = {
intendedPossessionChange: boolean; // For punts and kickoffs
numPossessionChanges: number;
flag: boolean;
countsTowardsNumPlays: boolean;
countsTowardsYards: boolean;

// Team with the ball after the play ends
t: 0 | 1;
Expand All @@ -30,8 +30,6 @@ export type SportState = {
export const DEFAULT_SPORT_STATE: SportState = {
awaitingKickoff: true,
t: 0,
numPlays: 0,
initialScrimmage: 0,
scrimmage: 0,
toGo: 0,
plays: [],
Expand Down Expand Up @@ -422,8 +420,6 @@ const processLiveGameEvents = ({

if (awaitingKickoff || sportState.t !== actualT) {
sportState.t = actualT;
sportState.numPlays = 0;
sportState.initialScrimmage = e.scrimmage;
sportState.plays = [];
}
sportState.awaitingKickoff = awaitingKickoff;
Expand All @@ -441,6 +437,8 @@ const processLiveGameEvents = ({
intendedPossessionChange: awaitingKickoff,
numPossessionChanges: 0,
flag: false,
countsTowardsNumPlays: false,
countsTowardsYards: false,
});

const prevPlay = sportState.plays.at(-2);
Expand Down Expand Up @@ -535,11 +533,22 @@ const processLiveGameEvents = ({
}

play.flag = true;

// For penalties before the snap, still count them
play.countsTowardsNumPlays = true;
play.countsTowardsYards = true;
} else if (e.type === "penaltyCount" && e.offsetStatus === "offset") {
// Offsetting penalties don't make it this far in the penalty event, because they have no associated text. But we can find them here. No play since the down is replayed.
// Maybe accepted penalties that lead to replaying the down should also be considered here, but I'm not totally sure how to find those (!e.tackOn penalty events maybe?) and I'm not sure it's actually useful to do that (can have weird stuff like a 5 yard drive from 0 plays).
play.countsTowardsNumPlays = false;
} else if (e.type === "dropback" || e.type === "handoff") {
play.countsTowardsNumPlays = true;
play.countsTowardsYards = true;
}

if (e.type === "kickoff") {
// yds is the distance kicked to
play.yards = 100 - sportState.initialScrimmage - e.yds;
play.yards = 100 - sportState.scrimmage - e.yds;
} else if (
e.type === "kickoffReturn" ||
e.type === "punt" ||
Expand Down

0 comments on commit bf30259

Please sign in to comment.