#5 Render inventory when pressing i

This commit is contained in:
Tibo De Peuter 2022-12-22 14:35:58 +01:00
parent f529fc5237
commit d0302c3156
9 changed files with 76 additions and 52 deletions

View file

@ -32,16 +32,16 @@ composeInputHandlers (ih:ihs) ev a = composeInputHandlers ihs ev (ih ev a)
-- Handle any event
handle :: Event -> (a -> a) -> InputHandler a
handle (EventKey key _ _ _) = handleKey key
handle (EventKey key state _ _) = handleKey key state
-- handle (EventMotion _) = undefined -- TODO
-- handle (EventResize _) = undefined -- TODO
handle _ = const (const id)
handle _ = const (const id)
-- Handle a event by pressing a key
handleKey :: Key -> (a -> a) -> InputHandler a
handleKey (SpecialKey sk) = handleSpecialKey sk
handleKey (Char c ) = handleCharKey c
handleKey (MouseButton _ ) = const (const id)
handleKey :: Key -> KeyState -> (a -> a) -> InputHandler a
handleKey (SpecialKey sk) s = handleSpecialKey sk s
handleKey (Char c ) s = handleCharKey c s
handleKey (MouseButton _ ) _ = const (const id)
-- Handle any key, equivalent to "Press any key to start"
handleAnyKey :: (a -> a) -> InputHandler a
@ -50,14 +50,14 @@ handleAnyKey _ _ = id
--------------------------- Help functions ---------------------------
handleCharKey :: Char -> (a -> a) -> InputHandler a
handleCharKey c1 f (EventKey (Char c2) Down _ _)
| c1 == c2 = f
| otherwise = id
handleCharKey _ _ _ = id
handleCharKey :: Char -> KeyState -> (a -> a) -> InputHandler a
handleCharKey c1 s1 f (EventKey (Char c2) s2 _ _)
| c1 == c2 && s1 == s2 = f
| otherwise = id
handleCharKey _ _ _ _ = id
handleSpecialKey :: SpecialKey -> (a -> a) -> InputHandler a
handleSpecialKey sk1 f (EventKey (SpecialKey sk2) Down _ _)
| sk1 == sk2 = f
handleSpecialKey :: SpecialKey -> KeyState -> (a -> a) -> InputHandler a
handleSpecialKey sk1 s1 f (EventKey (SpecialKey sk2) s2 _ _)
| sk1 == sk2 && s1 == s2 = f
| otherwise = id
handleSpecialKey _ _ _ = id
handleSpecialKey _ _ _ _ = id