mtlstats/src/Mtlstats/Prompt/EditPlayer.hs

126 lines
3.6 KiB
Haskell
Raw Normal View History

{- |
mtlstats
2020-01-11 00:29:45 -05:00
Copyright (C) 1984, 1985, 2019, 2020 Rhéal Lamothe
<rheal.lamothe@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-}
2019-11-01 06:10:37 -04:00
module Mtlstats.Prompt.EditPlayer
( editPlayerNumPrompt
, editPlayerNamePrompt
2019-11-01 06:26:38 -04:00
, editPlayerPosPrompt
2019-11-01 06:30:37 -04:00
, editPlayerYtdGoalsPrompt
, editPlayerYtdAssistsPrompt
, editPlayerYtdPMinPrompt
2019-11-01 06:40:48 -04:00
, editPlayerLtGoalsPrompt
2019-11-01 06:43:39 -04:00
, editPlayerLtAssistsPrompt
, editPlayerLtPMinPrompt
2019-11-01 06:10:37 -04:00
) where
import Control.Monad.Trans.State (modify)
import Lens.Micro ((.~))
2019-11-01 06:06:41 -04:00
import Mtlstats.Actions
2019-11-01 06:06:41 -04:00
import Mtlstats.Prompt
import Mtlstats.Types
-- | Prompt to edit a player's number
editPlayerNumPrompt :: Prompt
editPlayerNumPrompt = editNum "Player number: " EPMenu
(pNumber .~)
2019-11-01 06:10:37 -04:00
-- | Prompt to edit a player's name
editPlayerNamePrompt :: Prompt
editPlayerNamePrompt = namePrompt "Player name: " $ \name ->
if null name
then goto EPMenu
else doEdit EPMenu $ pName .~ name
2019-11-01 06:22:48 -04:00
2019-11-01 06:26:38 -04:00
-- | Prompt to edit a player's position
editPlayerPosPrompt :: Prompt
editPlayerPosPrompt = ucStrPrompt "Player position: " $ \pos ->
if null pos
then goto EPMenu
else doEdit EPMenu $ pPosition .~ pos
2019-11-01 06:26:38 -04:00
2019-11-01 06:30:37 -04:00
-- | Prompt to edit a player's year-to-date goals
editPlayerYtdGoalsPrompt
:: Bool
-- ^ Indicates wheter or not we're editing in batch mode
-> Prompt
editPlayerYtdGoalsPrompt batchMode = editNum "Year-to-date goals: " mode
(pYtd.psGoals .~)
where
mode = if batchMode then EPYtdAssists True else EPYtd
2019-11-01 06:30:37 -04:00
-- | Prompt to edit a player's year-to-date assists
editPlayerYtdAssistsPrompt
:: Bool
-- ^ Indicates wheter or not we're editing in batch mode
-> Prompt
editPlayerYtdAssistsPrompt batchMode = editNum "Year-to-date assists: " mode
(pYtd.psAssists .~)
where
mode = if batchMode then EPYtdPMin else EPYtd
-- | Prompt to edit a player's year-to-date penalty minutes
editPlayerYtdPMinPrompt :: Prompt
editPlayerYtdPMinPrompt = editNum "Year-to-date penalty minutes: " EPYtd
(pYtd.psPMin .~)
2019-11-01 06:40:48 -04:00
-- | Prompt to edit a player's lifetime goals
editPlayerLtGoalsPrompt
:: Bool
-- ^ Indicates wheter or not we're editing in batch mode
-> Prompt
editPlayerLtGoalsPrompt batchMode = editNum "Lifetime goals: " mode
(pLifetime.psGoals .~)
where
mode = if batchMode then EPLtAssists True else EPLifetime
2019-11-01 06:40:48 -04:00
2019-11-01 06:43:39 -04:00
-- | Prompt to edit a player's lifetime assists
editPlayerLtAssistsPrompt
:: Bool
-- ^ Indicates wheter or not we're editing in batch mode
-> Prompt
editPlayerLtAssistsPrompt batchMode = editNum "Lifetime assists: " mode
(pLifetime.psAssists .~)
where
mode = if batchMode then EPLtPMin else EPLifetime
2019-11-01 06:43:39 -04:00
-- | Prompt to edit a player's lifetime penalty minutes
editPlayerLtPMinPrompt :: Prompt
editPlayerLtPMinPrompt = editNum "Lifetime penalty minutes: " EPLifetime
(pLifetime.psPMin .~)
editNum
:: String
-> EditPlayerMode
-> (Int -> Player -> Player)
-> Prompt
editNum pStr mode f = numPromptWithFallback pStr
(goto mode)
(doEdit mode . f)
doEdit :: EditPlayerMode -> (Player -> Player) -> Action ()
doEdit mode f = do
modify $ editSelectedPlayer f
goto mode
goto :: EditPlayerMode -> Action ()
goto = modify . (progMode.editPlayerStateL.epsMode .~)