diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-06-03 01:51:28 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-06-03 01:51:28 +0200 |
commit | e82a3a8c147b34b75a203f66f974f5b3ec21d98c (patch) | |
tree | 1597109533e3e21251da22126e224cd5c9188d13 /src/Sequence | |
parent | 49847034c56b105763a9d6d369f68a7d433ca521 (diff) | |
download | 2017-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')
-rw-r--r-- | src/Sequence/Types.hs | 4 | ||||
-rw-r--r-- | src/Sequence/Utils.hs | 17 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/Sequence/Types.hs b/src/Sequence/Types.hs index fd8d7ab..8895569 100644 --- a/src/Sequence/Types.hs +++ b/src/Sequence/Types.hs | |||
@@ -1,7 +1,7 @@ | |||
1 | {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeSynonymInstances, ViewPatterns, OverloadedStrings, TemplateHaskell, GeneralizedNewtypeDeriving #-} | 1 | {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeSynonymInstances, ViewPatterns, OverloadedStrings, TemplateHaskell, GeneralizedNewtypeDeriving #-} |
2 | 2 | ||
3 | module Sequence.Types | 3 | module Sequence.Types |
4 | ( GameState(..), gEntities, gEntityNames | 4 | ( GameState(..), gEntities, gEntityNames, gFocus |
5 | , Faction, faction, faction' | 5 | , Faction, faction, faction' |
6 | , SeqVal(..), seqVal | 6 | , SeqVal(..), seqVal |
7 | , Entity(..), eFaction, eSeqVal | 7 | , Entity(..), eFaction, eSeqVal |
@@ -81,6 +81,7 @@ makeLenses ''EntityIdentifier | |||
81 | data GameState = GameState | 81 | data GameState = GameState |
82 | { _gEntities :: Map EntityIdentifier Entity | 82 | { _gEntities :: Map EntityIdentifier Entity |
83 | , _gEntityNames :: Bimap EntityIdentifier EntityName | 83 | , _gEntityNames :: Bimap EntityIdentifier EntityName |
84 | , _gFocus :: Maybe EntityIdentifier | ||
84 | } | 85 | } |
85 | makeLenses ''GameState | 86 | makeLenses ''GameState |
86 | 87 | ||
@@ -88,6 +89,7 @@ instance Default GameState where | |||
88 | def = GameState | 89 | def = GameState |
89 | { _gEntities = def | 90 | { _gEntities = def |
90 | , _gEntityNames = Bimap.empty | 91 | , _gEntityNames = Bimap.empty |
92 | , _gFocus = Nothing | ||
91 | } | 93 | } |
92 | 94 | ||
93 | inhabitedFactions :: Getter GameState [Faction] | 95 | inhabitedFactions :: Getter GameState [Faction] |
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 | ||
3 | module Sequence.Utils | 3 | module Sequence.Utils |
4 | ( withArg, toName, fromName | 4 | ( withArg, withFocus |
5 | , askBool | ||
6 | , toName, fromName | ||
5 | ) where | 7 | ) where |
6 | 8 | ||
7 | import Sequence.Types | 9 | import Sequence.Types |
@@ -28,6 +30,7 @@ import Data.List | |||
28 | 30 | ||
29 | import System.Console.Shell | 31 | import System.Console.Shell |
30 | import System.Console.Shell.ShellMonad | 32 | import System.Console.Shell.ShellMonad |
33 | import System.Console.Shell.Backend.Haskeline | ||
31 | 34 | ||
32 | 35 | ||
33 | class Argument a st | a -> st where | 36 | class 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 | ||
44 | withFocus :: (EntityIdentifier -> Sh GameState ()) -> Sh GameState () | ||
45 | withFocus f = use gFocus >>= \focus -> case focus of | ||
46 | Nothing -> shellPutErrLn $ "Currently not focusing any entity" | ||
47 | Just id -> f id | ||
48 | |||
49 | askBool :: String -> Bool -> Sh st Bool | ||
50 | askBool 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 | |||
41 | unaligned = view faction' def | 56 | unaligned = view faction' def |
42 | 57 | ||
43 | toName :: MonadState GameState m => EntityIdentifier -> m String | 58 | toName :: MonadState GameState m => EntityIdentifier -> m String |