From 6ceb5415c50d2df12cd6dc12eb06a277e2e01ace Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 13 Sep 2019 23:54:36 -0400 Subject: [PATCH] use player creation callbacks --- src/Mtlstats/Actions.hs | 9 ++++++++- src/Mtlstats/Control.hs | 9 +++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Mtlstats/Actions.hs b/src/Mtlstats/Actions.hs index 951e236..ae38e64 100644 --- a/src/Mtlstats/Actions.hs +++ b/src/Mtlstats/Actions.hs @@ -34,6 +34,7 @@ module Mtlstats.Actions , addPlayer ) where +import Control.Monad.Trans.State (modify) import Data.Maybe (fromMaybe) import Data.Time.Calendar (fromGregorianValid) import Lens.Micro (over, (^.), (&), (.~), (?~), (%~), (+~)) @@ -116,7 +117,13 @@ validateGameDate s = fromMaybe s $ do -- | Starts player creation mode createPlayer :: ProgState -> ProgState -createPlayer = progMode .~ CreatePlayer newCreatePlayerState +createPlayer = let + cb = modify $ progMode .~ MainMenu + cps + = newCreatePlayerState + & cpsSuccessCallback .~ cb + & cpsFailureCallback .~ cb + in progMode .~ CreatePlayer cps -- | Adds the entered player to the roster addPlayer :: ProgState -> ProgState diff --git a/src/Mtlstats/Control.hs b/src/Mtlstats/Control.hs index edb8c42..3152dc3 100644 --- a/src/Mtlstats/Control.hs +++ b/src/Mtlstats/Control.hs @@ -21,11 +21,12 @@ along with this program. If not, see . module Mtlstats.Control (dispatch) where -import Control.Monad (when) -import Control.Monad.Trans.State (modify) +import Control.Monad (join, when) +import Control.Monad.Trans.State (gets, modify) import Data.Char (toUpper) import Data.Maybe (fromJust) import Lens.Micro ((^.), (.~)) +import Lens.Micro.Extras (view) import qualified UI.NCurses as C import Mtlstats.Actions @@ -237,8 +238,8 @@ confirmCreatePlayerC = Controller case ynHandler e of Just True -> do modify addPlayer - modify $ progMode .~ MainMenu - Just False -> modify $ progMode .~ MainMenu + join $ gets (view $ progMode.createPlayerStateL.cpsSuccessCallback) + Just False -> join $ gets (view $ progMode.createPlayerStateL.cpsFailureCallback) Nothing -> return () return True }