implemented selectGoaliePrompt

This commit is contained in:
Jonathan Lamothe
2019-10-30 21:57:31 -04:00
parent d215f27f4f
commit 2926e28e34
2 changed files with 49 additions and 3 deletions

View File

@@ -227,7 +227,25 @@ selectGoaliePrompt
-- ^ The callback to run (takes the index number of the goalie as
-- input)
-> Prompt
selectGoaliePrompt = undefined
selectGoaliePrompt pStr callback = selectPrompt SelectParams
{ spPrompt = pStr
, spSearchHeader = "Goalie select:"
, spSearch = \sStr db -> goalieSearch sStr (db^.dbGoalies)
, spSearchExact = \sStr db -> fst <$> goalieSearchExact sStr (db^.dbGoalies)
, spElemDesc = goalieSummary
, spCallback = callback
, spNotFound = \sStr -> do
mode <- gets (^.progMode)
let
cgs = newCreateGoalieState
& cgsName .~ sStr
& cgsSuccessCallback .~ do
modify $ progMode .~ mode
index <- pred . length <$> gets (^.database.dbGoalies)
callback $ Just index
& cgsFailureCallback .~ modify (progMode .~ mode)
modify $ progMode .~ CreateGoalie cgs
}
-- | Prompts for the player who scored the goal
recordGoalPrompt
@@ -287,7 +305,7 @@ goalieNamePrompt = strPrompt "Goalie name: " $
-- | Prompts for a goalie who played in the game
selectGameGoaliePrompt :: Prompt
selectGameGoaliePrompt = selectGoaliePrompt "Select goalie: " $
selectGameGoaliePrompt = selectGoaliePrompt "Which goalie played this game: " $
\case
Nothing -> modify $ progMode.gameStateL.goaliesRecorded .~ True
Just n -> modify $ progMode.gameStateL.gameSelectedGoalie ?~ n