From f235d13556440d9ae6e4cf0885f68e1794b81e61 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 8 Jul 2016 01:31:19 +0200 Subject: More logging --- sequence.cabal | 1 + sequence.nix | 10 +++++----- src/Main.hs | 5 +++-- src/Sequence/Utils.hs | 8 ++++++++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/sequence.cabal b/sequence.cabal index 931cba6..740a975 100644 --- a/sequence.cabal +++ b/sequence.cabal @@ -39,5 +39,6 @@ executable sequence , ansi-terminal , text , template + , regex-compat hs-source-dirs: src default-language: Haskell2010 \ No newline at end of file diff --git a/sequence.nix b/sequence.nix index ae75127..e0d93b7 100644 --- a/sequence.nix +++ b/sequence.nix @@ -1,8 +1,8 @@ { mkDerivation, ansi-terminal, base, bimap, case-insensitive , containers, data-default, directory, filepath, game-probability -, lens, mtl, readline, Shellac, Shellac-haskeline, stdenv -, table-layout, template, text, transformers, transformers-base -, xdg-basedir +, lens, mtl, readline, regex-compat, Shellac, Shellac-haskeline +, stdenv, table-layout, template, text, transformers +, transformers-base, xdg-basedir }: mkDerivation { pname = "sequence"; @@ -12,8 +12,8 @@ mkDerivation { isExecutable = true; executableHaskellDepends = [ ansi-terminal base bimap case-insensitive containers data-default - directory filepath game-probability lens mtl readline Shellac - Shellac-haskeline table-layout template text transformers + directory filepath game-probability lens mtl readline regex-compat + Shellac Shellac-haskeline table-layout template text transformers transformers-base xdg-basedir ]; license = stdenv.lib.licenses.mit; 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