aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-04-16 15:02:50 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-04-16 15:02:50 +0100
commitd333eca8c0761e39781af0711a54044cd5ea3c10 (patch)
treea8b7eb07cb0395ba49b2143e9a8506e461280dfe
parentbcb2baca918b758c77feabed7342d53559c5d897 (diff)
downloadspace-plat-hs-d333eca8c0761e39781af0711a54044cd5ea3c10.tar.gz
space-plat-hs-d333eca8c0761e39781af0711a54044cd5ea3c10.zip
Documented the notification module
-rw-r--r--src/Game/Toaster.hs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/Game/Toaster.hs b/src/Game/Toaster.hs
index b0920c5..190365e 100644
--- a/src/Game/Toaster.hs
+++ b/src/Game/Toaster.hs
@@ -27,6 +27,9 @@ data Toaster = Toaster
current :: Maybe Toast
}
+-- | Make a "toast" notification manager.
+--
+-- The toast notifications appear on the bottom left of the screen and disappear after some seconds.
mkToaster :: BM.BitmapFont -> Int -> IO Toaster
mkToaster font height = do
pure $ Toaster font height [] Nothing
@@ -35,6 +38,7 @@ add :: Toaster -> String -> Toaster
add t message =
t {queue = t.queue ++ [message]}
+-- | Update the current notification or activate the next one if there is no notification active.
update :: Toaster -> Toaster
update t = case t.current of
Nothing -> case t.queue of
@@ -50,6 +54,7 @@ update t = case t.current of
| toast.y < t.gameHeight = Just toast {y = toast.y + 1}
| otherwise = Nothing
+-- | Render current notification (if there's one active).
render :: SDL.Renderer -> Toaster -> IO ()
render renderer t =
traverse_ (\toast -> BM.renderTextSolid renderer t.font 4 toast.y toast.message) t.current