summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-06-10 14:20:08 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2016-06-10 14:20:08 +0200
commit486604532fa99fd294bb2d0c4166d815de6d4fde (patch)
tree03000fb1b99b75e94c0836e20180e9a82d578e66 /src/Main.hs
parentd8b49cbe1aff7cb3fcacac01d36128a248fc848b (diff)
download2017-01-16_17:13:37-486604532fa99fd294bb2d0c4166d815de6d4fde.tar
2017-01-16_17:13:37-486604532fa99fd294bb2d0c4166d815de6d4fde.tar.gz
2017-01-16_17:13:37-486604532fa99fd294bb2d0c4166d815de6d4fde.tar.bz2
2017-01-16_17:13:37-486604532fa99fd294bb2d0c4166d815de6d4fde.tar.xz
2017-01-16_17:13:37-486604532fa99fd294bb2d0c4166d815de6d4fde.zip
entity notes
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/Main.hs b/src/Main.hs
index e6d694a..36f2687 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -59,7 +59,10 @@ main = do
59 description = initialShellDescription 59 description = initialShellDescription
60 { historyFile = Just historyFile 60 { historyFile = Just historyFile
61 , prompt = \st -> return $ maybe "" (++ " ") ((evalState ?? st) . toName <$> view gFocus st) ++ "→ " 61 , prompt = \st -> return $ maybe "" (++ " ") ((evalState ?? st) . toName <$> view gFocus st) ++ "→ "
62 , beforePrompt = gets stateOutline >>= (\str -> if null str then return () else shellPutStrLn str) 62 , beforePrompt = do
63 { gets stateOutline >>= (\str -> if null str then return () else shellPutStr str)
64 ; gets focusNotes >>= (\str -> if null str then return () else shellPutStrLn str)
65 }
63 , commandStyle = OnlyCommands 66 , commandStyle = OnlyCommands
64 , shellCommands = [ exitCommand "exit" 67 , shellCommands = [ exitCommand "exit"
65 , helpCommand "help" 68 , helpCommand "help"
@@ -80,6 +83,7 @@ main = do
80 , cmd "combat'" factionSeqVal "Roll sequence values for all members of a faction and have them enter combat" 83 , cmd "combat'" factionSeqVal "Roll sequence values for all members of a faction and have them enter combat"
81 , cmd "spend" spendSeq "Spend some of the current focus´ AP" 84 , cmd "spend" spendSeq "Spend some of the current focus´ AP"
82 , cmd "delay" delay "Spend AP until the current focus´ sequence is no higher than the next highest" 85 , cmd "delay" delay "Spend AP until the current focus´ sequence is no higher than the next highest"
86 , cmd "note" addNote "Add a note to the current focus"
83 ] 87 ]
84 } 88 }
85 void $ runShell description haskelineBackend (def :: GameState) 89 void $ runShell description haskelineBackend (def :: GameState)
@@ -106,6 +110,15 @@ stateOutline st
106 roundStr n = show n ++ " Rounds later" 110 roundStr n = show n ++ " Rounds later"
107 factions = map (view faction') $ st ^. inhabitedFactions 111 factions = map (view faction') $ st ^. inhabitedFactions
108 112
113focusNotes :: GameState -> String
114focusNotes = maybe "" (unlines . map dotted) . preview (gFocus' . eNotes)
115 where
116 dotted "" = " • "
117 dotted str
118 | fstL : [] <- lines str = " • " ++ fstL
119 | fstL : tailL <- lines str = " • " ++ fstL ++ "\n" ++ unlines (map (" " ++ ) tailL)
120 | otherwise = ""
121
109-- Query state 122-- Query state
110listFactions, listEntities :: Sh GameState () 123listFactions, listEntities :: Sh GameState ()
111listFactions = use inhabitedFactions >>= mapM_ (shellPutStrLn . view faction') 124listFactions = use inhabitedFactions >>= mapM_ (shellPutStrLn . view faction')
@@ -119,7 +132,7 @@ blur = gFocus .= Nothing
119-- Manual focus 132-- Manual focus
120setFocus :: Completable EntityIdentifier -> Sh GameState () 133setFocus :: Completable EntityIdentifier -> Sh GameState ()
121setFocus = withArg $ \ident -> gFocus ?= ident 134setFocus = withArg $ \ident -> gFocus ?= ident
122 135
123-- Drop information 136-- Drop information
124remove :: Sh GameState () 137remove :: Sh GameState ()
125remove = withFocus $ \ident -> do 138remove = withFocus $ \ident -> do
@@ -228,3 +241,6 @@ delay = withFocus $ \focusId -> () <$ runMaybeT (delay' focusId)
228 focusSeq <- MaybeT . preuse $ gEntities . ix focusId . eStats . sSequence . _Just . seqVal . _Just 241 focusSeq <- MaybeT . preuse $ gEntities . ix focusId . eStats . sSequence . _Just . seqVal . _Just
229 guard $ focusSeq > tipSeq 242 guard $ focusSeq > tipSeq
230 lift . spendSeq $ focusSeq - tipSeq 243 lift . spendSeq $ focusSeq - tipSeq
244
245addNote :: String -> Sh GameState ()
246addNote note = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= (note :)