implemented overtimeCheck
This commit is contained in:
@@ -27,9 +27,10 @@ module Mtlstats.Actions
|
||||
, startNewGame
|
||||
, addChar
|
||||
, removeChar
|
||||
, overtimeCheck
|
||||
) where
|
||||
|
||||
import Lens.Micro (over, (&), (.~), (?~), (%~))
|
||||
import Lens.Micro (over, (^.), (&), (.~), (?~), (%~))
|
||||
|
||||
import Mtlstats.Types
|
||||
|
||||
@@ -58,3 +59,14 @@ removeChar :: ProgState -> ProgState
|
||||
removeChar = inputBuffer %~ \case
|
||||
"" -> ""
|
||||
str -> init str
|
||||
|
||||
-- | Determines whether or not to perform a check for overtime
|
||||
overtimeCheck :: ProgState -> ProgState
|
||||
overtimeCheck s
|
||||
| gameTied (s^.progMode.gameStateL) =
|
||||
s & progMode.gameStateL
|
||||
%~ (homeScore .~ Nothing)
|
||||
. (awayScore .~ Nothing)
|
||||
| gameWon (s^.progMode.gameStateL) =
|
||||
s & progMode.gameStateL.overtimeFlag ?~ False
|
||||
| otherwise = s
|
||||
|
||||
@@ -53,5 +53,6 @@ handleEvent e = gets (view progMode) >>= \case
|
||||
return True
|
||||
| null $ gs ^. awayScore -> do
|
||||
promptHandler awayScorePrompt e
|
||||
modify overtimeCheck
|
||||
return True
|
||||
| otherwise -> undefined
|
||||
|
||||
@@ -47,6 +47,7 @@ module Mtlstats.Types (
|
||||
otherTeam,
|
||||
homeScore,
|
||||
awayScore,
|
||||
overtimeFlag,
|
||||
-- ** Database Lenses
|
||||
dbPlayers,
|
||||
dbGoalies,
|
||||
@@ -131,14 +132,16 @@ data ProgState = ProgState
|
||||
|
||||
-- | The game state
|
||||
data GameState = GameState
|
||||
{ _gameType :: Maybe GameType
|
||||
{ _gameType :: Maybe GameType
|
||||
-- ^ The type of game (home/away)
|
||||
, _otherTeam :: String
|
||||
, _otherTeam :: String
|
||||
-- ^ The name of the other team
|
||||
, _homeScore :: Maybe Int
|
||||
, _homeScore :: Maybe Int
|
||||
-- ^ The home team's score
|
||||
, _awayScore :: Maybe Int
|
||||
, _awayScore :: Maybe Int
|
||||
-- ^ The away team's score
|
||||
, _overtimeFlag :: Maybe Bool
|
||||
-- ^ Indicates whether or not the game went into overtime
|
||||
} deriving (Eq, Show)
|
||||
|
||||
-- | The program mode
|
||||
@@ -400,10 +403,11 @@ newProgState = ProgState
|
||||
-- | Constructor for a 'GameState'
|
||||
newGameState :: GameState
|
||||
newGameState = GameState
|
||||
{ _gameType = Nothing
|
||||
, _otherTeam = ""
|
||||
, _homeScore = Nothing
|
||||
, _awayScore = Nothing
|
||||
{ _gameType = Nothing
|
||||
, _otherTeam = ""
|
||||
, _homeScore = Nothing
|
||||
, _awayScore = Nothing
|
||||
, _overtimeFlag = Nothing
|
||||
}
|
||||
|
||||
-- | Constructor for a 'Database'
|
||||
|
||||
Reference in New Issue
Block a user