use player creation callbacks

This commit is contained in:
Jonathan Lamothe 2019-09-13 23:54:36 -04:00
parent 6dd9350189
commit 6ceb5415c5
2 changed files with 13 additions and 5 deletions

View File

@ -34,6 +34,7 @@ module Mtlstats.Actions
, addPlayer , addPlayer
) where ) where
import Control.Monad.Trans.State (modify)
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Data.Time.Calendar (fromGregorianValid) import Data.Time.Calendar (fromGregorianValid)
import Lens.Micro (over, (^.), (&), (.~), (?~), (%~), (+~)) import Lens.Micro (over, (^.), (&), (.~), (?~), (%~), (+~))
@ -116,7 +117,13 @@ validateGameDate s = fromMaybe s $ do
-- | Starts player creation mode -- | Starts player creation mode
createPlayer :: ProgState -> ProgState 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 -- | Adds the entered player to the roster
addPlayer :: ProgState -> ProgState addPlayer :: ProgState -> ProgState

View File

@ -21,11 +21,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats.Control (dispatch) where module Mtlstats.Control (dispatch) where
import Control.Monad (when) import Control.Monad (join, when)
import Control.Monad.Trans.State (modify) import Control.Monad.Trans.State (gets, modify)
import Data.Char (toUpper) import Data.Char (toUpper)
import Data.Maybe (fromJust) import Data.Maybe (fromJust)
import Lens.Micro ((^.), (.~)) import Lens.Micro ((^.), (.~))
import Lens.Micro.Extras (view)
import qualified UI.NCurses as C import qualified UI.NCurses as C
import Mtlstats.Actions import Mtlstats.Actions
@ -237,8 +238,8 @@ confirmCreatePlayerC = Controller
case ynHandler e of case ynHandler e of
Just True -> do Just True -> do
modify addPlayer modify addPlayer
modify $ progMode .~ MainMenu join $ gets (view $ progMode.createPlayerStateL.cpsSuccessCallback)
Just False -> modify $ progMode .~ MainMenu Just False -> join $ gets (view $ progMode.createPlayerStateL.cpsFailureCallback)
Nothing -> return () Nothing -> return ()
return True return True
} }