implemented recordGoalPrompt

This commit is contained in:
Jonathan Lamothe 2019-09-19 05:50:48 -04:00
parent b125e72034
commit e80b7ec48c

View File

@ -37,18 +37,20 @@ module Mtlstats.Prompt (
playerNamePrompt, playerNamePrompt,
playerPosPrompt, playerPosPrompt,
selectPlayerPrompt, selectPlayerPrompt,
recordGoalPrompt,
) where ) where
import Control.Monad (when) import Control.Monad (when)
import Control.Monad.Trans.State (gets, modify) import Control.Monad.Trans.State (gets, modify)
import Data.Char (isDigit, toUpper) import Data.Char (isDigit, toUpper)
import Data.Foldable (forM_) import Data.Foldable (forM_)
import Lens.Micro ((^.), (&), (.~), (?~)) import Lens.Micro ((^.), (&), (.~), (?~), (%~))
import Lens.Micro.Extras (view) import Lens.Micro.Extras (view)
import Text.Read (readMaybe) import Text.Read (readMaybe)
import qualified UI.NCurses as C import qualified UI.NCurses as C
import Mtlstats.Actions import Mtlstats.Actions
import Mtlstats.Format
import Mtlstats.Types import Mtlstats.Types
import Mtlstats.Util import Mtlstats.Util
@ -193,5 +195,21 @@ selectPlayerPrompt pStr callback = Prompt
_ -> return () _ -> return ()
} }
-- | Prompts for the player who scored the goal
recordGoalPrompt
:: Int
-- ^ The game number
-> Int
-- ^ The goal number
-> Prompt
recordGoalPrompt game goal = selectPlayerPrompt
("*** GAME " ++ padNum 2 game ++ " ***\n" ++
"Who scored goal number " ++ show goal ++ "? ") $
\case
Nothing -> return ()
Just n -> modify
$ awardGoal n
. (progMode.gameStateL.pointsAccounted %~ succ)
drawSimplePrompt :: String -> ProgState -> C.Update () drawSimplePrompt :: String -> ProgState -> C.Update ()
drawSimplePrompt pStr s = C.drawString $ pStr ++ s^.inputBuffer drawSimplePrompt pStr s = C.drawString $ pStr ++ s^.inputBuffer