From 9983d6cfc0eebf0dff720a285db3b0f180c8b854 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 10 Jul 2016 19:15:18 +0200 Subject: allow deletion of notes --- src/Main.hs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src') 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 , cmd "spend" spendSeq "Spend some of the current focus´ AP" , cmd "delay" delay "Spend AP until the current focus´ sequence is no higher than the next highest and focus that one" , cmd "note" addNote "Add a note to the current focus" + , cmd "unnote" delNote "Remove a note from the current focus" , cmd "hit" takeHit "Damage the focused entity" , cmd "heal" healDmg "Heal the focused entity" , cmd "heal'" healFatigue "Heal the focused entity of fatigue" @@ -142,12 +143,21 @@ stateOutline = do layoutTableToString <$> rowGs <*> pure (Just (roundStr round : factions, repeat def)) <*> pure (repeat def) <*> pure unicodeBoldHeaderS focusNotes :: GameState -> String -focusNotes = maybe "" (unlines . map dotted) . preview (gFocus' . eNotes) +focusNotes st + | (Just notes) <- preview (gFocus' . eNotes) st = let notes' = zip ([1..] :: [Int]) notes + dotted' = dotted . maximum $ map (length . show . fst) notes' + in unlines $ map dotted' notes' + | otherwise = "" where - dotted "" = " • " - dotted str - | fstL : [] <- lines str = " • " ++ fstL - | fstL : tailL <- lines str = " • " ++ fstL ++ "\n" ++ unlines (map (" " ++ ) tailL) + prefix :: Int -> Int -> String + prefix pad n = printf (" %*d) " :: String) pad n + prefix' :: Int -> String + prefix' pad = printf (" %*s) " :: String) pad ("" :: String) + dotted :: Int -> (Int, String) -> String + dotted pad (n, "") = prefix pad n + dotted pad (n, str) + | fstL : [] <- lines str = prefix pad n ++ fstL + | fstL : tailL <- lines str = prefix pad n ++ fstL ++ "\n" ++ unlines (map (prefix' pad ++ ) tailL) | otherwise = "" stateMaintenance :: Sh GameState () @@ -331,6 +341,14 @@ delay = withFocus $ fmap (\_ -> ()) . runMaybeT . delay' addNote :: String -> Sh GameState () addNote note = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= (note :) +delNote :: Int -> Sh GameState () +delNote ((\n -> n - 1) -> index) = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= strike index + where + strike :: Int -> [a] -> [a] + strike _ [] = [] + strike 0 (_:xs) = xs + strike n (x:xs) = x : strike (n - 1) xs + doShock :: Int -> Traversal' Stats ShockEffect -> Sh GameState () doShock dmg efLens = withFocus $ \focusId -> do let -- cgit v1.2.3