summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-07-08 01:31:48 +0200
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-07-08 01:32:01 +0200
commit384f07dd08569212c0384b299b7824ba4f36ba55 (patch)
treecfb26401684aeaa49f2294b641e33cd4744e4a38 /src
parentf235d13556440d9ae6e4cf0885f68e1794b81e61 (diff)
download2017-01-16_17:13:37-384f07dd08569212c0384b299b7824ba4f36ba55.tar
2017-01-16_17:13:37-384f07dd08569212c0384b299b7824ba4f36ba55.tar.gz
2017-01-16_17:13:37-384f07dd08569212c0384b299b7824ba4f36ba55.tar.bz2
2017-01-16_17:13:37-384f07dd08569212c0384b299b7824ba4f36ba55.tar.xz
2017-01-16_17:13:37-384f07dd08569212c0384b299b7824ba4f36ba55.zip
Better tests
Diffstat (limited to 'src')
-rw-r--r--src/Main.hs23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/Main.hs b/src/Main.hs
index de90b80..55c0d8b 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -257,9 +257,15 @@ spawnFaction cFaction num cEntity nameTemplate
257 257
258-- Dice rolls 258-- Dice rolls
259rollTest :: Completable (FormulaM Stats Test) -> Sh GameState () 259rollTest :: Completable (FormulaM Stats Test) -> Sh GameState ()
260rollTest = withArg $ enactTest' >=> maybe (return ()) (shellPutStrLn . ppResult) 260rollTest = withArg $ maybe (return ()) outputResult <=< enactTest'
261 where 261 where
262 ppResult result = pad 3 (show $ result^.rWith) ++ ": " ++ setSGRCode (colour result) ++ name result ++ setSGRCode [] ++ " by " ++ pad 2 (show $ result^.rBy) ++ "pp" 262 outputResult :: (String, TestResult) -> Sh GameState ()
263 outputResult (test, ppResult -> result) = do
264 focusId <- use gFocus
265 case focusId of
266 Nothing -> shellPutStrLn result
267 Just id -> outputLogged id $ test ++ ": " ++ result
268 ppResult result = pad 3 (show $ result^.rWith) ++ " → " ++ setSGRCode (colour result) ++ name result ++ setSGRCode [] ++ " by " ++ pad 2 (show $ result^.rBy) ++ "pp"
263 colour CritSuccess{..} = [SetColor Foreground Vivid Green, SetConsoleIntensity BoldIntensity] 269 colour CritSuccess{..} = [SetColor Foreground Vivid Green, SetConsoleIntensity BoldIntensity]
264 colour Success{..} = [SetColor Foreground Dull Green] 270 colour Success{..} = [SetColor Foreground Dull Green]
265 colour Failure{..} = [SetColor Foreground Dull Red] 271 colour Failure{..} = [SetColor Foreground Dull Red]
@@ -272,12 +278,13 @@ rollTest = withArg $ enactTest' >=> maybe (return ()) (shellPutStrLn . ppResult)
272 | length str >= n = str 278 | length str >= n = str
273 | otherwise = ' ' : pad (n - 1) str 279 | otherwise = ' ' : pad (n - 1) str
274 280
275enactTest' :: (FormulaM Stats Test) -> Sh GameState (Maybe TestResult) 281enactTest' :: FormulaM Stats Test -> Sh GameState (Maybe (String, TestResult))
276enactTest' test = withFocus' $ \focus -> do 282enactTest' test = runMaybeT $ do
277 focusName <- use gFocus >>= toName . fromJust 283 focusName <- MaybeT (use gFocus) >>= lift . toName
278 (newFocus, result) <- evalFormula [focusName] focus (enactTest =<< test) 284 let evalF = MaybeT . focusState (gFocus' . eStats) . evalFormula' [focusName]
279 gFocus' .= newFocus 285 test' <- evalF test
280 return result 286 result <- evalF $ enactTest test'
287 return (view (tName . to CI.original) test', result)
281 288
282entitySeqVal :: Sh GameState () 289entitySeqVal :: Sh GameState ()
283entitySeqVal = withFocus entitySeqVal' 290entitySeqVal = withFocus entitySeqVal'