From 736e78441ae8b0cffa610de4baa7248f726cf69c Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 10 Jun 2016 02:14:31 +0200 Subject: refactoring & combat rounds --- src/Main.hs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs index b7c6a6e..f46fd3e 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -32,6 +32,7 @@ import Data.Bool import Data.Function import Control.Monad.State.Strict +import Control.Monad.Trans.Maybe import Sequence.Types import Sequence.Contact.Types @@ -92,11 +93,11 @@ stateOutline st faction id = fromJust $ view eFaction <$> Map.lookup id (st ^. gEntities) factionIndex id = fromJust $ elemIndex (view faction' $ faction id) factions rowGs = do - rowGroup'@((review seqVal' -> seqVal, _):_) <- protoRows + rowGroup'@((seq, _):_) <- protoRows let rowGroup = map snd rowGroup' factionColumn i = [evalState ?? st $ toName x | x <- rowGroup, factionIndex x == i ] - return . colsAllG top $ [seqVal] : map factionColumn [0..(length factions - 1)] + return . colsAllG top $ [show $ view seqVal seq] : map factionColumn [0..(length factions - 1)] -- Query state listFactions, listEntities :: Sh GameState () @@ -195,12 +196,13 @@ factionSeqVal :: Completable Faction -> Sh GameState () factionSeqVal = withArg $ \qFaction -> use gEntities >>= mapM_ (entitySeqVal') . Map.keys . Map.filter ((==) qFaction . view eFaction) entitySeqVal' :: EntityIdentifier -> Sh GameState () -entitySeqVal' ident = do - entity <- preuse (gEntities . ix ident) - let sVal = preview (eStats . sSeqVal) =<< entity - case (,) <$> entity <*> sVal of - Nothing -> return () - Just (entity, sVal) -> do - name <- toName ident - (newEntity, view (seqVal . re _Just) -> val) <- evalFormula name entity sVal - gEntities . at ident .= Just (newEntity & set eSeqVal val) +entitySeqVal' ident = void . runMaybeT $ do + entity <- MaybeT $ preuse (gEntities . ix ident) + sVal <- MaybeT . return $ preview (eStats . sSeqVal) entity + name <- toName ident + round <- use gRound + (newEntity, sNum) <- evalFormula name entity sVal + let val = Just $ def + & set seqRound round + & set seqVal (Just sNum) + gEntities . at ident .= Just (newEntity & set eSeqVal val) -- cgit v1.2.3