Permalink
Browse files

progress

  • Loading branch information...
1 parent 8bf7f73 commit 5ddcf500ab0899cd794017f7c6458bb73c0400ab @vogievetsky vogievetsky committed Sep 16, 2012
Showing with 139 additions and 58 deletions.
  1. +35 −15 app.coffee
  2. +39 −20 app.js
  3. +29 −9 public/muse.coffee
  4. +36 −14 public/muse.js
View
@@ -74,14 +74,15 @@ class Card
return this
class Drawer
- constructor: ({cards} = {}) ->
+ constructor: ({@id, cards}) ->
cards ?= []
@cards = cards.map((c) -> new Card(c))
@claim = null
@semiCard = null
simple: ->
return {
+ id: @id
cards: @cards
}
@@ -185,41 +186,60 @@ io.sockets.on 'connection', (socket) ->
socket.emit('drawerInfo', location.drawers)
return
- socket.on 'drawerClaim', (drawer) ->
+ foo = (x) ->
+ console.log 'foo', x
+ return x
+
+ socket.on 'drawerClaim', (drawerId) ->
location = locations[client.locationName]
- if drawer.match(/^\d+_\d+$/) and location and (location.drawers[drawer] or= new Drawer()).claim is null
+ if drawerId.match(/^\d+_\d+$/) and
+ location and
+ (drawer = (location.drawers[drawerId] or= new Drawer({id: drawerId}))).claim is null
clinetUnclaim()
- location.drawers[drawer].claim = client
+ drawer.claim = client
client.claim = drawer
socket.emit('drawerClaimResult', 'OK')
- socket.broadcast.to(location.name).emit('drawerClaim', drawer)
+ socket.broadcast.to(location.name).emit('drawerUpdate', drawer.id, Boolean(drawer.claim), simplify(drawer.cards))
else
socket.emit('drawerClaimResult', 'FAIL')
return
socket.on 'drawerUnclaim', clinetUnclaim = ->
- drawer = client.claim
- return unless drawer
location = locations[client.locationName]
- return unless location
- location.drawers[drawer].claim = null
- client.claim = null
- socket.broadcast.to(location.name).emit('drawerUnclaim', drawer)
+ drawer = client.claim
+ if location and drawer
+ drawer.claim = null
+ client.claim = null
+ socket.broadcast.to(location.name).emit('drawerUnclaim', drawer)
+ else
+ null # ??
return
socket.on 'makeCard', (text) ->
- drawer = client.claim
location = locations[client.locationName]
- if drawer and location
+ drawer = client.claim
+ if location and drawer
card = new Card({text})
- location.drawers[drawer].cards.unshift(card)
+ drawer.cards.unshift(card)
socket.emit('makeCardResult', 'OK')
- socket.broadcast.to(location.name).emit('putCard', drawer, card)
+ socket.broadcast.to(location.name).emit('drawerUpdate', drawer.id, Boolean(drawer.claim), simplify(drawer.cards))
location.makeDirty()
else
socket.emit('makeCardResult', 'FAIL')
return
+ socket.on 'updateCard', (text) ->
+ location = locations[client.locationName]
+ drawer = client.claim
+ if location and drawer and card = drawer.cards[0]
+ card.text = text
+ socket.emit('updateCardResult', 'OK')
+ socket.broadcast.to(location.name).emit('drawerUpdate', drawer.id, Boolean(drawer.claim), simplify(drawer.cards))
+ location.makeDirty()
+ else
+ socket.emit('updateCardResult', 'FAIL')
+ return
+
socket.on 'disconnect', clinetUnclaim
return
View
59 app.js

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -90,7 +90,7 @@ make_box = (box) ->
make_cards = (box) ->
card = box.selectAll('div.card')
- .data((d) -> if d then cross({card: drawerState[d].cards, pos:[drawerPos[d]]}) else [])
+ .data((d) -> if d then cross({card: drawerState[d].cards.map((c) -> c.text), pos:[drawerPos[d]]}) else [])
animEnd = ->
el = d3.select(this)
@@ -212,7 +212,7 @@ do ->
makeCard '', ->
editCont.style('display', null)
writerDrawer = drawer
- editor.property('value', drawerState[writerDrawer].cards[0])
+ editor.property('value', '') # drawerState[writerDrawer].cards[0].text
writer
.style('left', (d) -> drawerPos[writerDrawer].x + 'px')
.style('top', (d) -> (drawerPos[writerDrawer].y - drawerHeight) + 'px')
@@ -227,6 +227,7 @@ do ->
.style('width', writerWidth + 'px')
.style('height', writerHeight + 'px')
.style('border-radius', '3px')
+ .each('end', -> editor.node().focus())
return
), delay)
return
@@ -252,6 +253,12 @@ do ->
.on('click', -> d3.event.stopPropagation())
editor = writer.append('textarea')
+ .on('keyup', ->
+ updateCard editor.property('value'), (res) ->
+ console.log 'updateCardResult', res
+ return
+ return
+ )
writer.append('button')
.text('Close')
@@ -274,6 +281,7 @@ hideLoading = ->
drawerClaim = (d, cb) -> setTimeout(cb, 1, 'OK')
makeCard = (text, cb) -> setTimeout(cb, 1, 'OK')
+updateCard = (text, cb) -> setTimeout(cb, 1, 'OK')
notifyChange = -> return
do ->
if window.io
@@ -298,12 +306,12 @@ do ->
hideLoading()
return
- socket.on 'putCard', (drawer, card) ->
- return unless drawer.match(/^\d+_\d+$/)
- console.log 'GOT putCard', drawer, card
- drawerState[drawer].cards.unshift(card)
- updateDrawers()
- return
+ # socket.on 'putCard', (drawer, card) ->
+ # return unless drawer.match(/^\d+_\d+$/)
+ # console.log 'GOT putCard', drawer, card
+ # drawerState[drawer].cards.unshift(card)
+ # updateDrawers()
+ # return
socket.on 'drawerClaim', (drawer) ->
return unless drawer.match(/^\d+_\d+$/)
@@ -345,6 +353,18 @@ do ->
socket.emit 'makeCard', text
return
+ do ->
+ callback = null
+ socket.on 'updateCardResult', (res) ->
+ callback?(res)
+ callback = null
+ return
+
+ updateCard = (text, cb) ->
+ callback = cb
+ socket.emit 'updateCard', text
+ return
+
notifyChange = (d) ->
socket.emit('drawerChange', d, drawerState[d])
return
@@ -384,7 +404,7 @@ In 2002, I walked for the Homeless in DC, it's the one place I felt I made a dif
for d in drawers
drawerState[d] = {
- cards: if Math.random() > 0.85 then [msgs[Math.floor(Math.random() * msgs.length)]] else []
+ cards: if Math.random() > 0.85 then [{ text: msgs[Math.floor(Math.random() * msgs.length)] }] else []
open: false
}
Oops, something went wrong.

0 comments on commit 5ddcf50

Please sign in to comment.