conways-game-of-life/Graphics/Command.hs

29 lines
863 B
Haskell
Raw Permalink Normal View History

2021-12-29 18:51:48 -05:00
module Graphics.Command where
2021-12-29 19:57:29 -05:00
import FRP.Yampa (Event, Time)
2021-12-29 18:51:48 -05:00
2021-12-29 19:57:29 -05:00
-- | A datatype representing all possible commands the user
-- can give through UI.
2021-12-29 18:51:48 -05:00
data Command
2021-12-29 19:57:29 -05:00
= -- | A command to resize the window to the given dimensions.
Resize (Int, Int)
| -- | A command to change the tick speed of the simulation,
-- given by a function on the period between ticks.
ChangeSpeed (Time -> Time)
2021-12-29 20:37:00 -05:00
| -- | A command to play/pause the simulation.
PlayPause
2021-12-29 18:51:48 -05:00
getResize :: Command -> Maybe (Int, Int)
getResize (Resize size) = Just size
getResize _ = Nothing
getChangeSpeed :: Command -> Maybe (Time -> Time)
getChangeSpeed (ChangeSpeed f) = Just f
getChangeSpeed _ = Nothing
2021-12-29 20:37:00 -05:00
isPlayPause :: Command -> Bool
isPlayPause PlayPause = True
isPlayPause _ = False
2021-12-29 19:57:29 -05:00
-- | An event signalling that a command has been given by the user.
2021-12-29 18:51:48 -05:00
type CommandEvent = Event Command