implemented homeTeam and awayTeam

This commit is contained in:
Jonathan Lamothe
2019-09-02 18:50:21 -04:00
parent f0e0d644d2
commit 6136151614
3 changed files with 87 additions and 0 deletions
+20
View File
@@ -97,6 +97,8 @@ module Mtlstats.Types (
-- ** GameState Helpers
teamScore,
otherScore,
homeTeam,
awayTeam,
gameWon,
gameLost,
gameTied,
@@ -124,6 +126,8 @@ import Lens.Micro (Lens', lens, (&), (^.), (.~))
import Lens.Micro.TH (makeLenses)
import UI.NCurses (Curses, Update)
import Mtlstats.Config
-- | Action which maintains program state
type Action a = StateT ProgState Curses a
@@ -509,6 +513,22 @@ otherScore s = case s ^. gameType of
Just AwayGame -> s ^. homeScore
Nothing -> Nothing
-- | Returns the name of the home team (or an empty string if
-- unavailable)
homeTeam :: GameState -> String
homeTeam gs = case gs^.gameType of
Just HomeGame -> myTeam
Just AwayGame -> gs^.otherTeam
Nothing -> ""
-- | Returns the name of the visiting team (or an empty string if
-- unavailable)
awayTeam :: GameState -> String
awayTeam gs = case gs^.gameType of
Just HomeGame -> gs^.otherTeam
Just AwayGame -> myTeam
Nothing -> ""
-- | Checks if the game was won
gameWon :: GameState -> Maybe Bool
gameWon gs = (>) <$> teamScore gs <*> otherScore gs