allow player creation callbacks to be impure
This commit is contained in:
parent
8277f8bac7
commit
11a66cfd33
|
@ -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, (^.), (&), (.~), (?~), (%~), (+~))
|
||||||
|
@ -117,7 +118,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 = progMode .~ MainMenu
|
cb = modify $ progMode .~ MainMenu
|
||||||
cps
|
cps
|
||||||
= newCreatePlayerState
|
= newCreatePlayerState
|
||||||
& cpsSuccessCallback .~ cb
|
& cpsSuccessCallback .~ cb
|
||||||
|
|
|
@ -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 (when)
|
import Control.Monad (join, 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)
|
||||||
|
@ -236,12 +236,11 @@ confirmCreatePlayerC = Controller
|
||||||
return C.CursorInvisible
|
return C.CursorInvisible
|
||||||
, handleController = \e -> do
|
, handleController = \e -> do
|
||||||
case ynHandler e of
|
case ynHandler e of
|
||||||
Just True -> do
|
Just True -> do
|
||||||
modify addPlayer
|
modify addPlayer
|
||||||
gets (view $ progMode.createPlayerStateL.cpsSuccessCallback)
|
join $ gets $ view $ progMode.createPlayerStateL.cpsSuccessCallback
|
||||||
>>= modify
|
Just False ->
|
||||||
Just False -> gets (view $ progMode.createPlayerStateL.cpsFailureCallback)
|
join $ gets $ view $ progMode.createPlayerStateL.cpsFailureCallback
|
||||||
>>= modify
|
Nothing -> return ()
|
||||||
Nothing -> return ()
|
|
||||||
return True
|
return True
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,9 +217,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 :: ProgState -> ProgState
|
, _cpsSuccessCallback :: Action ()
|
||||||
-- ^ The function to call on success
|
-- ^ The function to call on success
|
||||||
, _cpsFailureCallback :: ProgState -> ProgState
|
, _cpsFailureCallback :: Action ()
|
||||||
-- ^ The function to call on failure
|
-- ^ The function to call on failure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,8 +495,8 @@ newCreatePlayerState = CreatePlayerState
|
||||||
{ _cpsNumber = Nothing
|
{ _cpsNumber = Nothing
|
||||||
, _cpsName = ""
|
, _cpsName = ""
|
||||||
, _cpsPosition = ""
|
, _cpsPosition = ""
|
||||||
, _cpsSuccessCallback = id
|
, _cpsSuccessCallback = return ()
|
||||||
, _cpsFailureCallback = id
|
, _cpsFailureCallback = return ()
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Constructor for a 'Database'
|
-- | Constructor for a 'Database'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user