diff options
author | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-11-12 22:25:47 +0100 |
---|---|---|
committer | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-11-12 22:25:47 +0100 |
commit | ec57713b3d4acea066c30cf4285339303860df01 (patch) | |
tree | b869a0fbe85e1f8498ac4484857f7b4b5f475188 /src/Sequence/Utils.hs | |
parent | cf4bda4d1c9a5e3e57c0b2682c7647d811a31740 (diff) | |
download | 2017-01-16_17:13:37-ec57713b3d4acea066c30cf4285339303860df01.tar 2017-01-16_17:13:37-ec57713b3d4acea066c30cf4285339303860df01.tar.gz 2017-01-16_17:13:37-ec57713b3d4acea066c30cf4285339303860df01.tar.bz2 2017-01-16_17:13:37-ec57713b3d4acea066c30cf4285339303860df01.tar.xz 2017-01-16_17:13:37-ec57713b3d4acea066c30cf4285339303860df01.zip |
Timers for use with probabilistic focus and without
Diffstat (limited to 'src/Sequence/Utils.hs')
-rw-r--r-- | src/Sequence/Utils.hs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/Sequence/Utils.hs b/src/Sequence/Utils.hs index fbf3c7d..bb29b86 100644 --- a/src/Sequence/Utils.hs +++ b/src/Sequence/Utils.hs | |||
@@ -1,10 +1,12 @@ | |||
1 | {-# LANGUAGE ViewPatterns, FlexibleContexts, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances, OverloadedStrings, OverloadedLists, RankNTypes #-} | 1 | {-# LANGUAGE ViewPatterns, FlexibleContexts, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances, OverloadedStrings, OverloadedLists, RankNTypes #-} |
2 | 2 | ||
3 | module Sequence.Utils | 3 | module Sequence.Utils |
4 | ( withArg, withFocus, withFocus' | 4 | ( TimerLength(..), TimerOrigin(..) |
5 | , withArg, withFocus, withFocus' | ||
5 | , focusState | 6 | , focusState |
6 | , toName, toDesc | 7 | , toName, toDesc |
7 | , outputLogged | 8 | , outputLogged |
9 | , scaleTimer | ||
8 | , Argument(..) | 10 | , Argument(..) |
9 | , Completion(..) | 11 | , Completion(..) |
10 | , module Sequence.Utils.Ask | 12 | , module Sequence.Utils.Ask |
@@ -50,6 +52,10 @@ import Sequence.Formula | |||
50 | 52 | ||
51 | import Text.Regex (mkRegex, subRegex) | 53 | import Text.Regex (mkRegex, subRegex) |
52 | 54 | ||
55 | data TimerLength = TimerLength TimerOrigin Int | ||
56 | |||
57 | data TimerOrigin = Absolute | Now | ||
58 | |||
53 | class Argument a st | a -> st where | 59 | class Argument a st | a -> st where |
54 | arg :: String -> Sh st (Maybe a) | 60 | arg :: String -> Sh st (Maybe a) |
55 | 61 | ||
@@ -93,6 +99,23 @@ outputLogged id str = gLog <>= pure (id, clean str) >> shellPutStrLn str | |||
93 | where | 99 | where |
94 | clean str = subRegex (mkRegex "(\x9B|\x1B\\[)[0-?]*[ -/]*[@-~]") str "" -- remove ANSI escapes | 100 | clean str = subRegex (mkRegex "(\x9B|\x1B\\[)[0-?]*[ -/]*[@-~]") str "" -- remove ANSI escapes |
95 | 101 | ||
102 | scaleTimer :: Int -> Rational -> Timer -> Timer | ||
103 | scaleTimer _ _ t@(Constant _) = t | ||
104 | scaleTimer (fromIntegral -> now) factor (Scaled r) = Scaled $ ((max 0 $ r - now) * factor) + now | ||
105 | |||
106 | instance Completion TimerLength GameState where | ||
107 | completableLabel _ = "<timer offset>" | ||
108 | complete _ st prefix = return [] | ||
109 | |||
110 | instance Argument TimerLength GameState where | ||
111 | arg str | ||
112 | | ('+':cs) <- str | ||
113 | , (Just n) <- readMaybe cs | ||
114 | , n >= 0 = return . Just $ TimerLength Now n | ||
115 | | (Just n) <- readMaybe str | ||
116 | , n >= 0 = return . Just $ TimerLength Absolute n | ||
117 | | otherwise = return Nothing | ||
118 | |||
96 | instance Completion EntityIdentifier GameState where | 119 | instance Completion EntityIdentifier GameState where |
97 | completableLabel _ = "<entity>" | 120 | completableLabel _ = "<entity>" |
98 | complete _ st prefix = return . filter ((isPrefixOf `on` CI.foldCase) prefix) . map ((evalState ?? st) . toName) . Map.keys $ st ^. gEntities | 121 | complete _ st prefix = return . filter ((isPrefixOf `on` CI.foldCase) prefix) . map ((evalState ?? st) . toName) . Map.keys $ st ^. gEntities |