Game :: Config -> WS.Connection -> IO [ServerMessage]
playGame config conn = do
    startTime <- getTime Monotonic
    forever $ do
        OutEvent pid eo <- getServerMessage config conn
        when (pid == 0) $
            case decodeEvent eo of
                Just (t,mbEvent) -> do
                    let mbEvent' = modify <$> mbEvent
                    currentTime <- getTime Monotonic
                    let t' | Just ms <- delay config = max 0 (t + ms/1000)
                           | otherwise               = timeSpecToS (currentTime - startTime)
                    sendClientMessage config conn (InEvent (show (t',mbEvent')))
                Nothing -> putStrLn $ "Could not parse event: " ++ eo
  where
    modify e | not (invert config) = e
    modify (KeyPress d) = KeyPress (inv d)
    modify (KeyRelease d) = KeyRelease (inv d)
    modify e = e

    inv "Up"    = "Down"
    inv "Down"  = "Up"
    inv "Left"  = "Right"
    inv "Right" = "Left"
    inv c       = c

ti
playGame :: Config -> WS.Connection -> IO [ServerMessage]
playGame config conn = do
    startTime <- getTime Monotonic
    forever $ do
        OutEvent pid eo <- getServerMessage config conn
        when (pid == 0) $
            case decodeEvent eo of
                Just (t,mbEvent) -> do
                    let mbEvent' = modify <$> mbEvent
                    currentTime <- getTime Monotonic
                    let t' | Just ms <- delay config = max 0 (t + ms/1000)
                           | otherwise               = timeSpecToS (currentTime - startTime)
                    sendClientMessage config conn (InEvent (show (t',mbEvent')))
                Nothing -> putStrLn $ "Could not parse event: " ++ eo
  where
    modify e | not (invert config) = e
    modify (KeyPress d) = KeyPress (inv d)
    modify (KeyRelease d) = KeyRelease (inv d)
    modify e = e

    inv "Up"    = "Down"
    inv "Down"  = "Up"
    inv "Left"  = "Right"
    inv "Right" = "Left"
    inv c       = c
playGame config conn = do
    startTime <- getTime Monotonic
    forever $ do
        OutEvent pid eo <- getServerMessage config conn
        when (pid == 0) $
            case decodeEvent eo of
                Just (t,mbEvent) -> do
                    let mbEvent' = modify <$> mbEvent
                    currentTime <- getTime Monotonic
                    let t' | Just ms <- delay config = max 0 (t + ms/1000)
                           | otherwise               = timeSpecToS (currentTime - startTime)
                    sendClientMessage config conn (InEvent (show (t',mbEvent')))
                Nothing -> putStrLn $ "Could not parse event: " ++ eo
  where
    modify e | not (invert config) = e
    modify (KeyPress d) = KeyPress (inv d)
    modify (KeyRelease d) = KeyRelease (inv d)
    modify e = e

    inv "Up"    = "Down"
    inv "Down"  = "Up"
    inv "Left"  = "Right"
    inv "Right" = "Left"
    inv c       = c