Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
feat(model): more useful game accessors, including weather
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Reed committed Oct 15, 2020
1 parent 3f42ff1 commit fecdca6
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/lib/model/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ import { Entry } from './_entry';
import { sha256 } from 'hash.js';
import { Player } from './player';

const WEATHER = [
"Void",
"Sunny",
"Overcast",
"Rainy",
"Sandstorm",
"Snowy",
"Acidic",
"Solar Eclipse",
"Glitter",
"Blooddrain",
"Peanuts",
"Lots of Birds",
"Feedback",
"Reverb",
];

export class Game extends Entry {
id: string;
atBatBalls: number;
Expand Down Expand Up @@ -214,6 +231,15 @@ export class Game extends Entry {
return undefined;
}

public get winnerId(): string {
if (this.homeScore < this.awayScore) {
return this.awayTeam;
} else if (this.homeScore > this.awayScore) {
return this.homeTeam;
}
return undefined;
}

public get winner(): string {
if (this.homeScore < this.awayScore) {
return this.awayTeamName;
Expand All @@ -223,6 +249,15 @@ export class Game extends Entry {
return undefined;
}

public get loserId(): string {
if (this.homeScore < this.awayScore) {
return this.homeTeam;
} else if (this.homeScore > this.awayScore) {
return this.awayTeam;
}
return undefined;
}

public get loser(): string {
if (this.homeScore < this.awayScore) {
return this.homeTeamName;
Expand All @@ -232,6 +267,10 @@ export class Game extends Entry {
return undefined;
}

public get weatherString() {
return WEATHER[this.weather] || 'Unknown';
}

public get winningScore(): number {
return Math.max(this.homeScore, this.awayScore);
}
Expand Down

0 comments on commit fecdca6

Please sign in to comment.