allow player creation callbacks to be impure
This commit is contained in:
parent
8277f8bac7
commit
11a66cfd33
|
@ -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, (^.), (&), (.~), (?~), (%~), (+~))
|
||||
|
@ -117,7 +118,7 @@ validateGameDate s = fromMaybe s $ do
|
|||
-- | Starts player creation mode
|
||||
createPlayer :: ProgState -> ProgState
|
||||
createPlayer = let
|
||||
cb = progMode .~ MainMenu
|
||||
cb = modify $ progMode .~ MainMenu
|
||||
cps
|
||||
= newCreatePlayerState
|
||||
& cpsSuccessCallback .~ cb
|
||||
|
|
|
@ -21,7 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
module Mtlstats.Control (dispatch) where
|
||||
|
||||
import Control.Monad (when)
|
||||
import Control.Monad (join, when)
|
||||
import Control.Monad.Trans.State (gets, modify)
|
||||
import Data.Char (toUpper)
|
||||
import Data.Maybe (fromJust)
|
||||
|
@ -236,12 +236,11 @@ confirmCreatePlayerC = Controller
|
|||
return C.CursorInvisible
|
||||
, handleController = \e -> do
|
||||
case ynHandler e of
|
||||
Just True -> do
|
||||
Just True -> do
|
||||
modify addPlayer
|
||||
gets (view $ progMode.createPlayerStateL.cpsSuccessCallback)
|
||||
>>= modify
|
||||
Just False -> gets (view $ progMode.createPlayerStateL.cpsFailureCallback)
|
||||
>>= modify
|
||||
Nothing -> return ()
|
||||
join $ gets $ view $ progMode.createPlayerStateL.cpsSuccessCallback
|
||||
Just False ->
|
||||
join $ gets $ view $ progMode.createPlayerStateL.cpsFailureCallback
|
||||
Nothing -> return ()
|
||||
return True
|
||||
}
|
||||
|
|
|
@ -217,9 +217,9 @@ data CreatePlayerState = CreatePlayerState
|
|||
-- ^ The player's name
|
||||
, _cpsPosition :: String
|
||||
-- ^ The player's position
|
||||
, _cpsSuccessCallback :: ProgState -> ProgState
|
||||
, _cpsSuccessCallback :: Action ()
|
||||
-- ^ The function to call on success
|
||||
, _cpsFailureCallback :: ProgState -> ProgState
|
||||
, _cpsFailureCallback :: Action ()
|
||||
-- ^ The function to call on failure
|
||||
}
|
||||
|
||||
|
@ -495,8 +495,8 @@ newCreatePlayerState = CreatePlayerState
|
|||
{ _cpsNumber = Nothing
|
||||
, _cpsName = ""
|
||||
, _cpsPosition = ""
|
||||
, _cpsSuccessCallback = id
|
||||
, _cpsFailureCallback = id
|
||||
, _cpsSuccessCallback = return ()
|
||||
, _cpsFailureCallback = return ()
|
||||
}
|
||||
|
||||
-- | Constructor for a 'Database'
|
||||
|
|
Loading…
Reference in New Issue
Block a user