diff options
| author | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-07-10 19:15:18 +0200 |
|---|---|---|
| committer | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-07-10 19:15:18 +0200 |
| commit | 9983d6cfc0eebf0dff720a285db3b0f180c8b854 (patch) | |
| tree | c9d73f686101de7974e306a3d1f4d5391f2a7e96 /src | |
| parent | 7bd64df07668883920be7e0bf9d6eaea96dfba12 (diff) | |
| download | 2017-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
Diffstat (limited to 'src')
| -rw-r--r-- | src/Main.hs | 28 |
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 | ||
| 144 | focusNotes :: GameState -> String | 145 | focusNotes :: GameState -> String |
| 145 | focusNotes = maybe "" (unlines . map dotted) . preview (gFocus' . eNotes) | 146 | focusNotes 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 | ||
| 153 | stateMaintenance :: Sh GameState () | 163 | stateMaintenance :: Sh GameState () |
| @@ -331,6 +341,14 @@ delay = withFocus $ fmap (\_ -> ()) . runMaybeT . delay' | |||
| 331 | addNote :: String -> Sh GameState () | 341 | addNote :: String -> Sh GameState () |
| 332 | addNote note = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= (note :) | 342 | addNote note = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= (note :) |
| 333 | 343 | ||
| 344 | delNote :: Int -> Sh GameState () | ||
| 345 | delNote ((\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 | |||
| 334 | doShock :: Int -> Traversal' Stats ShockEffect -> Sh GameState () | 352 | doShock :: Int -> Traversal' Stats ShockEffect -> Sh GameState () |
| 335 | doShock dmg efLens = withFocus $ \focusId -> do | 353 | doShock dmg efLens = withFocus $ \focusId -> do |
| 336 | let | 354 | let |
