make selectPlayerPrompt call selectPrompt

This commit is contained in:
Jonathan Lamothe 2019-10-30 17:29:47 -04:00
parent 1e78ca6f40
commit d215f27f4f

View File

@ -199,49 +199,24 @@ selectPlayerPrompt
-- ^ The callback to run (takes the index number of the payer as -- ^ The callback to run (takes the index number of the payer as
-- input) -- input)
-> Prompt -> Prompt
selectPlayerPrompt pStr callback = Prompt selectPlayerPrompt pStr callback = selectPrompt SelectParams
{ promptDrawer = \s -> do { spPrompt = pStr
let sStr = s^.inputBuffer , spSearchHeader = "Player select:"
C.drawString pStr , spSearch = \sStr db -> playerSearch sStr (db^.dbPlayers)
C.drawString sStr , spSearchExact = \sStr db -> fst <$> playerSearchExact sStr (db^.dbPlayers)
(row, col) <- C.cursorPosition , spElemDesc = playerSummary
C.drawString "\n\nPlayer select:\n" , spCallback = callback
let sel = zip [1..maxFunKeys] $ playerSearch sStr $ s^.database.dbPlayers , spNotFound = \sStr -> do
mapM_ mode <- gets (^.progMode)
(\(n, (_, p)) -> C.drawString $
"F" ++ show n ++ ") " ++ p^.pName ++ " (" ++ show (p^.pNumber) ++ ")\n")
sel
C.moveCursor row col
, promptCharCheck = const True
, promptAction = \sStr -> if null sStr
then callback Nothing
else do
players <- gets $ view $ database.dbPlayers
case playerSearchExact sStr players of
Just (n, _) -> callback $ Just n
Nothing -> do
mode <- gets $ view progMode
let let
cps = newCreatePlayerState cps = newCreatePlayerState
& cpsName .~ sStr & cpsName .~ sStr
& cpsSuccessCallback .~ do & cpsSuccessCallback .~ do
modify $ progMode .~ mode modify $ progMode .~ mode
pIndex <- pred . length <$> gets (view $ database.dbPlayers) index <- pred . length <$> gets (^.database.dbPlayers)
callback $ Just pIndex callback $ Just index
& cpsFailureCallback .~ do & cpsFailureCallback .~ modify (progMode .~ mode)
modify $ progMode .~ mode
modify $ progMode .~ CreatePlayer cps modify $ progMode .~ CreatePlayer cps
, promptSpecialKey = \case
C.KeyFunction n -> do
sStr <- gets $ view inputBuffer
players <- gets $ view $ database.dbPlayers
modify $ inputBuffer .~ ""
let
fKey = pred $ fromIntegral n
options = playerSearch sStr players
sel = fst <$> nth fKey options
callback sel
_ -> return ()
} }
-- | Selects a goalie (creating one if necessary) -- | Selects a goalie (creating one if necessary)