perform follow-up action on player edit

This commit is contained in:
Jonathan Lamothe 2020-01-29 01:19:25 -05:00
parent 79d527866f
commit 2f0a3a5c57
2 changed files with 105 additions and 63 deletions

View File

@ -37,7 +37,8 @@ import Mtlstats.Util
editPlayerC :: EditPlayerState -> Controller editPlayerC :: EditPlayerState -> Controller
editPlayerC eps editPlayerC eps
| null $ eps^.epsSelectedPlayer = selectPlayerC | null $ eps^.epsSelectedPlayer = selectPlayerC
| otherwise = case eps^.epsMode of | otherwise =
( case eps^.epsMode of
EPMenu -> menuC EPMenu -> menuC
EPNumber -> numberC EPNumber -> numberC
EPName -> nameC EPName -> nameC
@ -50,45 +51,50 @@ editPlayerC eps
EPLtGoals b -> ltGoalsC b EPLtGoals b -> ltGoalsC b
EPLtAssists b -> ltAssistsC b EPLtAssists b -> ltAssistsC b
EPLtPMin -> ltPMinC EPLtPMin -> ltPMinC
) $ eps^.epsCallback
selectPlayerC :: Controller selectPlayerC :: Controller
selectPlayerC = promptController playerToEditPrompt selectPlayerC = promptController playerToEditPrompt
menuC :: Controller menuC :: Action () -> Controller
menuC = menuControllerWith header editPlayerMenu menuC _ = menuControllerWith header editPlayerMenu
numberC :: Controller numberC :: Action () -> Controller
numberC = promptController editPlayerNumPrompt numberC = promptController . editPlayerNumPrompt
nameC :: Controller nameC :: Action () -> Controller
nameC = promptController editPlayerNamePrompt nameC = promptController . editPlayerNamePrompt
positionC :: Controller positionC :: Action () -> Controller
positionC = promptController editPlayerPosPrompt positionC = promptController . editPlayerPosPrompt
ytdC :: Controller ytdC :: Action () -> Controller
ytdC = menuControllerWith header editPlayerYtdMenu ytdC _ = menuControllerWith header editPlayerYtdMenu
lifetimeC :: Controller lifetimeC :: Action () -> Controller
lifetimeC = menuControllerWith header editPlayerLtMenu lifetimeC _ = menuControllerWith header editPlayerLtMenu
ytdGoalsC :: Bool -> Controller ytdGoalsC :: Bool -> Action () -> Controller
ytdGoalsC = promptController . editPlayerYtdGoalsPrompt ytdGoalsC batchMode callback = promptController $
editPlayerYtdGoalsPrompt batchMode callback
ytdAssistsC :: Bool -> Controller ytdAssistsC :: Bool -> Action () -> Controller
ytdAssistsC = promptController . editPlayerYtdAssistsPrompt ytdAssistsC batchMode callback = promptController $
editPlayerYtdAssistsPrompt batchMode callback
ytdPMinC :: Controller ytdPMinC :: Action () -> Controller
ytdPMinC = promptController editPlayerYtdPMinPrompt ytdPMinC = promptController . editPlayerYtdPMinPrompt
ltGoalsC :: Bool -> Controller ltGoalsC :: Bool -> Action () -> Controller
ltGoalsC = promptController . editPlayerLtGoalsPrompt ltGoalsC batchMode callback = promptController $
editPlayerLtGoalsPrompt batchMode callback
ltAssistsC :: Bool -> Controller ltAssistsC :: Bool -> Action () -> Controller
ltAssistsC = promptController . editPlayerLtAssistsPrompt ltAssistsC batchMode callback = promptController $
editPlayerLtAssistsPrompt batchMode callback
ltPMinC :: Controller ltPMinC :: Action () -> Controller
ltPMinC = promptController editPlayerLtPMinPrompt ltPMinC = promptController . editPlayerLtPMinPrompt
header :: ProgState -> C.Update () header :: ProgState -> C.Update ()
header s = C.drawString $ fromMaybe "" $ do header s = C.drawString $ fromMaybe "" $ do

View File

@ -39,46 +39,68 @@ import Mtlstats.Prompt
import Mtlstats.Types import Mtlstats.Types
-- | Prompt to edit a player's number -- | Prompt to edit a player's number
editPlayerNumPrompt :: Prompt editPlayerNumPrompt
:: Action ()
-- ^ The action to be performed upon completion
-> Prompt
editPlayerNumPrompt = editNum "Player number: " EPMenu editPlayerNumPrompt = editNum "Player number: " EPMenu
(pNumber .~) (pNumber .~)
-- | Prompt to edit a player's name -- | Prompt to edit a player's name
editPlayerNamePrompt :: Prompt editPlayerNamePrompt
editPlayerNamePrompt = namePrompt "Player name: " $ \name -> :: Action ()
-- ^ The action to be performed upon completion
-> Prompt
editPlayerNamePrompt callback = namePrompt "Player name: " $ \name -> do
if null name if null name
then goto EPMenu then goto EPMenu
else doEdit EPMenu $ pName .~ name else doEdit EPMenu $ pName .~ name
callback
-- | Prompt to edit a player's position -- | Prompt to edit a player's position
editPlayerPosPrompt :: Prompt editPlayerPosPrompt
editPlayerPosPrompt = ucStrPrompt "Player position: " $ \pos -> :: Action ()
-- ^ The action to be performed upon completion
-> Prompt
editPlayerPosPrompt callback = ucStrPrompt "Player position: " $ \pos -> do
if null pos if null pos
then goto EPMenu then goto EPMenu
else doEdit EPMenu $ pPosition .~ pos else doEdit EPMenu $ pPosition .~ pos
callback
-- | Prompt to edit a player's year-to-date goals -- | Prompt to edit a player's year-to-date goals
editPlayerYtdGoalsPrompt editPlayerYtdGoalsPrompt
:: Bool :: Bool
-- ^ Indicates wheter or not we're editing in batch mode -- ^ Indicates wheter or not we're editing in batch mode
-> Action ()
-- ^ The action to be performed upon completion
-> Prompt -> Prompt
editPlayerYtdGoalsPrompt batchMode = editNum "Year-to-date goals: " mode editPlayerYtdGoalsPrompt batchMode callback = editNum "Year-to-date goals: " mode
(pYtd.psGoals .~) (pYtd.psGoals .~) callback'
where where
mode = if batchMode then EPYtdAssists True else EPYtd (mode, callback') = if batchMode
then (EPYtdAssists True, return ())
else (EPYtd, callback)
-- | Prompt to edit a player's year-to-date assists -- | Prompt to edit a player's year-to-date assists
editPlayerYtdAssistsPrompt editPlayerYtdAssistsPrompt
:: Bool :: Bool
-- ^ Indicates wheter or not we're editing in batch mode -- ^ Indicates wheter or not we're editing in batch mode
-> Action ()
-- ^ The action to be performed upon completion
-> Prompt -> Prompt
editPlayerYtdAssistsPrompt batchMode = editNum "Year-to-date assists: " mode editPlayerYtdAssistsPrompt batchMode callback = editNum "Year-to-date assists: " mode
(pYtd.psAssists .~) (pYtd.psAssists .~) callback'
where where
mode = if batchMode then EPYtdPMin else EPYtd (mode, callback') = if batchMode
then (EPYtdPMin, return ())
else (EPYtd, callback)
-- | Prompt to edit a player's year-to-date penalty minutes -- | Prompt to edit a player's year-to-date penalty minutes
editPlayerYtdPMinPrompt :: Prompt editPlayerYtdPMinPrompt
:: Action ()
-- ^ The action to be performed upon completion
-> Prompt
editPlayerYtdPMinPrompt = editNum "Year-to-date penalty minutes: " EPYtd editPlayerYtdPMinPrompt = editNum "Year-to-date penalty minutes: " EPYtd
(pYtd.psPMin .~) (pYtd.psPMin .~)
@ -86,24 +108,35 @@ editPlayerYtdPMinPrompt = editNum "Year-to-date penalty minutes: " EPYtd
editPlayerLtGoalsPrompt editPlayerLtGoalsPrompt
:: Bool :: Bool
-- ^ Indicates wheter or not we're editing in batch mode -- ^ Indicates wheter or not we're editing in batch mode
-> Action ()
-- ^ The action to be performed upon completion
-> Prompt -> Prompt
editPlayerLtGoalsPrompt batchMode = editNum "Lifetime goals: " mode editPlayerLtGoalsPrompt batchMode callback = editNum "Lifetime goals: " mode
(pLifetime.psGoals .~) (pLifetime.psGoals .~) callback'
where where
mode = if batchMode then EPLtAssists True else EPLifetime (mode, callback') = if batchMode
then (EPLtAssists True, return ())
else (EPLifetime, callback)
-- | Prompt to edit a player's lifetime assists -- | Prompt to edit a player's lifetime assists
editPlayerLtAssistsPrompt editPlayerLtAssistsPrompt
:: Bool :: Bool
-- ^ Indicates wheter or not we're editing in batch mode -- ^ Indicates wheter or not we're editing in batch mode
-> Action ()
-- ^ The action to be performed upon completion
-> Prompt -> Prompt
editPlayerLtAssistsPrompt batchMode = editNum "Lifetime assists: " mode editPlayerLtAssistsPrompt batchMode callback = editNum "Lifetime assists: " mode
(pLifetime.psAssists .~) (pLifetime.psAssists .~) callback'
where where
mode = if batchMode then EPLtPMin else EPLifetime (mode, callback') = if batchMode
then (EPLtPMin, return ())
else (EPLifetime, callback)
-- | Prompt to edit a player's lifetime penalty minutes -- | Prompt to edit a player's lifetime penalty minutes
editPlayerLtPMinPrompt :: Prompt editPlayerLtPMinPrompt
:: Action ()
-- ^ The action to be performed upon completion
-> Prompt
editPlayerLtPMinPrompt = editNum "Lifetime penalty minutes: " EPLifetime editPlayerLtPMinPrompt = editNum "Lifetime penalty minutes: " EPLifetime
(pLifetime.psPMin .~) (pLifetime.psPMin .~)
@ -111,10 +144,13 @@ editNum
:: String :: String
-> EditPlayerMode -> EditPlayerMode
-> (Int -> Player -> Player) -> (Int -> Player -> Player)
-> Action ()
-> Prompt -> Prompt
editNum pStr mode f = numPromptWithFallback pStr editNum pStr mode f callback = numPromptWithFallback pStr
(goto mode) (goto mode >> callback)
(doEdit mode . f) (\num -> do
doEdit mode $ f num
callback)
doEdit :: EditPlayerMode -> (Player -> Player) -> Action () doEdit :: EditPlayerMode -> (Player -> Player) -> Action ()
doEdit mode f = do doEdit mode f = do