summaryrefslogtreecommitdiff
path: root/src/Sequence
diff options
context:
space:
mode:
Diffstat (limited to 'src/Sequence')
-rw-r--r--src/Sequence/Types.hs4
-rw-r--r--src/Sequence/Utils.hs17
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
3module Sequence.Types 3module 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
81data GameState = GameState 81data 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 }
85makeLenses ''GameState 86makeLenses ''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
93inhabitedFactions :: Getter GameState [Faction] 95inhabitedFactions :: 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
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