From 8bc9b48aa2c3809bb1e77b076342d6ffb6bbfe49 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 31 Jan 2020 00:25:20 -0500 Subject: [PATCH 1/5] added callback to EditGoalieState --- src/Mtlstats/Types.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index 17f8116..275d382 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -102,6 +102,7 @@ module Mtlstats.Types ( -- ** EditGoalieState Lenses egsSelectedGoalie, egsMode, + egsCallback, -- ** Database Lenses dbPlayers, dbGoalies, @@ -376,6 +377,9 @@ data EditGoalieState = EditGoalieState { _egsSelectedGoalie :: Maybe Int -- ^ The index number of the 'Goalie' being edited , _egsMode :: EditGoalieMode + -- ^ The editing mode + , _egsCallback :: Action () + -- ^ The action to perform when the edit is complete } -- | 'Goalie' editing mode @@ -829,6 +833,7 @@ newEditGoalieState :: EditGoalieState newEditGoalieState = EditGoalieState { _egsSelectedGoalie = Nothing , _egsMode = EGMenu + , _egsCallback = return () } -- | Constructor for a 'Database' From 835cb9582bee8703fa703f03a2eeb0fa7271d9c9 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 31 Jan 2020 00:36:16 -0500 Subject: [PATCH 2/5] created Mtlstats.Control.CreateGoalie module --- src/Mtlstats/Control.hs | 62 +++------------------- src/Mtlstats/Control/CreateGoalie.hs | 78 ++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 54 deletions(-) create mode 100644 src/Mtlstats/Control/CreateGoalie.hs diff --git a/src/Mtlstats/Control.hs b/src/Mtlstats/Control.hs index 1c192be..b527fa4 100644 --- a/src/Mtlstats/Control.hs +++ b/src/Mtlstats/Control.hs @@ -21,20 +21,15 @@ along with this program. If not, see . module Mtlstats.Control (dispatch) where -import Control.Monad (join) -import Control.Monad.Trans.State (gets, modify) -import Data.Maybe (fromJust) import Lens.Micro ((^.)) -import qualified UI.NCurses as C -import Mtlstats.Actions +import Mtlstats.Control.CreateGoalie import Mtlstats.Control.CreatePlayer import Mtlstats.Control.EditGoalie import Mtlstats.Control.EditPlayer import Mtlstats.Control.EditStandings import Mtlstats.Control.NewGame import Mtlstats.Control.TitleScreen -import Mtlstats.Handlers import Mtlstats.Menu import Mtlstats.Prompt import Mtlstats.Types @@ -43,16 +38,13 @@ import Mtlstats.Types -- run dispatch :: ProgState -> Controller dispatch s = case s^.progMode of - TitleScreen -> titleScreenC - MainMenu -> mainMenuC - NewSeason flag -> newSeasonC flag - NewGame gs -> newGameC gs - EditMenu -> editMenuC - CreatePlayer cps -> createPlayerC cps - CreateGoalie cgs - | null $ cgs^.cgsNumber -> getGoalieNumC - | null $ cgs^.cgsName -> getGoalieNameC - | otherwise -> confirmCreateGoalieC + TitleScreen -> titleScreenC + MainMenu -> mainMenuC + NewSeason flag -> newSeasonC flag + NewGame gs -> newGameC gs + EditMenu -> editMenuC + CreatePlayer cps -> createPlayerC cps + CreateGoalie cgs -> createGoalieC cgs EditPlayer eps -> editPlayerC eps EditGoalie egs -> editGoalieC egs (EditStandings esm) -> editStandingsC esm @@ -69,41 +61,3 @@ newSeasonC True = menuController newSeasonMenu editMenuC :: Controller editMenuC = menuController editMenu - -getGoalieNumC :: Controller -getGoalieNumC = Controller - { drawController = drawPrompt goalieNumPrompt - , handleController = \e -> do - promptHandler goalieNumPrompt e - return True - } - -getGoalieNameC :: Controller -getGoalieNameC = Controller - { drawController = drawPrompt goalieNamePrompt - , handleController = \e -> do - promptHandler goalieNamePrompt e - return True - } - -confirmCreateGoalieC :: Controller -confirmCreateGoalieC = Controller - { drawController = \s -> do - let cgs = s^.progMode.createGoalieStateL - C.drawString $ unlines - [ "Goalie number: " ++ show (fromJust $ cgs^.cgsNumber) - , " Goalie name: " ++ cgs^.cgsName - , "" - , "Create goalie: are you sure? (Y/N)" - ] - return C.CursorInvisible - , handleController = \e -> do - case ynHandler e of - Just True -> do - modify addGoalie - join $ gets (^.progMode.createGoalieStateL.cgsSuccessCallback) - Just False -> - join $ gets (^.progMode.createGoalieStateL.cgsFailureCallback) - Nothing -> return () - return True - } diff --git a/src/Mtlstats/Control/CreateGoalie.hs b/src/Mtlstats/Control/CreateGoalie.hs new file mode 100644 index 0000000..1514a2d --- /dev/null +++ b/src/Mtlstats/Control/CreateGoalie.hs @@ -0,0 +1,78 @@ +{- | + +mtlstats +Copyright (C) 1984, 1985, 2019, 2020 Rhéal Lamothe + + +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 . + +-} + +module Mtlstats.Control.CreateGoalie (createGoalieC) where + +import Control.Monad (join) +import Control.Monad.Trans.State (gets, modify) +import Data.Maybe (fromJust) +import Lens.Micro ((^.)) +import qualified UI.NCurses as C + +import Mtlstats.Actions +import Mtlstats.Handlers +import Mtlstats.Prompt +import Mtlstats.Types + +-- | Handles goalie creation +createGoalieC :: CreateGoalieState -> Controller +createGoalieC cgs + | null $ cgs^.cgsNumber = getGoalieNumC + | null $ cgs^.cgsName = getGoalieNameC + | otherwise = confirmCreateGoalieC + +getGoalieNumC :: Controller +getGoalieNumC = Controller + { drawController = drawPrompt goalieNumPrompt + , handleController = \e -> do + promptHandler goalieNumPrompt e + return True + } + +getGoalieNameC :: Controller +getGoalieNameC = Controller + { drawController = drawPrompt goalieNamePrompt + , handleController = \e -> do + promptHandler goalieNamePrompt e + return True + } + +confirmCreateGoalieC :: Controller +confirmCreateGoalieC = Controller + { drawController = \s -> do + let cgs = s^.progMode.createGoalieStateL + C.drawString $ unlines + [ "Goalie number: " ++ show (fromJust $ cgs^.cgsNumber) + , " Goalie name: " ++ cgs^.cgsName + , "" + , "Create goalie: are you sure? (Y/N)" + ] + return C.CursorInvisible + , handleController = \e -> do + case ynHandler e of + Just True -> do + modify addGoalie + join $ gets (^.progMode.createGoalieStateL.cgsSuccessCallback) + Just False -> + join $ gets (^.progMode.createGoalieStateL.cgsFailureCallback) + Nothing -> return () + return True + } From 13a1949446687d0ac528fd083019fe22890db063 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 31 Jan 2020 21:14:56 -0500 Subject: [PATCH 3/5] perform action on completion of goalie edit --- src/Mtlstats/Control/EditGoalie.hs | 134 ++++++++++++++----------- src/Mtlstats/Prompt/EditGoalie.hs | 156 ++++++++++++++++++++--------- 2 files changed, 184 insertions(+), 106 deletions(-) diff --git a/src/Mtlstats/Control/EditGoalie.hs b/src/Mtlstats/Control/EditGoalie.hs index fac4c87..595b35a 100644 --- a/src/Mtlstats/Control/EditGoalie.hs +++ b/src/Mtlstats/Control/EditGoalie.hs @@ -39,89 +39,103 @@ import Mtlstats.Util editGoalieC :: EditGoalieState -> Controller editGoalieC egs | null $ egs^.egsSelectedGoalie = selectC - | otherwise = editC $ egs^.egsMode + | otherwise = editC (egs^.egsCallback) (egs^.egsMode) selectC :: Controller selectC = promptController goalieToEditPrompt -editC :: EditGoalieMode -> Controller -editC = \case - EGMenu -> menuC - EGNumber -> numberC - EGName -> nameC - EGYtd -> ytdMenuC - EGLifetime -> lifetimeMenuC - EGYtdGames b -> ytdGamesC b - EGYtdMins b -> ytdMinsC b - EGYtdGoals b -> ytdGoalsC b - EGYtdShutouts b -> ytdShutoutsC b - EGYtdWins b -> ytdWinsC b - EGYtdLosses b -> ytdLossesC b - EGYtdTies -> ytdTiesC - EGLtGames b -> ltGamesC b - EGLtMins b -> ltMinsC b - EGLtGoals b -> ltGoalsC b - EGLtShutouts b -> ltShutoutsC b - EGLtWins b -> ltWinsC b - EGLtLosses b -> ltLossesC b - EGLtTies -> ltTiesC +editC :: Action () -> EditGoalieMode -> Controller +editC cb = + ( \case + EGMenu -> menuC + EGNumber -> numberC + EGName -> nameC + EGYtd -> ytdMenuC + EGLifetime -> lifetimeMenuC + EGYtdGames b -> ytdGamesC b + EGYtdMins b -> ytdMinsC b + EGYtdGoals b -> ytdGoalsC b + EGYtdShutouts b -> ytdShutoutsC b + EGYtdWins b -> ytdWinsC b + EGYtdLosses b -> ytdLossesC b + EGYtdTies -> ytdTiesC + EGLtGames b -> ltGamesC b + EGLtMins b -> ltMinsC b + EGLtGoals b -> ltGoalsC b + EGLtShutouts b -> ltShutoutsC b + EGLtWins b -> ltWinsC b + EGLtLosses b -> ltLossesC b + EGLtTies -> ltTiesC + ) <*> return cb -menuC :: Controller -menuC = menuControllerWith header editGoalieMenu +menuC :: Action () -> Controller +menuC _ = menuControllerWith header editGoalieMenu -numberC :: Controller -numberC = promptController editGoalieNumberPrompt +numberC :: Action () -> Controller +numberC = promptController . editGoalieNumberPrompt -nameC :: Controller -nameC = promptController editGoalieNamePrompt +nameC :: Action () -> Controller +nameC = promptController . editGoalieNamePrompt -ytdMenuC :: Controller -ytdMenuC = menuControllerWith header editGoalieYtdMenu +ytdMenuC :: Action () -> Controller +ytdMenuC _ = menuControllerWith header editGoalieYtdMenu -lifetimeMenuC :: Controller -lifetimeMenuC = menuControllerWith header editGoalieLtMenu +lifetimeMenuC :: Action () -> Controller +lifetimeMenuC _ = menuControllerWith header editGoalieLtMenu -ytdGamesC :: Bool -> Controller -ytdGamesC = promptController . editGoalieYtdGamesPrompt +ytdGamesC :: Bool -> Action () -> Controller +ytdGamesC = curry $ promptController . + uncurry editGoalieYtdGamesPrompt -ytdMinsC :: Bool -> Controller -ytdMinsC = promptController . editGoalieYtdMinsPrompt +ytdMinsC :: Bool -> Action () -> Controller +ytdMinsC = curry $ promptController . + uncurry editGoalieYtdMinsPrompt -ytdGoalsC :: Bool -> Controller -ytdGoalsC = promptController . editGoalieYtdGoalsPrompt +ytdGoalsC :: Bool -> Action () -> Controller +ytdGoalsC = curry $ promptController . + uncurry editGoalieYtdGoalsPrompt -ytdShutoutsC :: Bool -> Controller -ytdShutoutsC = promptController . editGoalieYtdShutoutsPrompt +ytdShutoutsC :: Bool -> Action () -> Controller +ytdShutoutsC = curry $ promptController . + uncurry editGoalieYtdShutoutsPrompt -ytdWinsC :: Bool -> Controller -ytdWinsC = promptController . editGoalieYtdWinsPrompt +ytdWinsC :: Bool -> Action () -> Controller +ytdWinsC = curry $ promptController . + uncurry editGoalieYtdWinsPrompt -ytdLossesC :: Bool -> Controller -ytdLossesC = promptController . editGoalieYtdLossesPrompt +ytdLossesC :: Bool -> Action () -> Controller +ytdLossesC = curry $ promptController . + uncurry editGoalieYtdLossesPrompt -ytdTiesC :: Controller -ytdTiesC = promptController editGoalieYtdTiesPrompt +ytdTiesC :: Action () -> Controller +ytdTiesC = promptController . editGoalieYtdTiesPrompt -ltGamesC :: Bool -> Controller -ltGamesC = promptController . editGoalieLtGamesPrompt +ltGamesC :: Bool -> Action () -> Controller +ltGamesC = curry $ promptController . + uncurry editGoalieLtGamesPrompt -ltMinsC :: Bool -> Controller -ltMinsC = promptController . editGoalieLtMinsPrompt +ltMinsC :: Bool -> Action () -> Controller +ltMinsC = curry $ promptController . + uncurry editGoalieLtMinsPrompt -ltGoalsC :: Bool -> Controller -ltGoalsC = promptController . editGoalieLtGoalsPrompt +ltGoalsC :: Bool -> Action() -> Controller +ltGoalsC = curry $ promptController . + uncurry editGoalieLtGoalsPrompt -ltShutoutsC :: Bool -> Controller -ltShutoutsC = promptController . editGoalieLtShutoutsPrompt +ltShutoutsC :: Bool -> Action () -> Controller +ltShutoutsC = curry $ promptController . + uncurry editGoalieLtShutoutsPrompt -ltWinsC :: Bool -> Controller -ltWinsC = promptController . editGoalieLtWinsPrompt +ltWinsC :: Bool -> Action () -> Controller +ltWinsC = curry $ promptController . + uncurry editGoalieLtWinsPrompt -ltLossesC :: Bool -> Controller -ltLossesC = promptController . editGoalieLtLossesPrompt +ltLossesC :: Bool -> Action () -> Controller +ltLossesC = curry $ promptController . + uncurry editGoalieLtLossesPrompt -ltTiesC :: Controller -ltTiesC = promptController editGoalieLtTiesPrompt +ltTiesC :: Action () -> Controller +ltTiesC = promptController . editGoalieLtTiesPrompt header :: ProgState -> C.Update () header s = C.drawString $ fromMaybe "" $ do diff --git a/src/Mtlstats/Prompt/EditGoalie.hs b/src/Mtlstats/Prompt/EditGoalie.hs index cde7d42..f77fe60 100644 --- a/src/Mtlstats/Prompt/EditGoalie.hs +++ b/src/Mtlstats/Prompt/EditGoalie.hs @@ -52,85 +52,119 @@ goalieToEditPrompt = selectGoaliePrompt "Goalie to edit: " $ modify . (progMode.editGoalieStateL.egsSelectedGoalie .~) -- | Prompt to edit a goalie's number -editGoalieNumberPrompt :: Prompt +editGoalieNumberPrompt + :: Action () + -- ^ Action to perform on completion + -> Prompt editGoalieNumberPrompt = editNum "Goalie number: " EGMenu (gNumber .~) -- | Prompt to edit a goalie's name -editGoalieNamePrompt :: Prompt -editGoalieNamePrompt = namePrompt "Goalie name: " $ \name -> +editGoalieNamePrompt + :: Action () + -- ^ Action to perform on completion + -> Prompt +editGoalieNamePrompt cb = namePrompt "Goalie name: " $ \name -> do if null name - then goto EGMenu - else doEdit EGMenu $ gName .~ name + then goto EGMenu + else doEdit EGMenu $ gName .~ name + cb -- | Prompt to edit a goalie's YTD games played editGoalieYtdGamesPrompt :: Bool -- ^ Indicates whether or not we're in batch mode + -> Action () + -- ^ Action to perform on completion -> Prompt -editGoalieYtdGamesPrompt batchMode = +editGoalieYtdGamesPrompt batchMode cb = editNum "Year-to-date games played: " mode - (gYtd.gsGames .~) + (gYtd.gsGames .~) cb' where - mode = if batchMode then EGYtdMins True else EGYtd + (mode, cb') = if batchMode + then (EGYtdMins True, return ()) + else (EGYtd, cb) -- | Prompt to edit a goalie's YTD minutes played editGoalieYtdMinsPrompt :: Bool -- ^ Indicates whether or not we're in batch mode + -> Action () + -- ^ Action to perform on completion -> Prompt -editGoalieYtdMinsPrompt batchMode = +editGoalieYtdMinsPrompt batchMode cb = editNum "Year-to-date minutes played: " mode - (gYtd.gsMinsPlayed .~) + (gYtd.gsMinsPlayed .~) cb' where - mode = if batchMode then EGYtdGoals True else EGYtd + (mode, cb') = if batchMode + then (EGYtdGoals True, return ()) + else (EGYtd, cb) -- | Prompt to edit a goalie's YTD goales allowed editGoalieYtdGoalsPrompt :: Bool -- ^ Indicates whether or not we're in batch mode + -> Action () + -- ^ Action to perform on completion -> Prompt -editGoalieYtdGoalsPrompt batchMode = +editGoalieYtdGoalsPrompt batchMode cb = editNum "Year-to-date goals allowed: " mode - (gYtd.gsGoalsAllowed .~) + (gYtd.gsGoalsAllowed .~) cb' where - mode = if batchMode then EGYtdShutouts True else EGYtd + (mode, cb') = if batchMode + then (EGYtdShutouts True, return ()) + else (EGYtd, cb) -- | Prompt to edit a goalie's YTD shutouts editGoalieYtdShutoutsPrompt :: Bool -- ^ Indicates whether or not we're in batch mode + -> Action () + -- ^ Action to perform on completion -> Prompt -editGoalieYtdShutoutsPrompt batchMode = +editGoalieYtdShutoutsPrompt batchMode cb = editNum "Year-to-date shutouts: " mode - (gYtd.gsShutouts .~) + (gYtd.gsShutouts .~) cb' where - mode = if batchMode then EGYtdWins True else EGYtd + (mode, cb') = if batchMode + then (EGYtdWins True, return ()) + else (EGYtd, cb) -- | Prompt to edit a goalie's YTD wins editGoalieYtdWinsPrompt :: Bool -- ^ Indicates whether or not we're in batch mode + -> Action () + -- ^ Action to perform on completion -> Prompt -editGoalieYtdWinsPrompt batchMode = +editGoalieYtdWinsPrompt batchMode cb = editNum "Year-to-date wins: " mode - (gYtd.gsWins .~) + (gYtd.gsWins .~) cb' where - mode = if batchMode then EGYtdLosses True else EGYtd + (mode, cb') = if batchMode + then (EGYtdLosses True, return ()) + else (EGYtd, cb) -- | Prompt to edit a goalie's YTD losses editGoalieYtdLossesPrompt :: Bool -- ^ Indicates whether or not we're in batch mode + -> Action () + -- ^ Action to perform on completion -> Prompt -editGoalieYtdLossesPrompt batchMode = +editGoalieYtdLossesPrompt batchMode cb = editNum "Year-to-date losses: " mode - (gYtd.gsLosses .~) + (gYtd.gsLosses .~) cb' where - mode = if batchMode then EGYtdTies else EGYtd + (mode, cb') = if batchMode + then (EGYtdTies, return ()) + else (EGYtd, cb) -- | Prompt to edit a goalie's YTD ties -editGoalieYtdTiesPrompt :: Prompt +editGoalieYtdTiesPrompt + :: Action () + -- ^ Action to perform on completion + -> Prompt editGoalieYtdTiesPrompt = editNum "Year-to-date ties: " EGYtd (gYtd.gsTies .~) @@ -138,70 +172,97 @@ editGoalieYtdTiesPrompt = editNum "Year-to-date ties: " EGYtd editGoalieLtGamesPrompt :: Bool -- ^ Indicates whether or not we're in batch mode + -> Action () + -- ^ Action to perform on completion -> Prompt -editGoalieLtGamesPrompt batchMode = +editGoalieLtGamesPrompt batchMode cb = editNum "Lifetime games played: " mode - (gLifetime.gsGames .~) + (gLifetime.gsGames .~) cb' where - mode = if batchMode then EGLtMins True else EGLifetime + (mode, cb') = if batchMode + then (EGLtMins True, return ()) + else (EGLifetime, cb) -- | Prompt to edit a goalie's lifetime minutes played editGoalieLtMinsPrompt :: Bool -- ^ Indicates whether or not we're in batch mode + -> Action () + -- ^ Action to perform on completion -> Prompt -editGoalieLtMinsPrompt batchMode = +editGoalieLtMinsPrompt batchMode cb = editNum "Lifetime minutes played: " mode - (gLifetime.gsMinsPlayed .~) + (gLifetime.gsMinsPlayed .~) cb' where - mode = if batchMode then EGLtGoals True else EGLifetime + (mode, cb') = if batchMode + then (EGLtGoals True, return ()) + else (EGLifetime, cb) -- | Prompt to edit a goalie's lifetime goals allowed editGoalieLtGoalsPrompt :: Bool -- ^ Indicates whether or not we're in batch mode + -> Action () + -- ^ Action to perform on completion -> Prompt -editGoalieLtGoalsPrompt batchMode = +editGoalieLtGoalsPrompt batchMode cb = editNum "Lifetime goals allowed: " mode - (gLifetime.gsGoalsAllowed .~) + (gLifetime.gsGoalsAllowed .~) cb' where - mode = if batchMode then EGLtShutouts True else EGLifetime + (mode, cb') = if batchMode + then (EGLtShutouts True, return ()) + else (EGLifetime, cb) -- | Prompt to edit a goalie's lifetime shutouts editGoalieLtShutoutsPrompt :: Bool -- ^ Indicates whether or not we're in batch mode + -> Action () + -- ^ Action to perform on completion -> Prompt -editGoalieLtShutoutsPrompt batchMode = +editGoalieLtShutoutsPrompt batchMode cb = editNum "Lifetime shutouts: " mode - (gLifetime.gsShutouts .~) + (gLifetime.gsShutouts .~) cb' where - mode = if batchMode then EGLtWins True else EGLifetime + (mode, cb') = if batchMode + then (EGLtWins True, return ()) + else (EGLifetime, cb) -- | Prompt to edit a goalie's lifetime wins editGoalieLtWinsPrompt :: Bool -- ^ Indicates whether or not we're in batch mode + -> Action () + -- ^ Action to perform on completion -> Prompt -editGoalieLtWinsPrompt batchMode = +editGoalieLtWinsPrompt batchMode cb = editNum "Lifetime wins: " mode - (gLifetime.gsWins .~) + (gLifetime.gsWins .~) cb' where - mode = if batchMode then EGLtLosses True else EGLifetime + (mode, cb') = if batchMode + then (EGLtLosses True, return ()) + else (EGLifetime, cb) -- | Prompt to edit a goalie's lifetime losses editGoalieLtLossesPrompt :: Bool -- ^ Indicates whether or not we're in batch mode + -> Action () + -- ^ Action to perform on completion -> Prompt -editGoalieLtLossesPrompt batchMode = +editGoalieLtLossesPrompt batchMode cb = editNum "Lifetime losses: " mode - (gLifetime.gsLosses .~) + (gLifetime.gsLosses .~) cb' where - mode = if batchMode then EGLtTies else EGLifetime + (mode, cb') = if batchMode + then (EGLtTies, return ()) + else (EGLifetime, cb) -- | Prompt to edit a goalie's lifetime ties -editGoalieLtTiesPrompt :: Prompt +editGoalieLtTiesPrompt + :: Action () + -- ^ Action to perform on completion + -> Prompt editGoalieLtTiesPrompt = editNum "Lifetime ties: " EGLifetime (gLifetime.gsTies .~) @@ -209,10 +270,13 @@ editNum :: String -> EditGoalieMode -> (Int -> Goalie -> Goalie) + -> Action () -> Prompt -editNum pStr mode f = numPromptWithFallback pStr - (goto mode) - (doEdit mode . f) +editNum pStr mode f cb = numPromptWithFallback pStr + (goto mode >> cb) + (\num -> do + doEdit mode $ f num + cb) doEdit :: EditGoalieMode -> (Goalie -> Goalie) -> Action () doEdit mode f = do From 5771091f18bd2ed2bcd04a81ac114bcc74330897 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 31 Jan 2020 21:23:22 -0500 Subject: [PATCH 4/5] edit lifetime stats on goalie creation --- src/Mtlstats/Control/CreateGoalie.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Mtlstats/Control/CreateGoalie.hs b/src/Mtlstats/Control/CreateGoalie.hs index 1514a2d..7f20116 100644 --- a/src/Mtlstats/Control/CreateGoalie.hs +++ b/src/Mtlstats/Control/CreateGoalie.hs @@ -24,7 +24,7 @@ module Mtlstats.Control.CreateGoalie (createGoalieC) where import Control.Monad (join) import Control.Monad.Trans.State (gets, modify) import Data.Maybe (fromJust) -import Lens.Micro ((^.)) +import Lens.Micro ((^.), (.~), (?~), (%~), to) import qualified UI.NCurses as C import Mtlstats.Actions @@ -69,8 +69,14 @@ confirmCreateGoalieC = Controller , handleController = \e -> do case ynHandler e of Just True -> do - modify addGoalie - join $ gets (^.progMode.createGoalieStateL.cgsSuccessCallback) + gid <- gets (^.database.dbGoalies.to length) + cb <- gets (^.progMode.createGoalieStateL.cgsSuccessCallback) + modify + $ (progMode.editGoalieStateL + %~ (egsSelectedGoalie ?~ gid) + . (egsMode .~ EGLtGames True) + . (egsCallback .~ cb)) + . addGoalie Just False -> join $ gets (^.progMode.createGoalieStateL.cgsFailureCallback) Nothing -> return () From ce2d32407e47668ac9df9b5f0aaf989ba3f1e450 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 31 Jan 2020 21:24:05 -0500 Subject: [PATCH 5/5] updated change log --- ChangeLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 5346e18..22040fb 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,7 +1,7 @@ # Changelog for mtlstats ## current -- Edit lifetime stats on new player creation +- Edit lifetime stats on new player/goalie creation ## 0.11.0 - Added active flag to players/goalies