implemented assist prompt

This commit is contained in:
Jonathan Lamothe
2019-09-26 01:23:34 -04:00
parent ffdb8e1e8c
commit 75803edfe7
3 changed files with 55 additions and 7 deletions

View File

@@ -38,6 +38,7 @@ module Mtlstats.Prompt (
playerPosPrompt,
selectPlayerPrompt,
recordGoalPrompt,
recordAssistPrompt
) where
import Control.Monad (when)
@@ -205,8 +206,8 @@ recordGoalPrompt
-- ^ The goal number
-> Prompt
recordGoalPrompt game goal = selectPlayerPrompt
( "*** GAME " ++ padNum 2 game ++ " ***\n" ++
"Who scored goal number " ++ show goal ++ "? "
( "*** GAME " ++ padNum 2 game ++ " ***\n"
++ "Who scored goal number " ++ show goal ++ "? "
) $ \case
Nothing -> return ()
Just n -> nth n <$> gets (view $ database.dbPlayers)
@@ -214,5 +215,29 @@ recordGoalPrompt game goal = selectPlayerPrompt
(return ())
(\p -> modify $ progMode.gameStateL.goalBy .~ p^.pName)
-- | Prompts for a player who assisted the goal
recordAssistPrompt
:: Int
-- ^ The game number
-> Int
-- ^ The goal nuber
-> Int
-- ^ The assist number
-> Prompt
recordAssistPrompt game goal assist = selectPlayerPrompt
( "*** GAME " ++ padNum 2 game ++ " ***\n"
++ "Goal: " ++ show goal ++ "\n"
++ "Assist #" ++ show assist ++ ": "
) $ \case
Nothing -> modify recordGoalAssists
Just n -> nth n <$> gets (view $ database.dbPlayers)
>>= maybe
(return ())
(\p -> do
modify $ progMode.gameStateL.assistsBy %~ (++[p^.pName])
nAssists <- length <$> gets (view $ progMode.gameStateL.assistsBy)
when (nAssists >= maxAssists) $
modify recordGoalAssists)
drawSimplePrompt :: String -> ProgState -> C.Update ()
drawSimplePrompt pStr s = C.drawString $ pStr ++ s^.inputBuffer