Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

further

  • Loading branch information...
commit 8bf7f735fd1913ab449fcd0f8f4feb1ba1ea4d92 1 parent cebc84f
@vogievetsky vogievetsky authored
Showing with 657 additions and 244 deletions.
  1. +155 −33 app.coffee
  2. +217 −37 app.js
  3. +153 −102 public/muse.coffee
  4. +132 −72 public/muse.js
View
188 app.coffee
@@ -5,40 +5,131 @@ fs = require('fs')
LOCATION_DIR = 'store/'
-locationNames = ['dc']
+locationNames = ['DC']
locations = {}
+objMap = (obj, fn) ->
+ newObj = {}
+ for k, v of obj
+ newObj[k] = fn.call(obj, v, k)
+ return newObj
+
+simplify = (obj) ->
+ objType = typeof obj
+ if objType isnt 'object'
+ return obj
+ else
+ constructorName = obj.constructor.name
+ throw "Bad constructor name" unless constructorName
+
+ if obj.simple
+ simple = objMap(obj.simple(), simplify)
+ simple._c_ = constructorName
+ return simple
+
+ if constructorName is 'Date'
+ return {
+ _c_: constructorName
+ date: obj.toISOString()
+ }
+
+ if constructorName is 'Object'
+ return objMap(obj, simplify)
+
+ if constructorName is 'Array'
+ return {
+ _c_: constructorName
+ values: obj.map(simplify)
+ }
+
+ throw "Cound not handle #{obj.constructor.name}"
+
+unsimplify = (obj) ->
+ objType = typeof obj
+ if objType isnt 'object'
+ return obj
+ else
+ constructorName = obj._c_
+
+ if not constructorName?
+ return objMap(obj, unsimplify)
+
+ if constructorName is 'Date'
+ return new Date(obj.date)
+
+ if constructorName is 'Array'
+ return obj.values.map(unsimplify)
+
+ ctr = this[constructorName]
+ throw "unknown constructor name #{constructorName}"
+ delete obj._c_
+ return new ctr(objMap(obj, unsimplify))
+
+
+class Card
+ constructor: ({@text, @created}) ->
+ @created or= new Date()
+
+ simple: ->
+ return this
+
+class Drawer
+ constructor: ({cards} = {}) ->
+ cards ?= []
+ @cards = cards.map((c) -> new Card(c))
+ @claim = null
+ @semiCard = null
+
+ simple: ->
+ return {
+ cards: @cards
+ }
+
+class Location
+ constructor: ({@name, lastChanged, drawers}) ->
+ @drawers = objMap(drawers, (d) -> new Drawer(d))
+ @lastChanged = new Date(lastChanged)
+ @dirty = false
+
+ makeDirty: -> @dirty = true
+ clearDirty: -> @dirty = false
+
+ simple: ->
+ return {
+ name: @name
+ drawers: @drawers
+ lastChanged: @lastChanged
+ }
+
# loader
-for locationName in locationNames
+locationNames.forEach (locationName) ->
file = LOCATION_DIR + locationName + '.json'
- json = fs.readFileSync file
try
- json = JSON.parse(json)
+ location = unsimplify(JSON.parse(fs.readFileSync(file)))
catch e
- json = {
- dirty: false
+ location = new Location({
+ name: locationName
lastChanged: new Date()
drawers: {}
- }
+ })
- locations[locationName] = json
+ locations[locationName] = location
# saver
setInterval((->
- for locationName in locationNames
- do (locationName) ->
- locationSpec = locations[locationName]
- return unless locationSpec.dirty
- file = LOCATION_DIR + locationName + '.json'
- data = JSON.stringify(locationSpec, null, 2)
- fs.writeFile file, data, (err) ->
- if err
- console.error("There was an error writing the file [#{file}]", err)
- else
- console.log('Location file saved')
- locationSpec.dirty = false
- return
+ locationNames.forEach (locationName) ->
+ location = locations[locationName]
+ return unless location.dirty
+ file = LOCATION_DIR + location.name + '.json'
+ data = JSON.stringify(simplify(location), null, 2)
+ fs.writeFile file, data, (err) ->
+ if err
+ console.error("There was an error writing the file [#{file}]", err)
+ else
+ console.log('Location file saved')
+ location.clearDirty()
return
+ return
return
), 2000)
@@ -78,27 +169,58 @@ io = io.listen(app)
app.listen(8181)
io.sockets.on 'connection', (socket) ->
- client = {}
+ client = {
+ claim: null
+ }
# when the client emits 'adduser', this listens and executes
- socket.on 'addClient', (locationStr) ->
- client.location = locationStr
- location = locations[client.location]
+ socket.on 'register', (locationName) ->
+ location = locations[locationName]
+ return unless location
# send client to location
- socket.join(client.location)
+ socket.join(client.locationName = location.name)
# echo to client they've connected
- socket.emit('updateDrawers', location.drawers)
+ socket.emit('drawerInfo', location.drawers)
return
- socket.on 'drawerChange', (drawer, state) ->
- location = locations[client.location]
- location.drawers[drawer] = state
- socket.broadcast.to(client.location).emit('drawerChange', drawer, state)
- location.dirty = true
+ socket.on 'drawerClaim', (drawer) ->
+ location = locations[client.locationName]
+ if drawer.match(/^\d+_\d+$/) and location and (location.drawers[drawer] or= new Drawer()).claim is null
+ clinetUnclaim()
+ location.drawers[drawer].claim = client
+ client.claim = drawer
+ socket.emit('drawerClaimResult', 'OK')
+ socket.broadcast.to(location.name).emit('drawerClaim', drawer)
+ 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)
+ return
+
+ socket.on 'makeCard', (text) ->
+ drawer = client.claim
+ location = locations[client.locationName]
+ if drawer and location
+ card = new Card({text})
+ location.drawers[drawer].cards.unshift(card)
+ socket.emit('makeCardResult', 'OK')
+ socket.broadcast.to(location.name).emit('putCard', drawer, card)
+ location.makeDirty()
+ else
+ socket.emit('makeCardResult', 'FAIL')
return
+ socket.on 'disconnect', clinetUnclaim
return
archive = ->
@@ -108,7 +230,7 @@ archive = ->
io.sockets.emit('reset')
return
-# cron job :-)
+# 'CRON' job :-)
offset = -7 # PST
getDate = -> (new Date(Date.now() + offset * 60 * 60 * 1000)).getUTCDate()
lastDate = getDate()
View
254 app.js
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.3.1
(function() {
- var LOCATION_DIR, app, archive, file, fs, getDate, http, io, json, lastDate, locationName, locationNames, locations, offset, send, _i, _len;
+ var Card, Drawer, LOCATION_DIR, Location, app, archive, fs, getDate, http, io, lastDate, locationNames, locations, objMap, offset, send, simplify, unsimplify;
http = require('http');
@@ -12,49 +12,188 @@
LOCATION_DIR = 'store/';
- locationNames = ['dc'];
+ locationNames = ['DC'];
locations = {};
- for (_i = 0, _len = locationNames.length; _i < _len; _i++) {
- locationName = locationNames[_i];
+ objMap = function(obj, fn) {
+ var k, newObj, v;
+ newObj = {};
+ for (k in obj) {
+ v = obj[k];
+ newObj[k] = fn.call(obj, v, k);
+ }
+ return newObj;
+ };
+
+ simplify = function(obj) {
+ var constructorName, objType, simple;
+ objType = typeof obj;
+ if (objType !== 'object') {
+ return obj;
+ } else {
+ constructorName = obj.constructor.name;
+ if (!constructorName) {
+ throw "Bad constructor name";
+ }
+ if (obj.simple) {
+ simple = objMap(obj.simple(), simplify);
+ simple._c_ = constructorName;
+ return simple;
+ }
+ if (constructorName === 'Date') {
+ return {
+ _c_: constructorName,
+ date: obj.toISOString()
+ };
+ }
+ if (constructorName === 'Object') {
+ return objMap(obj, simplify);
+ }
+ if (constructorName === 'Array') {
+ return {
+ _c_: constructorName,
+ values: obj.map(simplify)
+ };
+ }
+ throw "Cound not handle " + obj.constructor.name;
+ }
+ };
+
+ unsimplify = function(obj) {
+ var constructorName, ctr, objType;
+ objType = typeof obj;
+ if (objType !== 'object') {
+ return obj;
+ } else {
+ constructorName = obj._c_;
+ if (!(constructorName != null)) {
+ return objMap(obj, unsimplify);
+ }
+ if (constructorName === 'Date') {
+ return new Date(obj.date);
+ }
+ if (constructorName === 'Array') {
+ return obj.values.map(unsimplify);
+ }
+ ctr = this[constructorName];
+ throw "unknown constructor name " + constructorName;
+ delete obj._c_;
+ return new ctr(objMap(obj, unsimplify));
+ }
+ };
+
+ Card = (function() {
+
+ Card.name = 'Card';
+
+ function Card(_arg) {
+ this.text = _arg.text, this.created = _arg.created;
+ this.created || (this.created = new Date());
+ }
+
+ Card.prototype.simple = function() {
+ return this;
+ };
+
+ return Card;
+
+ })();
+
+ Drawer = (function() {
+
+ Drawer.name = 'Drawer';
+
+ function Drawer(_arg) {
+ var cards;
+ cards = (_arg != null ? _arg : {}).cards;
+ if (cards == null) {
+ cards = [];
+ }
+ this.cards = cards.map(function(c) {
+ return new Card(c);
+ });
+ this.claim = null;
+ this.semiCard = null;
+ }
+
+ Drawer.prototype.simple = function() {
+ return {
+ cards: this.cards
+ };
+ };
+
+ return Drawer;
+
+ })();
+
+ Location = (function() {
+
+ Location.name = 'Location';
+
+ function Location(_arg) {
+ var drawers, lastChanged;
+ this.name = _arg.name, lastChanged = _arg.lastChanged, drawers = _arg.drawers;
+ this.drawers = objMap(drawers, function(d) {
+ return new Drawer(d);
+ });
+ this.lastChanged = new Date(lastChanged);
+ this.dirty = false;
+ }
+
+ Location.prototype.makeDirty = function() {
+ return this.dirty = true;
+ };
+
+ Location.prototype.clearDirty = function() {
+ return this.dirty = false;
+ };
+
+ Location.prototype.simple = function() {
+ return {
+ name: this.name,
+ drawers: this.drawers,
+ lastChanged: this.lastChanged
+ };
+ };
+
+ return Location;
+
+ })();
+
+ locationNames.forEach(function(locationName) {
+ var file, location;
file = LOCATION_DIR + locationName + '.json';
- json = fs.readFileSync(file);
try {
- json = JSON.parse(json);
+ location = unsimplify(JSON.parse(fs.readFileSync(file)));
} catch (e) {
- json = {
- dirty: false,
+ location = new Location({
+ name: locationName,
lastChanged: new Date(),
drawers: {}
- };
+ });
}
- locations[locationName] = json;
- }
+ return locations[locationName] = location;
+ });
setInterval((function() {
- var locationName, _fn, _j, _len1;
- _fn = function(locationName) {
- var data, locationSpec;
- locationSpec = locations[locationName];
- if (!locationSpec.dirty) {
+ locationNames.forEach(function(locationName) {
+ var data, file, location;
+ location = locations[locationName];
+ if (!location.dirty) {
return;
}
- file = LOCATION_DIR + locationName + '.json';
- data = JSON.stringify(locationSpec, null, 2);
+ file = LOCATION_DIR + location.name + '.json';
+ data = JSON.stringify(simplify(location), null, 2);
fs.writeFile(file, data, function(err) {
if (err) {
console.error("There was an error writing the file [" + file + "]", err);
} else {
console.log('Location file saved');
- locationSpec.dirty = false;
+ location.clearDirty();
}
});
- };
- for (_j = 0, _len1 = locationNames.length; _j < _len1; _j++) {
- locationName = locationNames[_j];
- _fn(locationName);
- }
+ });
}), 2000);
app = http.createServer(function(req, res) {
@@ -87,22 +226,63 @@
app.listen(8181);
io.sockets.on('connection', function(socket) {
- var client;
- client = {};
- socket.on('addClient', function(locationStr) {
+ var client, clinetUnclaim;
+ client = {
+ claim: null
+ };
+ socket.on('register', function(locationName) {
var location;
- client.location = locationStr;
- location = locations[client.location];
- socket.join(client.location);
- socket.emit('updateDrawers', location.drawers);
+ location = locations[locationName];
+ if (!location) {
+ return;
+ }
+ socket.join(client.locationName = location.name);
+ socket.emit('drawerInfo', location.drawers);
});
- socket.on('drawerChange', function(drawer, state) {
- var location;
- location = locations[client.location];
- location.drawers[drawer] = state;
- socket.broadcast.to(client.location).emit('drawerChange', drawer, state);
- location.dirty = true;
+ socket.on('drawerClaim', function(drawer) {
+ var location, _base;
+ location = locations[client.locationName];
+ if (drawer.match(/^\d+_\d+$/) && location && ((_base = location.drawers)[drawer] || (_base[drawer] = new Drawer())).claim === null) {
+ clinetUnclaim();
+ location.drawers[drawer].claim = client;
+ client.claim = drawer;
+ socket.emit('drawerClaimResult', 'OK');
+ socket.broadcast.to(location.name).emit('drawerClaim', drawer);
+ } else {
+ socket.emit('drawerClaimResult', 'FAIL');
+ }
+ });
+ socket.on('drawerUnclaim', clinetUnclaim = function() {
+ var drawer, location;
+ drawer = client.claim;
+ if (!drawer) {
+ return;
+ }
+ location = locations[client.locationName];
+ if (!location) {
+ return;
+ }
+ location.drawers[drawer].claim = null;
+ client.claim = null;
+ socket.broadcast.to(location.name).emit('drawerUnclaim', drawer);
+ });
+ socket.on('makeCard', function(text) {
+ var card, drawer, location;
+ drawer = client.claim;
+ location = locations[client.locationName];
+ if (drawer && location) {
+ card = new Card({
+ text: text
+ });
+ location.drawers[drawer].cards.unshift(card);
+ socket.emit('makeCardResult', 'OK');
+ socket.broadcast.to(location.name).emit('putCard', drawer, card);
+ location.makeDirty();
+ } else {
+ socket.emit('makeCardResult', 'FAIL');
+ }
});
+ socket.on('disconnect', clinetUnclaim);
});
archive = function() {
View
255 public/muse.coffee
@@ -21,37 +21,6 @@ $totalOuterHeight = $totalInnerHeight + drawerHeight + gap*2;
# --------------------------
-msgs = "
-Dear DC, It's all theatre, and some of it's bad, but I still love it. - Shira
------
-Dear D.C, I've been pretty serious with New York, but if one of your fine law firms gives me a job, I'm pretty sure I'd break up with her for you. Love, a frustrated 3L.
-Tho I will always love you, i don't have to like you right now.
------
-I have yet to experience another city who supports the arts with the same generosity. DC is my haven for the arts.
------
-Dear DC, you're the most kickass and most vibrant big town I've ever met. You have your own music, your own art culture, you have waterfronts and parks and rivers. There's more to you than just stately buildings filled with pretentious people, and I'm lucky to have grown up here and experienced the real dc. Best of all, you never make me feel like I'm alone, or just another number in a swarm of people on the street: you're a city that actually feels like a home. ALL my love, Lida
------
-Dear DC, thank you for letting me see your big blue sky on my way to work and during lunch. And giving me access to free education in the Smithsonian institutes. I hope to bring my children to see your beautiful museums and exhibits. One day, I will leave you to return to my home city. But I will always remember you and your sky.
------
-Dear DC, We should have gotten to know each other when we had the chance. My friend thinks you're really great. Love Gabi
------
-Dear DC, I've loved you from afar all these years. I'm looking forward to getting to know you better. Love, Becca
------
-The monuments inspire me to think of the founding principles that make our country great. They give me hope that we can remember who we are as a nation.
------
-Dear DC, I love standing next to Lincoln and looking up at a giant for democracy and freedom
------
-Hey DC, thanks for the clean ride… I like your metro
------
-Dear DC, I love you for fostering a surprising intelligent community of artists!
------
-To the District of Columbia - thank you for your hidden gardens in Georgetown
------
-In 2002, I walked for the Homeless in DC, it's the one place I felt I made a difference.
-"
-
-msgs = msgs.split('-----')
-
drawers = []
drawerPos = {}
for ix in [0...number]
@@ -191,27 +160,32 @@ drawerClassFn = (d) ->
].join(' ')
myDrawer = null
-box_click = (d) ->
- if myDrawer
- drawerState[myDrawer].open = false
- notifyChange(myDrawer)
-
- if myDrawer is d
- myDrawer = null
- #drawerChest.attr('class', "drawer-chest")
- else
- myDrawer = d
- #drawerChest.attr('class', "drawer-chest focus focus-x#{d.ix}y#{d.iy}")
- drawerState[d].open = true
- if drawerState[d].open and drawerState[d].cards.length is 0
- drawerState[d].cards.push('')
+drawerClick = (d) ->
+ return if drawerState[d].open
+
+ drawerClaim d, (res) ->
+ console.log 'claim result:', res
+ return unless res is 'OK'
+
+ if myDrawer
+ drawerState[myDrawer].open = false
+ notifyChange(myDrawer)
+
+ if myDrawer is d
+ myDrawer = null
+ #drawerChest.attr('class', "drawer-chest")
+ else
+ myDrawer = d
+ #drawerChest.attr('class', "drawer-chest focus focus-x#{d.ix}y#{d.iy}")
+ drawerState[d].open = true
+ if drawerState[d].cards.length is 0
+ drawerState[d].cards.push('')
- if drawerState[d].open
makeWriter(d)
+ notifyChange(d)
- notifyChange(d)
-
- updateDrawers()
+ updateDrawers()
+ return
return
drawerChest.selectAll('div.drawer').data(drawers)
@@ -219,7 +193,7 @@ drawerChest.selectAll('div.drawer').data(drawers)
.attr('class', drawerClassFn)
.style('left', (d) -> drawerPos[d].x + 'px')
.style('top', (d) -> drawerPos[d].y + 'px')
- .on('click', box_click)
+ .on('click', drawerClick)
.call(make_box)
updateDrawers = ->
@@ -235,23 +209,25 @@ do ->
writerDrawer = null
makeWriter = (drawer, delay = 2000) ->
setTimeout((->
- editCont.style('display', null)
- writerDrawer = drawer
- editor.property('value', drawerState[writerDrawer].cards[0])
- writer
- .style('left', (d) -> drawerPos[writerDrawer].x + 'px')
- .style('top', (d) -> (drawerPos[writerDrawer].y - drawerHeight) + 'px')
- .style('width', drawerWidth + 'px')
- .style('height', drawerHeight + 'px')
- .style('border-radius', '0px')
- .transition()
- .duration(1000)
- .delay(500)
- .style('left', ($totalOuterWidth - writerWidth)/2 + 'px')
- .style('top', ($totalOuterHeight - writerHeight)/2 + 'px')
- .style('width', writerWidth + 'px')
- .style('height', writerHeight + 'px')
- .style('border-radius', '3px')
+ makeCard '', ->
+ editCont.style('display', null)
+ writerDrawer = drawer
+ editor.property('value', drawerState[writerDrawer].cards[0])
+ writer
+ .style('left', (d) -> drawerPos[writerDrawer].x + 'px')
+ .style('top', (d) -> (drawerPos[writerDrawer].y - drawerHeight) + 'px')
+ .style('width', drawerWidth + 'px')
+ .style('height', drawerHeight + 'px')
+ .style('border-radius', '0px')
+ .transition()
+ .duration(1000)
+ .delay(500)
+ .style('left', ($totalOuterWidth - writerWidth)/2 + 'px')
+ .style('top', ($totalOuterHeight - writerHeight)/2 + 'px')
+ .style('width', writerWidth + 'px')
+ .style('height', writerHeight + 'px')
+ .style('border-radius', '3px')
+ return
), delay)
return
@@ -296,49 +272,124 @@ hideLoading = ->
# -------------------------------------------------------
# -------------------------------------------------------
-if window.io
- console.log 'IO detected'
-
- socket = io.connect()
+drawerClaim = (d, cb) -> setTimeout(cb, 1, 'OK')
+makeCard = (text, cb) -> setTimeout(cb, 1, 'OK')
+notifyChange = -> return
+do ->
+ if window.io
+ console.log 'IO detected'
+
+ socket = io.connect()
+
+ socket.on 'connect', ->
+ socket.emit('register', 'DC')
+ return
+
+ socket.on 'drawerInfo', (dr) ->
+ console.log 'DRAWER INFO:', dr
+ for ix in [0...number]
+ for iy in [0...number]
+ id = "#{ix}_#{iy}"
+ drawerState[id] = {
+ cards: dr[id]?.cards or []
+ open: dr[id]?.claimed or false
+ }
+ updateDrawers()
+ 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 'drawerClaim', (drawer) ->
+ return unless drawer.match(/^\d+_\d+$/)
+ drawerState[drawer].open = true
+ return
+
+ socket.on 'drawerUnclaim', (drawer) ->
+ return unless drawer.match(/^\d+_\d+$/)
+ drawerState[drawer].open = false
+ return
+
+ socket.on 'reset', ->
+ console.log 'GOT reset'
+ resetDrawerState()
+ updateDrawers()
+ return
+
+ do ->
+ callback = null
+ socket.on 'drawerClaimResult', (res) ->
+ callback?(res)
+ callback = null
+ return
- socket.on 'connect', ->
- socket.emit('addClient', 'dc')
- return
+ drawerClaim = (d, cb) ->
+ callback = cb
+ socket.emit 'drawerClaim', d
+ return
- socket.on 'updateDrawers', (dr) ->
- console.log 'DRAWERS!', dr
- for k,v of dr
- drawerState[k] = v or { open: false, cards: [] }
- updateDrawers()
- hideLoading()
- return
+ do ->
+ callback = null
+ socket.on 'makeCardResult', (res) ->
+ callback?(res)
+ callback = null
+ return
- socket.on 'drawerChange', (drawer, state) ->
- console.log 'GOT drawerChange', drawer
- for d in drawers
- if d is drawer
- drawerState[d] = state
- updateDrawers()
+ makeCard = (text, cb) ->
+ callback = cb
+ socket.emit 'makeCard', text
return
- return
- socket.on 'reset', ->
- console.log 'GOT reset'
- resetDrawerState()
- updateDrawers()
- return
+ notifyChange = (d) ->
+ socket.emit('drawerChange', d, drawerState[d])
+ return
+ else
+ console.log 'IO not detected :-('
- notifyChange = (d) ->
- socket.emit('drawerChange', d, drawerState[d])
- return
-else
- console.log 'IO not detected :-('
+ msgs = "
+Dear DC, It's all theatre, and some of it's bad, but I still love it. - Shira
+-----
+Dear D.C, I've been pretty serious with New York, but if one of your fine law firms gives me a job, I'm pretty sure I'd break up with her for you. Love, a frustrated 3L.
+Tho I will always love you, i don't have to like you right now.
+-----
+I have yet to experience another city who supports the arts with the same generosity. DC is my haven for the arts.
+-----
+Dear DC, you're the most kickass and most vibrant big town I've ever met. You have your own music, your own art culture, you have waterfronts and parks and rivers. There's more to you than just stately buildings filled with pretentious people, and I'm lucky to have grown up here and experienced the real dc. Best of all, you never make me feel like I'm alone, or just another number in a swarm of people on the street: you're a city that actually feels like a home. ALL my love, Lida
+-----
+Dear DC, thank you for letting me see your big blue sky on my way to work and during lunch. And giving me access to free education in the Smithsonian institutes. I hope to bring my children to see your beautiful museums and exhibits. One day, I will leave you to return to my home city. But I will always remember you and your sky.
+-----
+Dear DC, We should have gotten to know each other when we had the chance. My friend thinks you're really great. Love Gabi
+-----
+Dear DC, I've loved you from afar all these years. I'm looking forward to getting to know you better. Love, Becca
+-----
+The monuments inspire me to think of the founding principles that make our country great. They give me hope that we can remember who we are as a nation.
+-----
+Dear DC, I love standing next to Lincoln and looking up at a giant for democracy and freedom
+-----
+Hey DC, thanks for the clean ride… I like your metro
+-----
+Dear DC, I love you for fostering a surprising intelligent community of artists!
+-----
+To the District of Columbia - thank you for your hidden gardens in Georgetown
+-----
+In 2002, I walked for the Homeless in DC, it's the one place I felt I made a difference.
+"
- for d in drawers
- d.cards = if Math.random() > 0.85 then [msgs[Math.floor(Math.random() * msgs.length)]] else []
+ msgs = msgs.split('-----')
+
+ for d in drawers
+ drawerState[d] = {
+ cards: if Math.random() > 0.85 then [msgs[Math.floor(Math.random() * msgs.length)]] else []
+ open: false
+ }
+
+ hideLoading()
- hideLoading()
- notifyChange = -> return
View
204 public/muse.js
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.3.1
(function() {
- var $totalInnerHeight, $totalInnerWidth, $totalOuterHeight, $totalOuterWidth, box_click, closeWriter, cross, d, drawerChest, drawerClassFn, drawerDepth, drawerHeight, drawerPos, drawerState, drawerWidth, drawers, drawersCont, gap, hideLoading, id, ix, iy, makeWriter, make_box, make_cards, msgs, myDrawer, next, notifyChange, number, openDepth, resetDrawerState, scale, socket, updateDrawers, writerHeight, writerWidth, x, y, _i, _j, _k, _len;
+ var $totalInnerHeight, $totalInnerWidth, $totalOuterHeight, $totalOuterWidth, closeWriter, cross, drawerChest, drawerClaim, drawerClassFn, drawerClick, drawerDepth, drawerHeight, drawerPos, drawerState, drawerWidth, drawers, drawersCont, gap, hideLoading, id, ix, iy, makeCard, makeWriter, make_box, make_cards, myDrawer, next, notifyChange, number, openDepth, resetDrawerState, scale, updateDrawers, writerHeight, writerWidth, x, y, _i, _j;
if (window.console == null) {
window.console = {
@@ -35,10 +35,6 @@
$totalOuterHeight = $totalInnerHeight + drawerHeight + gap * 2;
- msgs = "Dear DC, It's all theatre, and some of it's bad, but I still love it. - Shira-----Dear D.C, I've been pretty serious with New York, but if one of your fine law firms gives me a job, I'm pretty sure I'd break up with her for you. Love, a frustrated 3L.Tho I will always love you, i don't have to like you right now.-----I have yet to experience another city who supports the arts with the same generosity. DC is my haven for the arts.-----Dear DC, you're the most kickass and most vibrant big town I've ever met. You have your own music, your own art culture, you have waterfronts and parks and rivers. There's more to you than just stately buildings filled with pretentious people, and I'm lucky to have grown up here and experienced the real dc. Best of all, you never make me feel like I'm alone, or just another number in a swarm of people on the street: you're a city that actually feels like a home. ALL my love, Lida-----Dear DC, thank you for letting me see your big blue sky on my way to work and during lunch. And giving me access to free education in the Smithsonian institutes. I hope to bring my children to see your beautiful museums and exhibits. One day, I will leave you to return to my home city. But I will always remember you and your sky.-----Dear DC, We should have gotten to know each other when we had the chance. My friend thinks you're really great. Love Gabi-----Dear DC, I've loved you from afar all these years. I'm looking forward to getting to know you better. Love, Becca-----The monuments inspire me to think of the founding principles that make our country great. They give me hope that we can remember who we are as a nation.-----Dear DC, I love standing next to Lincoln and looking up at a giant for democracy and freedom-----Hey DC, thanks for the clean ride… I like your metro-----Dear DC, I love you for fostering a surprising intelligent community of artists!-----To the District of Columbia - thank you for your hidden gardens in Georgetown-----In 2002, I walked for the Homeless in DC, it's the one place I felt I made a difference.";
-
- msgs = msgs.split('-----');
-
drawers = [];
drawerPos = {};
@@ -197,32 +193,39 @@
myDrawer = null;
- box_click = function(d) {
- if (myDrawer) {
- drawerState[myDrawer].open = false;
- notifyChange(myDrawer);
+ drawerClick = function(d) {
+ if (drawerState[d].open) {
+ return;
}
- if (myDrawer === d) {
- myDrawer = null;
- } else {
- myDrawer = d;
- drawerState[d].open = true;
- if (drawerState[d].open && drawerState[d].cards.length === 0) {
- drawerState[d].cards.push('');
+ drawerClaim(d, function(res) {
+ console.log('claim result:', res);
+ if (res !== 'OK') {
+ return;
}
- if (drawerState[d].open) {
+ if (myDrawer) {
+ drawerState[myDrawer].open = false;
+ notifyChange(myDrawer);
+ }
+ if (myDrawer === d) {
+ myDrawer = null;
+ } else {
+ myDrawer = d;
+ drawerState[d].open = true;
+ if (drawerState[d].cards.length === 0) {
+ drawerState[d].cards.push('');
+ }
makeWriter(d);
+ notifyChange(d);
}
- notifyChange(d);
- }
- updateDrawers();
+ updateDrawers();
+ });
};
drawerChest.selectAll('div.drawer').data(drawers).enter().append('div').attr('class', drawerClassFn).style('left', function(d) {
return drawerPos[d].x + 'px';
}).style('top', function(d) {
return drawerPos[d].y + 'px';
- }).on('click', box_click).call(make_box);
+ }).on('click', drawerClick).call(make_box);
updateDrawers = function() {
drawerChest.selectAll('div.drawer').attr('class', drawerClassFn).call(make_cards);
@@ -240,14 +243,16 @@
delay = 2000;
}
setTimeout((function() {
- editCont.style('display', null);
- writerDrawer = drawer;
- editor.property('value', drawerState[writerDrawer].cards[0]);
- return writer.style('left', function(d) {
- return drawerPos[writerDrawer].x + 'px';
- }).style('top', function(d) {
- return (drawerPos[writerDrawer].y - drawerHeight) + 'px';
- }).style('width', drawerWidth + 'px').style('height', drawerHeight + 'px').style('border-radius', '0px').transition().duration(1000).delay(500).style('left', ($totalOuterWidth - writerWidth) / 2 + 'px').style('top', ($totalOuterHeight - writerHeight) / 2 + 'px').style('width', writerWidth + 'px').style('height', writerHeight + 'px').style('border-radius', '3px');
+ return makeCard('', function() {
+ editCont.style('display', null);
+ writerDrawer = drawer;
+ editor.property('value', drawerState[writerDrawer].cards[0]);
+ writer.style('left', function(d) {
+ return drawerPos[writerDrawer].x + 'px';
+ }).style('top', function(d) {
+ return (drawerPos[writerDrawer].y - drawerHeight) + 'px';
+ }).style('width', drawerWidth + 'px').style('height', drawerHeight + 'px').style('border-radius', '0px').transition().duration(1000).delay(500).style('left', ($totalOuterWidth - writerWidth) / 2 + 'px').style('top', ($totalOuterHeight - writerHeight) / 2 + 'px').style('width', writerWidth + 'px').style('height', writerHeight + 'px').style('border-radius', '3px');
+ });
}), delay);
};
closeWriter = function() {
@@ -274,53 +279,108 @@
return d3.select('.loading-cont').style('opacity', 1).transition().duration(1000).style('opacity', 0).remove();
};
- if (window.io) {
- console.log('IO detected');
- socket = io.connect();
- socket.on('connect', function() {
- socket.emit('addClient', 'dc');
- });
- socket.on('updateDrawers', function(dr) {
- var k, v;
- console.log('DRAWERS!', dr);
- for (k in dr) {
- v = dr[k];
- drawerState[k] = v || {
- open: false,
- cards: []
+ drawerClaim = function(d, cb) {
+ return setTimeout(cb, 1, 'OK');
+ };
+
+ makeCard = function(text, cb) {
+ return setTimeout(cb, 1, 'OK');
+ };
+
+ notifyChange = function() {};
+
+ (function() {
+ var d, msgs, socket, _k, _len;
+ if (window.io) {
+ console.log('IO detected');
+ socket = io.connect();
+ socket.on('connect', function() {
+ socket.emit('register', 'DC');
+ });
+ socket.on('drawerInfo', function(dr) {
+ var ix, iy, _k, _l, _ref, _ref1;
+ console.log('DRAWER INFO:', dr);
+ for (ix = _k = 0; 0 <= number ? _k < number : _k > number; ix = 0 <= number ? ++_k : --_k) {
+ for (iy = _l = 0; 0 <= number ? _l < number : _l > number; iy = 0 <= number ? ++_l : --_l) {
+ id = "" + ix + "_" + iy;
+ drawerState[id] = {
+ cards: ((_ref = dr[id]) != null ? _ref.cards : void 0) || [],
+ open: ((_ref1 = dr[id]) != null ? _ref1.claimed : void 0) || false
+ };
+ }
+ }
+ updateDrawers();
+ hideLoading();
+ });
+ socket.on('putCard', function(drawer, card) {
+ if (!drawer.match(/^\d+_\d+$/)) {
+ return;
+ }
+ console.log('GOT putCard', drawer, card);
+ drawerState[drawer].cards.unshift(card);
+ updateDrawers();
+ });
+ socket.on('drawerClaim', function(drawer) {
+ if (!drawer.match(/^\d+_\d+$/)) {
+ return;
+ }
+ drawerState[drawer].open = true;
+ });
+ socket.on('drawerUnclaim', function(drawer) {
+ if (!drawer.match(/^\d+_\d+$/)) {
+ return;
+ }
+ drawerState[drawer].open = false;
+ });
+ socket.on('reset', function() {
+ console.log('GOT reset');
+ resetDrawerState();
+ updateDrawers();
+ });
+ (function() {
+ var callback;
+ callback = null;
+ socket.on('drawerClaimResult', function(res) {
+ if (typeof callback === "function") {
+ callback(res);
+ }
+ callback = null;
+ });
+ return drawerClaim = function(d, cb) {
+ callback = cb;
+ socket.emit('drawerClaim', d);
};
- }
- updateDrawers();
- hideLoading();
- });
- socket.on('drawerChange', function(drawer, state) {
- var d, _k, _len;
- console.log('GOT drawerChange', drawer);
+ })();
+ (function() {
+ var callback;
+ callback = null;
+ socket.on('makeCardResult', function(res) {
+ if (typeof callback === "function") {
+ callback(res);
+ }
+ callback = null;
+ });
+ return makeCard = function(text, cb) {
+ callback = cb;
+ socket.emit('makeCard', text);
+ };
+ })();
+ return notifyChange = function(d) {
+ socket.emit('drawerChange', d, drawerState[d]);
+ };
+ } else {
+ console.log('IO not detected :-(');
+ msgs = "Dear DC, It's all theatre, and some of it's bad, but I still love it. - Shira-----Dear D.C, I've been pretty serious with New York, but if one of your fine law firms gives me a job, I'm pretty sure I'd break up with her for you. Love, a frustrated 3L.Tho I will always love you, i don't have to like you right now.-----I have yet to experience another city who supports the arts with the same generosity. DC is my haven for the arts.-----Dear DC, you're the most kickass and most vibrant big town I've ever met. You have your own music, your own art culture, you have waterfronts and parks and rivers. There's more to you than just stately buildings filled with pretentious people, and I'm lucky to have grown up here and experienced the real dc. Best of all, you never make me feel like I'm alone, or just another number in a swarm of people on the street: you're a city that actually feels like a home. ALL my love, Lida-----Dear DC, thank you for letting me see your big blue sky on my way to work and during lunch. And giving me access to free education in the Smithsonian institutes. I hope to bring my children to see your beautiful museums and exhibits. One day, I will leave you to return to my home city. But I will always remember you and your sky.-----Dear DC, We should have gotten to know each other when we had the chance. My friend thinks you're really great. Love Gabi-----Dear DC, I've loved you from afar all these years. I'm looking forward to getting to know you better. Love, Becca-----The monuments inspire me to think of the founding principles that make our country great. They give me hope that we can remember who we are as a nation.-----Dear DC, I love standing next to Lincoln and looking up at a giant for democracy and freedom-----Hey DC, thanks for the clean ride… I like your metro-----Dear DC, I love you for fostering a surprising intelligent community of artists!-----To the District of Columbia - thank you for your hidden gardens in Georgetown-----In 2002, I walked for the Homeless in DC, it's the one place I felt I made a difference.";
+ msgs = msgs.split('-----');
for (_k = 0, _len = drawers.length; _k < _len; _k++) {
d = drawers[_k];
- if (d === drawer) {
- drawerState[d] = state;
- updateDrawers();
- return;
- }
+ drawerState[d] = {
+ cards: Math.random() > 0.85 ? [msgs[Math.floor(Math.random() * msgs.length)]] : [],
+ open: false
+ };
}
- });
- socket.on('reset', function() {
- console.log('GOT reset');
- resetDrawerState();
- updateDrawers();
- });
- notifyChange = function(d) {
- socket.emit('drawerChange', d, drawerState[d]);
- };
- } else {
- console.log('IO not detected :-(');
- for (_k = 0, _len = drawers.length; _k < _len; _k++) {
- d = drawers[_k];
- d.cards = Math.random() > 0.85 ? [msgs[Math.floor(Math.random() * msgs.length)]] : [];
+ return hideLoading();
}
- hideLoading();
- notifyChange = function() {};
- }
+ })();
}).call(this);
Please sign in to comment.
Something went wrong with that request. Please try again.