diff options
Diffstat (limited to 'src/Sequence/Utils.hs')
-rw-r--r-- | src/Sequence/Utils.hs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/Sequence/Utils.hs b/src/Sequence/Utils.hs index 9f03ca7..667d520 100644 --- a/src/Sequence/Utils.hs +++ b/src/Sequence/Utils.hs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | module Sequence.Utils | 3 | module Sequence.Utils |
4 | ( TimerLength(..), TimerOrigin(..) | 4 | ( TimerLength(..), TimerOrigin(..) |
5 | , withArg, withFocus, withFocus' | 5 | , withArg, (<~>), withFocus, withFocus' |
6 | , focusState | 6 | , focusState |
7 | , toName, toDesc | 7 | , toName, toDesc |
8 | , outputLogged | 8 | , outputLogged |
@@ -65,6 +65,10 @@ withArg f (Completable str) = arg str >>= \a -> case a of | |||
65 | Nothing -> shellPutErrLn $ "Could not parse ‘" ++ str ++ "’" | 65 | Nothing -> shellPutErrLn $ "Could not parse ‘" ++ str ++ "’" |
66 | Just a -> f a | 66 | Just a -> f a |
67 | 67 | ||
68 | infixr 0 <~> | ||
69 | (<~>) :: Argument a st => Completable a -> (a -> Sh st ()) -> Sh st () | ||
70 | (<~>) = flip withArg | ||
71 | |||
68 | withFocus :: (EntityIdentifier -> Sh GameState ()) -> Sh GameState () | 72 | withFocus :: (EntityIdentifier -> Sh GameState ()) -> Sh GameState () |
69 | withFocus f = use gFocus >>= maybe (shellPutErrLn $ "Currently not focusing any entity") f | 73 | withFocus f = use gFocus >>= maybe (shellPutErrLn $ "Currently not focusing any entity") f |
70 | 74 | ||
@@ -178,9 +182,12 @@ instance Completion (Formula Stats) GameState where | |||
178 | complete _ st (CI.foldCase -> prefix) = return . map CI.original . filter ((prefix `isPrefixOf`) . CI.foldedCase) . Map.keys $ Map.filter (isJust . (\a -> preview (gFocus' . eStats . folding a) st)) statAccessors | 182 | complete _ st (CI.foldCase -> prefix) = return . map CI.original . filter ((prefix `isPrefixOf`) . CI.foldedCase) . Map.keys $ Map.filter (isJust . (\a -> preview (gFocus' . eStats . folding a) st)) statAccessors |
179 | 183 | ||
180 | instance Argument (Formula Stats) GameState where | 184 | instance Argument (Formula Stats) GameState where |
181 | arg (CI.mk -> name) = runMaybeT $ do | 185 | arg (CI.mk -> name) = runMaybeT $ fromAccessor `mplus` fromNumber |
182 | accessor <- MaybeT . return $ Map.lookup name statAccessors | 186 | where |
183 | MaybeT . preuse $ gFocus' . eStats . folding accessor | 187 | fromAccessor = do |
188 | accessor <- MaybeT . return $ Map.lookup name statAccessors | ||
189 | MaybeT . preuse $ gFocus' . eStats . folding accessor | ||
190 | fromNumber = MaybeT . return . fmap fromInteger . (readMaybe :: String -> Maybe Integer) $ CI.original name | ||
184 | 191 | ||
185 | statAccessors :: Map (CI String) (Stats -> Maybe (Formula Stats)) | 192 | statAccessors :: Map (CI String) (Stats -> Maybe (Formula Stats)) |
186 | statAccessors = [ ("Stärke", preview sAStrength) | 193 | statAccessors = [ ("Stärke", preview sAStrength) |