don't edit player values when no new value entered

This commit is contained in:
Jonathan Lamothe 2019-12-31 23:23:34 -05:00
parent 63bd9a6de4
commit 34b743a55b

View File

@ -41,52 +41,67 @@ import Mtlstats.Util
-- | Prompt to edit a player's number -- | Prompt to edit a player's number
editPlayerNumPrompt :: Prompt editPlayerNumPrompt :: Prompt
editPlayerNumPrompt = numPrompt "Player number: " $ editPlayerNumPrompt = editNum "Player number: " EPMenu
editPlayer EPMenu . (pNumber .~) (pNumber .~)
-- | Prompt to edit a player's name -- | Prompt to edit a player's name
editPlayerNamePrompt :: Prompt editPlayerNamePrompt :: Prompt
editPlayerNamePrompt = namePrompt "Player name: " $ editPlayerNamePrompt = namePrompt "Player name: " $ \name ->
editPlayer EPMenu . (pName .~) if null name
then goto EPMenu
else editPlayer EPMenu $ pName .~ name
-- | Prompt to edit a player's position -- | Prompt to edit a player's position
editPlayerPosPrompt :: Prompt editPlayerPosPrompt :: Prompt
editPlayerPosPrompt = ucStrPrompt "Player position: " $ editPlayerPosPrompt = ucStrPrompt "Player position: " $ \pos ->
editPlayer EPMenu . (pPosition .~) if null pos
then goto EPMenu
else editPlayer EPMenu $ pPosition .~ pos
-- | Prompt to edit a player's year-to-date goals -- | Prompt to edit a player's year-to-date goals
editPlayerYtdGoalsPrompt :: Prompt editPlayerYtdGoalsPrompt :: Prompt
editPlayerYtdGoalsPrompt = numPrompt "Year-to-date goals: " $ editPlayerYtdGoalsPrompt = editNum "Year-to-date goals: " EPYtd
editPlayer EPYtd . (pYtd.psGoals .~) (pYtd.psGoals .~)
-- | Prompt to edit a player's year-to-date assists -- | Prompt to edit a player's year-to-date assists
editPlayerYtdAssistsPrompt :: Prompt editPlayerYtdAssistsPrompt :: Prompt
editPlayerYtdAssistsPrompt = numPrompt "Year-to-date assists: " $ editPlayerYtdAssistsPrompt = editNum "Year-to-date assists: " EPYtd
editPlayer EPYtd . (pYtd.psAssists .~) (pYtd.psAssists .~)
-- | 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 :: Prompt
editPlayerYtdPMinPrompt = numPrompt "Year-to-date penalty minutes: " $ editPlayerYtdPMinPrompt = editNum "Year-to-date penalty minutes: " EPYtd
editPlayer EPYtd . (pYtd.psPMin .~) (pYtd.psPMin .~)
-- | Prompt to edit a player's lifetime goals -- | Prompt to edit a player's lifetime goals
editPlayerLtGoalsPrompt :: Prompt editPlayerLtGoalsPrompt :: Prompt
editPlayerLtGoalsPrompt = numPrompt "Lifetime goals: " $ editPlayerLtGoalsPrompt = editNum "Lifetime goals: " EPLifetime
editPlayer EPLifetime . (pLifetime.psGoals .~) (pLifetime.psGoals .~)
-- | Prompt to edit a player's lifetime assists -- | Prompt to edit a player's lifetime assists
editPlayerLtAssistsPrompt :: Prompt editPlayerLtAssistsPrompt :: Prompt
editPlayerLtAssistsPrompt = numPrompt "Lifetime assists: " $ editPlayerLtAssistsPrompt = editNum "Lifetime assists: " EPLifetime
editPlayer EPLifetime . (pLifetime.psAssists .~) (pLifetime.psAssists .~)
-- | Prompt to edit a player's lifetime penalty minutes -- | Prompt to edit a player's lifetime penalty minutes
editPlayerLtPMinPrompt :: Prompt editPlayerLtPMinPrompt :: Prompt
editPlayerLtPMinPrompt = numPrompt "Lifetime penalty minutes: " $ editPlayerLtPMinPrompt = editNum "Lifetime penalty minutes: " EPLifetime
editPlayer EPLifetime . (pLifetime.psPMin .~) (pLifetime.psPMin .~)
editNum
:: String
-> EditPlayerMode
-> (Int -> Player -> Player)
-> Prompt
editNum pStr mode f = numPromptWithFallback pStr
(goto mode)
(editPlayer mode . f)
editPlayer :: EditPlayerMode -> (Player -> Player) -> Action () editPlayer :: EditPlayerMode -> (Player -> Player) -> Action ()
editPlayer mode f = editPlayer mode f =
whenJustM (gets (^.progMode.editPlayerStateL.epsSelectedPlayer)) $ \pid -> whenJustM (gets (^.progMode.editPlayerStateL.epsSelectedPlayer)) $ \pid -> do
modify modify $ database.dbPlayers %~ modifyNth pid f
$ (database.dbPlayers %~ modifyNth pid f) goto mode
. (progMode.editPlayerStateL.epsMode .~ mode)
goto :: EditPlayerMode -> Action ()
goto = modify . (progMode.editPlayerStateL.epsMode .~)