Safe Haskell | Safe-Infered |
---|
Game action monad and basic building blocks for player and monster actions.
- type ActionFun r a = Session -> DungeonPerception -> (State -> Diary -> a -> IO r) -> (Msg -> IO r) -> State -> Diary -> IO r
- data Action a
- handlerToIO :: Session -> State -> Diary -> Action () -> IO ()
- rndToAction :: Rnd a -> Action a
- type ActionFrame a = Action (a, [Maybe SingleFrame])
- returnNoFrame :: a -> ActionFrame a
- whenFrame :: Bool -> ActionFrame () -> ActionFrame ()
- inFrame :: Action () -> ActionFrame ()
- data Session = Session {
- sfs :: FrontendSession
- scops :: COps
- skeyb :: Binding (ActionFrame ())
- getCOps :: Action COps
- getBinding :: Action (Binding (ActionFrame ()))
- abort :: Action a
- abortWith :: Msg -> Action a
- abortIfWith :: Bool -> Msg -> Action a
- neverMind :: Bool -> Action a
- tryWith :: (Msg -> Action a) -> Action a -> Action a
- tryWithFrame :: Action a -> ActionFrame a -> ActionFrame a
- tryRepeatedlyWith :: (Msg -> Action ()) -> Action () -> Action ()
- tryIgnore :: Action () -> Action ()
- tryIgnoreFrame :: ActionFrame () -> ActionFrame ()
- getDiary :: Action Diary
- msgAdd :: Msg -> Action ()
- recordHistory :: Action ()
- getKeyCommand :: Maybe Bool -> Action (Key, Modifier)
- getKeyChoice :: [(Key, Modifier)] -> SingleFrame -> Action (Key, Modifier)
- getOverConfirm :: [SingleFrame] -> Action Bool
- displayMore :: ColorMode -> Msg -> Action Bool
- displayYesNo :: Msg -> Action Bool
- displayOverAbort :: Msg -> [Overlay] -> Action ()
- displayOverlays :: Msg -> [Overlay] -> ActionFrame ()
- displayChoiceUI :: Msg -> [Overlay] -> [(Key, Modifier)] -> Action (Key, Modifier)
- displayFramePush :: Maybe SingleFrame -> Action ()
- drawPrompt :: ColorMode -> Msg -> Action SingleFrame
- startClip :: Action () -> Action ()
- remember :: Action ()
- rememberList :: [Point] -> Action ()
- getPerception :: Action Perception
- updateAnyActor :: ActorId -> (Actor -> Actor) -> Action ()
- updatePlayerBody :: (Actor -> Actor) -> Action ()
- currentDate :: Action ClockTime
- saveGameBkp :: State -> Diary -> Action ()
- dumpCfg :: FilePath -> CP -> Action ()
- shutGame :: (Bool, Status) -> Action ()
- debug :: String -> 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.
rndToAction :: Rnd a -> Action aSource
Invoke pseudo-random computation with the generator kept in the state.
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.
whenFrame :: Bool -> ActionFrame () -> ActionFrame ()Source
As the when
monad operation, but on type ActionFrame ()
.
Game session and its accessors
The constant session information, not saved to the game save file.
Session | |
|
getBinding :: Action (Binding (ActionFrame ()))Source
Get the key binding.
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.
tryWithFrame :: Action a -> ActionFrame a -> ActionFrame aSource
Set the current exception handler. Apart of executing it, draw and pass along a frame with the abort message, if any.
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.
tryIgnoreFrame :: ActionFrame () -> ActionFrame ()Source
Try the given computation and silently catch failure, returning empty set of screen frames.
Diary and report
recordHistory :: Action ()Source
Store current report in the history and reset report.
Key input
getKeyChoice :: [(Key, Modifier)] -> SingleFrame -> Action (Key, Modifier)Source
Wait for a player keypress.
getOverConfirm :: [SingleFrame] -> Action BoolSource
A series of confirmations for all overlays.
Display each frame and confirm
displayMore :: ColorMode -> Msg -> Action BoolSource
Display a msg with a more
prompt. Return value indicates if the player
tried to cancel/escape.
displayYesNo :: Msg -> Action BoolSource
Print a yes/no question and return the player's answer. Use black and white colours to turn player's attention to the choice.
displayOverAbort :: Msg -> [Overlay] -> Action ()Source
Print a msg and several overlays, one per page.
All frames require confirmations. Raise abort
if the players presses ESC.
Assorted frame operations
displayOverlays :: Msg -> [Overlay] -> ActionFrame ()Source
Print a msg and several overlays, one per page. The last frame does not expect a confirmation.
displayChoiceUI :: Msg -> [Overlay] -> [(Key, Modifier)] -> Action (Key, Modifier)Source
Print a prompt and an overlay and wait for a player keypress.
If many overlays, scroll screenfuls with SPACE. Do not wrap screenfuls
(in some menus ?
cycles views, so the user can restart from the top).
displayFramePush :: Maybe SingleFrame -> Action ()Source
Push a frame or a single frame's worth of delay to the frame queue.
drawPrompt :: ColorMode -> Msg -> Action SingleFrameSource
Draw the current level. The prompt is displayed, but not added to history. The prompt is appended to the current message and only the first screenful of the resulting overlay is displayed.
Clip init operations
startClip :: Action () -> Action ()Source
Initialize perception, etc., display level and run the action.
rememberList :: [Point] -> Action ()Source
Update player at the given list of locations..
Assorted operations
getPerception :: Action PerceptionSource
Get the current perception.
updateAnyActor :: ActorId -> (Actor -> Actor) -> Action ()Source
Update actor stats. Works for actors on other levels, too.
Assorted primitives
currentDate :: Action ClockTimeSource
Obtains the current date and time.
saveGameBkp :: State -> Diary -> Action ()Source
Save the diary and a backup of the save game file, in case of crashes.
See saveGameBkp
.