made callbacks pure

This commit is contained in:
Jonathan Lamothe 2019-09-14 00:03:26 -04:00
parent 6ceb5415c5
commit 1a25c0dc92
3 changed files with 10 additions and 9 deletions

View File

@ -34,7 +34,6 @@ 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, (^.), (&), (.~), (?~), (%~), (+~))
@ -118,7 +117,7 @@ validateGameDate s = fromMaybe s $ do
-- | Starts player creation mode -- | Starts player creation mode
createPlayer :: ProgState -> ProgState createPlayer :: ProgState -> ProgState
createPlayer = let createPlayer = let
cb = modify $ progMode .~ MainMenu cb = progMode .~ MainMenu
cps cps
= newCreatePlayerState = newCreatePlayerState
& cpsSuccessCallback .~ cb & cpsSuccessCallback .~ cb

View File

@ -21,7 +21,7 @@ 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 (join, when) import Control.Monad (when)
import Control.Monad.Trans.State (gets, modify) import Control.Monad.Trans.State (gets, modify)
import Data.Char (toUpper) import Data.Char (toUpper)
import Data.Maybe (fromJust) import Data.Maybe (fromJust)
@ -238,8 +238,10 @@ confirmCreatePlayerC = Controller
case ynHandler e of case ynHandler e of
Just True -> do Just True -> do
modify addPlayer modify addPlayer
join $ gets (view $ progMode.createPlayerStateL.cpsSuccessCallback) gets (view $ progMode.createPlayerStateL.cpsSuccessCallback)
Just False -> join $ gets (view $ progMode.createPlayerStateL.cpsFailureCallback) >>= modify
Just False -> gets (view $ progMode.createPlayerStateL.cpsFailureCallback)
>>= modify
Nothing -> return () Nothing -> return ()
return True return True
} }

View File

@ -210,9 +210,9 @@ data CreatePlayerState = CreatePlayerState
-- ^ The player's name -- ^ The player's name
, _cpsPosition :: String , _cpsPosition :: String
-- ^ The player's position -- ^ The player's position
, _cpsSuccessCallback :: Action () , _cpsSuccessCallback :: ProgState -> ProgState
-- ^ The function to call on success -- ^ The function to call on success
, _cpsFailureCallback :: Action () , _cpsFailureCallback :: ProgState -> ProgState
-- ^ The function to call on failure -- ^ The function to call on failure
} }
@ -487,8 +487,8 @@ newCreatePlayerState = CreatePlayerState
{ _cpsNumber = Nothing { _cpsNumber = Nothing
, _cpsName = "" , _cpsName = ""
, _cpsPosition = "" , _cpsPosition = ""
, _cpsSuccessCallback = return () , _cpsSuccessCallback = id
, _cpsFailureCallback = return () , _cpsFailureCallback = id
} }
-- | Constructor for a 'Database' -- | Constructor for a 'Database'