Skip to content

Instantly share code, notes, and snippets.

@MichaelXavier
Forked from anonymous/gist:25dd96829f15d989225a
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichaelXavier/d331d9817f120daf5a65 to your computer and use it in GitHub Desktop.
Save MichaelXavier/d331d9817f120daf5a65 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
data GUIEvent = KeyDownEvent { key_down__ctrl :: !Bool
, key_down__shift :: !Bool
, key_down__code :: !Int }
| MouseEvent { mouse__x :: !Int
, mouse__y ::!Int }
deriving (Show)
instance FromJSON GUIEvent where
parseJSON = withObject "GUIObject" parseGUIEvent
parseGUIEvent v = parseKeyDownEvent v <|> parseMouseEvent
parseKeyDownEvent = do
tag <- v .: "tag"
guard (tag == String "KeyDownEvent")
KeyDownEvent <$> v .: "ctrlKey"
<*> v .: "shiftKey"
<*> v .: "keyCode"
parseMouseEvent = do
tag <- v .: "tag"
guard (tag == String "MouseEvent")
MouseEvent <$> v .: "x"
<*> v .: "y"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment