summaryrefslogtreecommitdiff
path: root/src/Sequence/Utils.hs
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-06-03 01:51:28 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2016-06-03 01:51:28 +0200
commite82a3a8c147b34b75a203f66f974f5b3ec21d98c (patch)
tree1597109533e3e21251da22126e224cd5c9188d13 /src/Sequence/Utils.hs
parent49847034c56b105763a9d6d369f68a7d433ca521 (diff)
download2017-01-16_17:13:37-e82a3a8c147b34b75a203f66f974f5b3ec21d98c.tar
2017-01-16_17:13:37-e82a3a8c147b34b75a203f66f974f5b3ec21d98c.tar.gz
2017-01-16_17:13:37-e82a3a8c147b34b75a203f66f974f5b3ec21d98c.tar.bz2
2017-01-16_17:13:37-e82a3a8c147b34b75a203f66f974f5b3ec21d98c.tar.xz
2017-01-16_17:13:37-e82a3a8c147b34b75a203f66f974f5b3ec21d98c.zip
focus
Diffstat (limited to 'src/Sequence/Utils.hs')
-rw-r--r--src/Sequence/Utils.hs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/Sequence/Utils.hs b/src/Sequence/Utils.hs
index aa92081..aea853d 100644
--- a/src/Sequence/Utils.hs
+++ b/src/Sequence/Utils.hs
@@ -1,7 +1,9 @@
1{-# LANGUAGE ViewPatterns, FlexibleContexts, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances #-} 1{-# LANGUAGE ViewPatterns, FlexibleContexts, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances #-}
2 2
3module Sequence.Utils 3module Sequence.Utils
4 ( withArg, toName, fromName 4 ( withArg, withFocus
5 , askBool
6 , toName, fromName
5 ) where 7 ) where
6 8
7import Sequence.Types 9import Sequence.Types
@@ -28,6 +30,7 @@ import Data.List
28 30
29import System.Console.Shell 31import System.Console.Shell
30import System.Console.Shell.ShellMonad 32import System.Console.Shell.ShellMonad
33import System.Console.Shell.Backend.Haskeline
31 34
32 35
33class Argument a st | a -> st where 36class Argument a st | a -> st where
@@ -38,6 +41,18 @@ withArg f (Completable str) = arg str >>= \a -> case a of
38 Nothing -> shellPutErrLn $ "Could not parse ‘" ++ str ++ "’" 41 Nothing -> shellPutErrLn $ "Could not parse ‘" ++ str ++ "’"
39 Just a -> f a 42 Just a -> f a
40 43
44withFocus :: (EntityIdentifier -> Sh GameState ()) -> Sh GameState ()
45withFocus f = use gFocus >>= \focus -> case focus of
46 Nothing -> shellPutErrLn $ "Currently not focusing any entity"
47 Just id -> f id
48
49askBool :: String -> Bool -> Sh st Bool
50askBool prompt initial = liftIO $ runShell (initialShellDescription { shellCommands = [cmd "y" yes "yes", cmd "n" no "no"], commandStyle = SingleCharCommands, prompt = const $ return prompt, historyEnabled = False }) haskelineBackend initial
51 where
52 yes, no :: Sh Bool ()
53 yes = put True
54 no = put False
55
41unaligned = view faction' def 56unaligned = view faction' def
42 57
43toName :: MonadState GameState m => EntityIdentifier -> m String 58toName :: MonadState GameState m => EntityIdentifier -> m String