Skip to content

Instantly share code, notes, and snippets.

@rrichardson
Created June 6, 2013 19:58
Show Gist options
  • Save rrichardson/5724439 to your computer and use it in GitHub Desktop.
Save rrichardson/5724439 to your computer and use it in GitHub Desktop.
import Graphics.Input as Input
import Http
import WebSocket
import JavaScript.Experimental as JS
import Json
import Window
import Keyboard
(nameInput, username) = Input.field "Your name here"
(chatInput, chats) = Input.field "Type here to chat!"
chatSubmit = keepWhen Keyboard.enter [] chats
type GameState = { name : String,
members : [String],
chatlog : [String] }
messages : Signal String -> Signal [String]
messages websock = foldp (\m acc -> if (length m) > 0 then acc ++ [m] else acc) [] websock
others : Signal [String]
others = constant ["just me"]
gameState websock = GameState <~ username
~ others
~ messages websock
display : (Int,Int) -> GameState -> Element -> Element -> Element
display (w,h) gameState name chat = asText gameState `above` name `above` chat
connectWS = WebSocket.connect "ws://localhost:4000" chatSubmit
main = display <~ Window.dimensions
~ (gameState connectWS)
~ nameInput
~ chatInput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment