diff options
author | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2017-01-16 18:10:17 +0100 |
---|---|---|
committer | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2017-01-16 18:10:17 +0100 |
commit | ce890f4b6fd478bf5a254390f5bc49e4afd97c8c (patch) | |
tree | fb5a239a32b610470cbefbd279f465df89c5f5f1 /src/Sequence/Utils.hs | |
parent | 7ff2052235140669bc9e9c5c1e94b194626dee67 (diff) | |
download | 2017-01-16_17:13:37-ce890f4b6fd478bf5a254390f5bc49e4afd97c8c.tar 2017-01-16_17:13:37-ce890f4b6fd478bf5a254390f5bc49e4afd97c8c.tar.gz 2017-01-16_17:13:37-ce890f4b6fd478bf5a254390f5bc49e4afd97c8c.tar.bz2 2017-01-16_17:13:37-ce890f4b6fd478bf5a254390f5bc49e4afd97c8c.tar.xz 2017-01-16_17:13:37-ce890f4b6fd478bf5a254390f5bc49e4afd97c8c.zip |
Burstfirerewrite
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) |