Safe Haskell | None |
---|
Game action monad and basic building blocks for player and monster
actions. Exports liftIO
for injecting IO
into the Action
monad,
but does not export the implementation of the Action monad.
The liftIO
and handlerToIO
operations are used only in Action.hs.
- type ActionFun r a = Session -> DungeonPerception -> (State -> Diary -> a -> IO r) -> (Msg -> IO r) -> State -> Diary -> IO r
- data Action a
- liftIO :: IO a -> Action a
- handlerToIO :: Session -> State -> Diary -> Action () -> IO ()
- withPerception :: Action () -> Action ()
- getPerception :: Action Perception
- type ActionFrame a = Action (a, [Maybe SingleFrame])
- returnNoFrame :: a -> ActionFrame a
- returnFrame :: SingleFrame -> ActionFrame ()
- whenFrame :: Bool -> ActionFrame () -> ActionFrame ()
- inFrame :: Action () -> ActionFrame ()
- data Session = Session {
- sfs :: FrontendSession
- scops :: COps
- sbinding :: Binding (ActionFrame ())
- sconfigUI :: ConfigUI
- getFrontendSession :: Action FrontendSession
- getCOps :: Action COps
- getBinding :: Action (Binding (ActionFrame ()))
- getConfigUI :: Action ConfigUI
- abort :: Action a
- abortWith :: Msg -> Action a
- abortIfWith :: Bool -> Msg -> Action a
- neverMind :: Bool -> Action a
- tryWith :: (Msg -> Action a) -> Action a -> Action a
- tryRepeatedlyWith :: (Msg -> Action ()) -> Action () -> Action ()
- tryIgnore :: Action () -> Action ()
- getDiary :: Action Diary
- msgAdd :: Msg -> Action ()
- historyReset :: History -> Action ()
- msgReset :: Msg -> Action ()
Actions and basic operations
= Session | session setup data |
-> DungeonPerception | cached perception |
-> (State -> Diary -> a -> IO r) | continuation |
-> (Msg -> IO r) | failure/reset continuation |
-> State | current state |
-> Diary | current diary |
-> IO r |
The type of the function inside any action.
(Separated from the Action
type to document each argument with haddock.)
Actions of player-controlled characters and of any other actors.
handlerToIO :: Session -> State -> Diary -> Action () -> IO ()Source
Run an action, with a given session, state and diary, in the IO
monad.
withPerception :: Action () -> Action ()Source
Update the cached perception for the given computation.
getPerception :: Action PerceptionSource
Get the current perception.
Actions returning frames
type ActionFrame a = Action (a, [Maybe SingleFrame])Source
Actions and screen frames, including delays, resulting from performing the actions.
returnNoFrame :: a -> ActionFrame aSource
Return the value with an empty set of screen frames.
returnFrame :: SingleFrame -> ActionFrame ()Source
Return the trivial value with a single frame to show.
whenFrame :: Bool -> ActionFrame () -> ActionFrame ()Source
As the when
monad operation, but on type ActionFrame ()
.
inFrame :: Action () -> ActionFrame ()Source
Inject action into actions with screen frames.
Game session and assessors to its components
The information that is constant across a playing session, including many consecutive games in a single session, but is completely disregarded and reset when a new playing session starts.
Session | |
|
getFrontendSession :: Action FrontendSessionSource
Get the frontend session.
getBinding :: Action (Binding (ActionFrame ()))Source
Get the key binding.
getConfigUI :: Action ConfigUISource
Get the config from the config file.
Various ways to abort action
Reset the state and resume from the last backup point, i.e., invoke the failure continuation.
abortIfWith :: Bool -> Msg -> Action aSource
Abort and print the given msg if the condition is true.
Abort exception handlers
tryWith :: (Msg -> Action a) -> Action a -> Action aSource
Set the current exception handler. First argument is the handler, second is the computation the handler scopes over.
tryRepeatedlyWith :: (Msg -> Action ()) -> Action () -> Action ()Source
Take a handler and a computation. If the computation fails, the handler is invoked and then the computation is retried.
Diary and report
historyReset :: History -> Action ()Source
Wipe out and set a new value for the history.