implemented assist prompt
This commit is contained in:
parent
ffdb8e1e8c
commit
75803edfe7
|
@ -32,6 +32,7 @@ module Mtlstats.Actions
|
|||
, validateGameDate
|
||||
, createPlayer
|
||||
, addPlayer
|
||||
, recordGoalAssists
|
||||
, awardGoal
|
||||
) where
|
||||
|
||||
|
@ -149,6 +150,10 @@ addPlayer s = fromMaybe s $ do
|
|||
Just $ s & database.dbPlayers
|
||||
%~ (player:)
|
||||
|
||||
-- | Awards the goal and assists to the players
|
||||
recordGoalAssists :: ProgState -> ProgState
|
||||
recordGoalAssists = undefined
|
||||
|
||||
-- | Awards a goal to a player
|
||||
awardGoal
|
||||
:: Int
|
||||
|
|
|
@ -190,18 +190,24 @@ goalInput gs
|
|||
recordGoalC :: Controller
|
||||
recordGoalC = Controller
|
||||
{ drawController = \s -> let
|
||||
game = s^.database.dbGames
|
||||
goal = succ $ s^.progMode.gameStateL.pointsAccounted
|
||||
(game, goal) = gameGoal s
|
||||
in drawPrompt (recordGoalPrompt game goal) s
|
||||
, handleController = \e -> do
|
||||
game <- gets $ view $ database.dbGames
|
||||
goal <- succ <$> gets (view $ progMode.gameStateL.pointsAccounted)
|
||||
(game, goal) <- gets gameGoal
|
||||
promptHandler (recordGoalPrompt game goal) e
|
||||
return True
|
||||
}
|
||||
|
||||
recordAssistC :: Controller
|
||||
recordAssistC = undefined
|
||||
recordAssistC = Controller
|
||||
{ drawController = \s -> let
|
||||
(game, goal, assist) = gameGoalAssist s
|
||||
in drawPrompt (recordAssistPrompt game goal assist) s
|
||||
, handleController = \e -> do
|
||||
(game, goal, assist) <- gets gameGoalAssist
|
||||
promptHandler (recordAssistPrompt game goal assist) e
|
||||
return True
|
||||
}
|
||||
|
||||
reportC :: Controller
|
||||
reportC = Controller
|
||||
|
@ -266,3 +272,15 @@ confirmCreatePlayerC = Controller
|
|||
Nothing -> return ()
|
||||
return True
|
||||
}
|
||||
|
||||
gameGoal :: ProgState -> (Int, Int)
|
||||
gameGoal s =
|
||||
( s^.database.dbGames
|
||||
, succ $ s^.progMode.gameStateL.pointsAccounted
|
||||
)
|
||||
|
||||
gameGoalAssist :: ProgState -> (Int, Int, Int)
|
||||
gameGoalAssist s = let
|
||||
(game, goal) = gameGoal s
|
||||
assist = succ $ length $ s^.progMode.gameStateL.assistsBy
|
||||
in (game, goal, assist)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user