summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-07-10 19:15:18 +0200
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-07-10 19:15:18 +0200
commit9983d6cfc0eebf0dff720a285db3b0f180c8b854 (patch)
treec9d73f686101de7974e306a3d1f4d5391f2a7e96
parent7bd64df07668883920be7e0bf9d6eaea96dfba12 (diff)
download2017-01-16_17:13:37-9983d6cfc0eebf0dff720a285db3b0f180c8b854.tar
2017-01-16_17:13:37-9983d6cfc0eebf0dff720a285db3b0f180c8b854.tar.gz
2017-01-16_17:13:37-9983d6cfc0eebf0dff720a285db3b0f180c8b854.tar.bz2
2017-01-16_17:13:37-9983d6cfc0eebf0dff720a285db3b0f180c8b854.tar.xz
2017-01-16_17:13:37-9983d6cfc0eebf0dff720a285db3b0f180c8b854.zip
allow deletion of notes
-rw-r--r--src/Main.hs28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/Main.hs b/src/Main.hs
index ace3ef2..8f44db8 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -98,6 +98,7 @@ main = do
98 , cmd "spend" spendSeq "Spend some of the current focus´ AP" 98 , cmd "spend" spendSeq "Spend some of the current focus´ AP"
99 , cmd "delay" delay "Spend AP until the current focus´ sequence is no higher than the next highest and focus that one" 99 , cmd "delay" delay "Spend AP until the current focus´ sequence is no higher than the next highest and focus that one"
100 , cmd "note" addNote "Add a note to the current focus" 100 , cmd "note" addNote "Add a note to the current focus"
101 , cmd "unnote" delNote "Remove a note from the current focus"
101 , cmd "hit" takeHit "Damage the focused entity" 102 , cmd "hit" takeHit "Damage the focused entity"
102 , cmd "heal" healDmg "Heal the focused entity" 103 , cmd "heal" healDmg "Heal the focused entity"
103 , cmd "heal'" healFatigue "Heal the focused entity of fatigue" 104 , cmd "heal'" healFatigue "Heal the focused entity of fatigue"
@@ -142,12 +143,21 @@ stateOutline = do
142 layoutTableToString <$> rowGs <*> pure (Just (roundStr round : factions, repeat def)) <*> pure (repeat def) <*> pure unicodeBoldHeaderS 143 layoutTableToString <$> rowGs <*> pure (Just (roundStr round : factions, repeat def)) <*> pure (repeat def) <*> pure unicodeBoldHeaderS
143 144
144focusNotes :: GameState -> String 145focusNotes :: GameState -> String
145focusNotes = maybe "" (unlines . map dotted) . preview (gFocus' . eNotes) 146focusNotes st
147 | (Just notes) <- preview (gFocus' . eNotes) st = let notes' = zip ([1..] :: [Int]) notes
148 dotted' = dotted . maximum $ map (length . show . fst) notes'
149 in unlines $ map dotted' notes'
150 | otherwise = ""
146 where 151 where
147 dotted "" = " • " 152 prefix :: Int -> Int -> String
148 dotted str 153 prefix pad n = printf (" %*d) " :: String) pad n
149 | fstL : [] <- lines str = " • " ++ fstL 154 prefix' :: Int -> String
150 | fstL : tailL <- lines str = " • " ++ fstL ++ "\n" ++ unlines (map (" " ++ ) tailL) 155 prefix' pad = printf (" %*s) " :: String) pad ("" :: String)
156 dotted :: Int -> (Int, String) -> String
157 dotted pad (n, "") = prefix pad n
158 dotted pad (n, str)
159 | fstL : [] <- lines str = prefix pad n ++ fstL
160 | fstL : tailL <- lines str = prefix pad n ++ fstL ++ "\n" ++ unlines (map (prefix' pad ++ ) tailL)
151 | otherwise = "" 161 | otherwise = ""
152 162
153stateMaintenance :: Sh GameState () 163stateMaintenance :: Sh GameState ()
@@ -331,6 +341,14 @@ delay = withFocus $ fmap (\_ -> ()) . runMaybeT . delay'
331addNote :: String -> Sh GameState () 341addNote :: String -> Sh GameState ()
332addNote note = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= (note :) 342addNote note = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= (note :)
333 343
344delNote :: Int -> Sh GameState ()
345delNote ((\n -> n - 1) -> index) = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= strike index
346 where
347 strike :: Int -> [a] -> [a]
348 strike _ [] = []
349 strike 0 (_:xs) = xs
350 strike n (x:xs) = x : strike (n - 1) xs
351
334doShock :: Int -> Traversal' Stats ShockEffect -> Sh GameState () 352doShock :: Int -> Traversal' Stats ShockEffect -> Sh GameState ()
335doShock dmg efLens = withFocus $ \focusId -> do 353doShock dmg efLens = withFocus $ \focusId -> do
336 let 354 let