use editSelectedPlayer for all player edits

This commit is contained in:
Jonathan Lamothe 2020-01-09 01:15:30 -05:00
parent e2aeb5bfa4
commit 2c561e9807

View File

@ -31,13 +31,12 @@ module Mtlstats.Prompt.EditPlayer
, editPlayerLtPMinPrompt , editPlayerLtPMinPrompt
) where ) where
import Control.Monad.Extra (whenJustM) import Control.Monad.Trans.State (modify)
import Control.Monad.Trans.State (gets, modify) import Lens.Micro ((.~))
import Lens.Micro ((^.), (.~), (%~))
import Mtlstats.Actions
import Mtlstats.Prompt import Mtlstats.Prompt
import Mtlstats.Types import Mtlstats.Types
import Mtlstats.Util
-- | Prompt to edit a player's number -- | Prompt to edit a player's number
editPlayerNumPrompt :: Prompt editPlayerNumPrompt :: Prompt
@ -49,14 +48,14 @@ editPlayerNamePrompt :: Prompt
editPlayerNamePrompt = namePrompt "Player name: " $ \name -> editPlayerNamePrompt = namePrompt "Player name: " $ \name ->
if null name if null name
then goto EPMenu then goto EPMenu
else editPlayer EPMenu $ pName .~ name else doEdit 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: " $ \pos -> editPlayerPosPrompt = ucStrPrompt "Player position: " $ \pos ->
if null pos if null pos
then goto EPMenu then goto EPMenu
else editPlayer EPMenu $ pPosition .~ pos else doEdit EPMenu $ pPosition .~ pos
-- | Prompt to edit a player's year-to-date goals -- | Prompt to edit a player's year-to-date goals
editPlayerYtdGoalsPrompt editPlayerYtdGoalsPrompt
@ -115,13 +114,12 @@ editNum
-> Prompt -> Prompt
editNum pStr mode f = numPromptWithFallback pStr editNum pStr mode f = numPromptWithFallback pStr
(goto mode) (goto mode)
(editPlayer mode . f) (doEdit mode . f)
editPlayer :: EditPlayerMode -> (Player -> Player) -> Action () doEdit :: EditPlayerMode -> (Player -> Player) -> Action ()
editPlayer mode f = doEdit mode f = do
whenJustM (gets (^.progMode.editPlayerStateL.epsSelectedPlayer)) $ \pid -> do modify $ editSelectedPlayer f
modify $ database.dbPlayers %~ modifyNth pid f goto mode
goto mode
goto :: EditPlayerMode -> Action () goto :: EditPlayerMode -> Action ()
goto = modify . (progMode.editPlayerStateL.epsMode .~) goto = modify . (progMode.editPlayerStateL.epsMode .~)