From cc4e079be3d0e918119c08301595460c3e91ef3c Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 2 Dec 2016 13:26:55 +0100 Subject: Print all applicable values --- src/Main.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs index 9a51332..1c2afd4 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -114,6 +114,7 @@ main = do , cmd "heal'" healFatigue "Heal the focused entity of fatigue" , cmd "log" dumpLog "Print the combat log" , cmd "val" printVal "Find the distribution of a specific value of the current entities" + , cmd "summary" printVals "Find the averages of applicable all values" ] , wordBreakChars = wordBreakChars initialShellDescription \\ [',', '\''] } @@ -572,3 +573,16 @@ printVal = withArg $ \formula -> withFocus $ \focusId -> do lengths = map (length . show . fst) vals -- normalize p = p / maximum (map snd vals) normalize = id + +printVals :: Sh GameState () +printVals = withFocus $ \focusId -> do + name <- toName focusId + sheet <- Map.mapMaybe id <$> mapM (\l -> preuse $ gFocus' . eStats . to l . _Just) statAccessors + let + maxLength = maximum . map (length . CI.original) $ Map.keys sheet + printAvg (str, formula) = do + result <- focusState (gFocus' . eStats) (findAverage [name] formula) + case result of + Just avg -> shellPutStrLn $ printf "%*s: %.2f" maxLength (CI.original str) (fromRational avg :: Double) + Nothing -> return () + mapM_ printAvg $ Map.toList sheet -- cgit v1.2.3