From f235d13556440d9ae6e4cf0885f68e1794b81e61 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 8 Jul 2016 01:31:19 +0200 Subject: More logging --- src/Main.hs | 5 +++-- src/Sequence/Utils.hs | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Main.hs b/src/Main.hs index 449e21d..de90b80 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -297,6 +297,7 @@ entitySeqVal' ident = void . runMaybeT $ do & set seqVal (Just sNum) & set seqEpsilon (entity ^. eStats . sSeqEpsilon) gEntities . at ident .= Just (newEntity & set eSeqVal val) + gLog <>= pure (ident, "Sequence: " ++ show sNum) spendSeq :: Int -> String -> Sh GameState () spendSeq n logStr = withFocus $ \focusId -> do @@ -342,7 +343,7 @@ doShock dmg efLens = withFocus $ \focusId -> do lStats . efLens . seApplied .= True Effect (CI.original -> effectName) effect <- evalF . table $ cripple ^. seEffect lStats <~ (MaybeT . fmap join . runMaybeT $ evalF effect) - lift $ shellPutStrLn effectName + lift . outputLogged focusId $ "Effect: " ++ effectName lift . addNote $ "Effect: " ++ effectName takeHit :: Int -> Completable (Set Hitzone) -> Completable DamageType -> Sh GameState () @@ -355,7 +356,7 @@ takeHit dmg a1 a2 = flip withArg a1 $ \zones -> flip withArg a2 $ \dType -> with dmg' <- MaybeT . focusState lStats . evalFormula' [name] $ absorb armor dType dmg forM_ (Map.toList dmg') $ \(dType, dmg) -> lift . runMaybeT $ do guard $ dmg > 0 - lift $ shellPutStrLn $ name ++ " took " ++ show dmg ++ " " ++ show dType + lift . outputLogged focusId $ name ++ " took " ++ show dmg ++ " " ++ show dType case dType of Fatigue -> lStats . sFatigue += dmg _ -> lStats . sDamage . ix zone += dmg diff --git a/src/Sequence/Utils.hs b/src/Sequence/Utils.hs index 1d34a4f..fbf3c7d 100644 --- a/src/Sequence/Utils.hs +++ b/src/Sequence/Utils.hs @@ -4,6 +4,7 @@ module Sequence.Utils ( withArg, withFocus, withFocus' , focusState , toName, toDesc + , outputLogged , Argument(..) , Completion(..) , module Sequence.Utils.Ask @@ -47,6 +48,8 @@ import Sequence.Utils.Ask import Sequence.Contact.Types import Sequence.Formula +import Text.Regex (mkRegex, subRegex) + class Argument a st | a -> st where arg :: String -> Sh st (Maybe a) @@ -85,6 +88,11 @@ toDesc ident = do Just dmg -> return $ name ++ " " ++ show dmg Nothing -> return name +outputLogged :: EntityIdentifier -> String -> Sh GameState () +outputLogged id str = gLog <>= pure (id, clean str) >> shellPutStrLn str + where + clean str = subRegex (mkRegex "(\x9B|\x1B\\[)[0-?]*[ -/]*[@-~]") str "" -- remove ANSI escapes + instance Completion EntityIdentifier GameState where completableLabel _ = "" complete _ st prefix = return . filter ((isPrefixOf `on` CI.foldCase) prefix) . map ((evalState ?? st) . toName) . Map.keys $ st ^. gEntities -- cgit v1.2.3