implemented confirmGoalDataC

This commit is contained in:
Jonathan Lamothe 2019-10-01 00:58:15 -04:00
parent 66148a25d8
commit 2be7d2bf1d
3 changed files with 43 additions and 3 deletions

View File

@ -35,6 +35,7 @@ module Mtlstats.Actions
, recordGoalAssists
, awardGoal
, awardAssist
, resetGoalData
) where
import Control.Monad.Trans.State (modify)
@ -195,3 +196,7 @@ awardAssist n ps = ps
& pYtd.psAssists %~ succ
& pLifetime.psAssists %~ succ
else p) . zip [0..]
-- | Resets the entered data for the current goal
resetGoalData :: ProgState -> ProgState
resetGoalData = undefined

View File

@ -36,6 +36,7 @@ import Mtlstats.Menu
import Mtlstats.Prompt
import Mtlstats.Report
import Mtlstats.Types
import Mtlstats.Util
-- | Reads the program state and returs the apropriate controller to
-- run
@ -184,8 +185,9 @@ verifyDataC = Controller
goalInput :: GameState -> Controller
goalInput gs
| null (gs^.goalBy) = recordGoalC
| otherwise = recordAssistC
| null (gs^.goalBy ) = recordGoalC
| not (gs^.confirmGoalDataFlag) = recordAssistC
| otherwise = confirmGoalDataC
recordGoalC :: Controller
recordGoalC = Controller
@ -209,6 +211,34 @@ recordAssistC = Controller
return True
}
confirmGoalDataC :: Controller
confirmGoalDataC = Controller
{ drawController = \s -> do
let
(game, goal) = gameGoal s
gs = s^.progMode.gameStateL
players = s^.database.dbPlayers
msg = unlines $
[ " Game: " ++ padNum 2 game
, " Goal: " ++ show goal
, "Goal scored by: " ++
playerSummary (fromJust $ gs^.goalBy >>= flip nth players)
] ++
map
(\pid -> " Assisted by: " ++
playerSummary (fromJust $ nth pid players))
(gs^.assistsBy) ++
[ "Is the above information correct? (Y/N)" ]
C.drawString msg
return C.CursorInvisible
, handleController = \e -> do
case ynHandler e of
Just True -> modify recordGoalAssists
Just False -> modify resetGoalData
Nothing -> return ()
return True
}
reportC :: Controller
reportC = Controller
{ drawController = \s -> do

View File

@ -128,7 +128,8 @@ module Mtlstats.Types (
pPoints,
playerSearch,
playerSearchExact,
modifyPlayer
modifyPlayer,
playerSummary
) where
import Control.Monad.Trans.State (StateT)
@ -713,3 +714,7 @@ modifyPlayer f n = map
(\p -> if p^.pName == n
then f p
else p)
-- | Provides a short summary string for a player
playerSummary :: Player -> String
playerSummary = undefined