summaryrefslogtreecommitdiff
path: root/src/Sequence/Utils.hs
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-11-12 22:25:47 +0100
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-11-12 22:25:47 +0100
commitec57713b3d4acea066c30cf4285339303860df01 (patch)
treeb869a0fbe85e1f8498ac4484857f7b4b5f475188 /src/Sequence/Utils.hs
parentcf4bda4d1c9a5e3e57c0b2682c7647d811a31740 (diff)
download2017-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.hs25
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
3module Sequence.Utils 3module 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
51import Text.Regex (mkRegex, subRegex) 53import Text.Regex (mkRegex, subRegex)
52 54
55data TimerLength = TimerLength TimerOrigin Int
56
57data TimerOrigin = Absolute | Now
58
53class Argument a st | a -> st where 59class 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
102scaleTimer :: Int -> Rational -> Timer -> Timer
103scaleTimer _ _ t@(Constant _) = t
104scaleTimer (fromIntegral -> now) factor (Scaled r) = Scaled $ ((max 0 $ r - now) * factor) + now
105
106instance Completion TimerLength GameState where
107 completableLabel _ = "<timer offset>"
108 complete _ st prefix = return []
109
110instance 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
96instance Completion EntityIdentifier GameState where 119instance 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