Skip to content
Browse files

go streams go

  • Loading branch information...
1 parent 9ac1cd4 commit a2247859b7ce61f6060ac3718ce7b994c4036352 @Raynos committed Aug 25, 2012
Showing with 126 additions and 25 deletions.
  1. +1 −1 index.js
  2. +13 −0 map/index.js
  3. +4 −1 package.json
  4. +20 −0 player/attribute.js
  5. +7 −4 player/index.js
  6. +15 −7 player/widget.js
  7. +64 −12 static/bundle.js
  8. +2 −0 wall/widget.js
View
2 index.js
@@ -4,7 +4,7 @@ var Map = require("./map")
, body = document.body
var map = Map()
- , player = Player()
+ , player = Player(50, 50)
map.addEntity(player)
View
13 map/index.js
@@ -1,4 +1,5 @@
var Widget = require("./widget")
+ , through = require("through")
module.exports = Map
@@ -13,8 +14,20 @@ function Map() {
return map
+ /*
+ When an entity emit deltas in position we pipe it through a
+ validator which checks collisions and then
+ pipe it back into the entity if the validator thinks there are
+ no collisions
+ */
function addEntity(entity) {
+ entity.pipe(through(detectCollisions)).pipe(entity)
+
addBlock(entity)
+
+ function detectCollisions(data) {
+
+ }
}
function addBlock(block) {
View
5 package.json
@@ -23,7 +23,10 @@
"through": "~0.1.4",
"fragment": "~0.2.0",
"svg": "0.0.1",
- "arrow-keys": "0.0.1"
+ "arrow-keys": "0.0.1",
+ "node-uuid": "~1.3.3",
+ "duplexer": "0.0.2",
+ "iterators": "~0.3.0"
},
"devDependencies": {},
"licenses": [
View
20 player/attribute.js
@@ -0,0 +1,20 @@
+var forEach = require("iterators").forEachSync
+ , through = require("through")
+
+module.exports = AttributeStream
+
+function AttributeStream(elem) {
+ var stream = through(updateAttribute)
+
+ return stream
+
+ function updateAttribute(data) {
+ var changes = data[0]
+
+ forEach(changes, setAttribute)
+ }
+
+ function setAttribute(value, key) {
+ elem.setAttribute(key, value)
+ }
+}
View
11 player/index.js
@@ -14,17 +14,20 @@ module.exports = Player
Generally you hook the input up to the change requests and you hook the
state upto the widget for rendering
*/
-function Player() {
+function Player(x, y) {
var input = ArrowKeys()
- , widget = Widget()
+ , widget = Widget(x, y)
, change = PositionChangeStream(SPEED)
- , stateStream = DeltaStream()
- , state = stateStream.createObservable()
+ , state = DeltaStream()
, player = duplex(state, change)
player.appendTo = widget.appendTo
+ player.x = x
+ player.y = y
input.pipe(change)
+ state.pipe(widget)
+
return player
}
View
22 player/widget.js
@@ -1,13 +1,21 @@
var Element = require("svg")
+ , svg = require("./player")
+ , AttributeStream = require("./attribute")
module.exports = Widget
-function Widget() {
-
-
- return {
- appendTo: appendTo
- }
+function Widget(x, y) {
+ var elem = Element(svg)
+ , stream = AttributeStream(elem)
+
+ elem.setAttribute("x", x)
+ elem.setAttribute("y", y)
+
+ stream.appendTo = appendTo
- function appendTo() {}
+ return stream
+
+ function appendTo(other) {
+ other.appendChild(elem)
+ }
}
View
76 static/bundle.js
@@ -202,7 +202,7 @@ require.define("/node_modules/vm-browserify/package.json",Function(['require','m
require.define("/node_modules/vm-browserify/index.js",Function(['require','module','exports','__dirname','__filename','process'],"var Object_keys = function (obj) {\n if (Object.keys) return Object.keys(obj)\n else {\n var res = [];\n for (var key in obj) res.push(key)\n return res;\n }\n};\n\nvar forEach = function (xs, fn) {\n if (xs.forEach) return xs.forEach(fn)\n else for (var i = 0; i < xs.length; i++) {\n fn(xs[i], i, xs);\n }\n};\n\nvar Script = exports.Script = function NodeScript (code) {\n if (!(this instanceof Script)) return new Script(code);\n this.code = code;\n};\n\nScript.prototype.runInNewContext = function (context) {\n if (!context) context = {};\n \n var iframe = document.createElement('iframe');\n if (!iframe.style) iframe.style = {};\n iframe.style.display = 'none';\n \n document.body.appendChild(iframe);\n \n var win = iframe.contentWindow;\n \n forEach(Object_keys(context), function (key) {\n win[key] = context[key];\n });\n \n if (!win.eval && win.execScript) {\n // win.eval() magically appears when this is called in IE:\n win.execScript('null');\n }\n \n var res = win.eval(this.code);\n \n forEach(Object_keys(win), function (key) {\n context[key] = win[key];\n });\n \n document.body.removeChild(iframe);\n \n return res;\n};\n\nScript.prototype.runInThisContext = function () {\n return eval(this.code); // maybe...\n};\n\nScript.prototype.runInContext = function (context) {\n // seems to be just runInNewContext on magical context objects which are\n // otherwise indistinguishable from objects except plain old objects\n // for the parameter segfaults node\n return this.runInNewContext(context);\n};\n\nforEach(Object_keys(Script.prototype), function (name) {\n exports[name] = Script[name] = function (code) {\n var s = Script(code);\n return s[name].apply(s, [].slice.call(arguments, 1));\n };\n});\n\nexports.createScript = function (code) {\n return exports.Script(code);\n};\n\nexports.createContext = Script.createContext = function (context) {\n // not really sure what this one does\n // seems to just make a shallow copy\n var copy = {};\n if(typeof context === 'object') {\n forEach(Object_keys(context), function (key) {\n copy[key] = context[key];\n });\n }\n return copy;\n};\n\n//@ sourceURL=/node_modules/vm-browserify/index.js"));
-require.define("/map/index.js",Function(['require','module','exports','__dirname','__filename','process'],"var Widget = require(\"./widget\")\n\nmodule.exports = Map\n\nfunction Map() {\n var widget = Widget(600, 400)\n , blocks = {}\n , map = {}\n\n map.addEntity = addEntity\n map.addBlock = addBlock\n map.appendTo = widget.appendTo\n\n return map\n\n function addEntity(entity) {\n addBlock(entity)\n }\n\n function addBlock(block) {\n blocks[block.x + \":\" + block.y] = block\n widget.addBlock(block)\n }\n}\n//@ sourceURL=/map/index.js"));
+require.define("/map/index.js",Function(['require','module','exports','__dirname','__filename','process'],"var Widget = require(\"./widget\")\n , through = require(\"through\")\n\nmodule.exports = Map\n\nfunction Map() {\n var widget = Widget(600, 400)\n , blocks = {}\n , map = {}\n\n map.addEntity = addEntity\n map.addBlock = addBlock\n map.appendTo = widget.appendTo\n\n return map\n\n /*\n When an entity emit deltas in position we pipe it through a\n validator which checks collisions and then\n pipe it back into the entity if the validator thinks there are\n no collisions\n */\n function addEntity(entity) {\n entity.pipe(through(detectCollisions)).pipe(entity)\n\n addBlock(entity)\n\n function detectCollisions(data) {\n \n }\n }\n\n function addBlock(block) {\n blocks[block.x + \":\" + block.y] = block\n widget.addBlock(block)\n }\n}\n//@ sourceURL=/map/index.js"));
require.define("/map/widget.js",Function(['require','module','exports','__dirname','__filename','process'],"var svg = require(\"./map.svg\")\n , Fragment = require(\"fragment\")\n\nmodule.exports = Widget\n\nfunction Widget(width, height) {\n var elem = Fragment(svg).firstChild\n elem.setAttribute(\"width\", width)\n elem.setAttribute(\"height\", height)\n\n return {\n appendTo: appendTo\n , addBlock: addBlock\n }\n \n function appendTo(other) {\n other.appendChild(elem)\n }\n\n function addBlock(block) {\n block.appendTo(elem)\n }\n}\n//@ sourceURL=/map/widget.js"));
@@ -212,10 +212,6 @@ require.define("/node_modules/fragment/package.json",Function(['require','module
require.define("/node_modules/fragment/index.js",Function(['require','module','exports','__dirname','__filename','process'],"Fragment.Element = Element\n\nmodule.exports = Fragment\n\nfunction Fragment(html, elementName) {\n var el = document.createElement(elementName || \"div\")\n , fragment = document.createDocumentFragment()\n\n el.innerHTML = html\n\n while (el.hasChildNodes()) {\n fragment.appendChild(el.firstChild)\n }\n\n return fragment\n}\n\nfunction Element(html, elementName) {\n var el = document.createElement(elementName || \"div\")\n\n el.innerHTML = html\n\n var child = el.firstChild\n el.removeChild(child)\n\n return child\n}\n//@ sourceURL=/node_modules/fragment/index.js"));
-require.define("/player/index.js",Function(['require','module','exports','__dirname','__filename','process'],"var Input = require(\"./input\")\n , Widget = require(\"./widget\")\n , DeltaStream = require(\"delta-stream\")\n\nmodule.exports = Player\n\nfunction Player() {\n var input = Input()\n , widget = Widget()\n , player = {}\n\n player.appendTo = widget.appendTo\n\n return player\n}\n//@ sourceURL=/player/index.js"));
-
-require.define("/player/input.js",Function(['require','module','exports','__dirname','__filename','process'],"var through = require(\"through\")\n , KEYS = {\n \"37\": \"left\"\n , \"38\": \"up\"\n , \"39\": \"right\"\n , \"40\": \"down\"\n }\n , LEFT = 37\n , UP = 38\n , RIGHT = 39\n , DOWN = 40\n\nmodule.exports = Input\n\nfunction Input() {\n var stream = through()\n\n window.addEventListener(\"keydown\", listenOnKeys)\n\n return stream\n\n function listenOnKeys(event) {\n var key = KEYS[event.which]\n \n if (key) {\n stream.write(key)\n }\n }\n}\n//@ sourceURL=/player/input.js"));
-
require.define("/node_modules/through/package.json",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = {\"main\":\"index.js\"}\n//@ sourceURL=/node_modules/through/package.json"));
require.define("/node_modules/through/index.js",Function(['require','module','exports','__dirname','__filename','process'],"var Stream = require('stream')\n\n// through\n//\n// a stream that does nothing but re-emit the input.\n// useful for aggregating a series of changing but not ending streams into one stream)\n\nexports = module.exports = through\nthrough.through = through\n\n//create a readable writable stream.\n\nfunction through (write, end) {\n write = write || function (data) { this.emit('data', data) }\n end = end || function () { this.emit('end') }\n\n var ended = false, destroyed = false\n var stream = new Stream()\n stream.readable = stream.writable = true\n stream.paused = false \n stream.write = function (data) {\n write.call(this, data)\n return !stream.paused\n }\n //this will be registered as the first 'end' listener\n //must call destroy next tick, to make sure we're after any\n //stream piped from here. \n stream.on('end', function () {\n stream.readable = false\n if(!stream.writable)\n process.nextTick(function () {\n stream.destroy()\n })\n })\n\n stream.end = function (data) {\n if(ended) return \n //this breaks, because pipe doesn't check writable before calling end.\n //throw new Error('cannot call end twice')\n ended = true\n if(arguments.length) stream.write(data)\n this.writable = false\n end.call(this)\n if(!this.readable)\n this.destroy()\n }\n stream.destroy = function () {\n if(destroyed) return\n destroyed = true\n ended = true\n stream.writable = stream.readable = false\n stream.emit('close')\n }\n stream.pause = function () {\n if(stream.paused) return\n stream.paused = true\n stream.emit('pause')\n }\n stream.resume = function () {\n if(stream.paused) {\n stream.paused = false\n stream.emit('drain')\n }\n }\n return stream\n}\n\n\n//@ sourceURL=/node_modules/through/index.js"));
@@ -226,7 +222,57 @@ require.define("events",Function(['require','module','exports','__dirname','__fi
require.define("util",Function(['require','module','exports','__dirname','__filename','process'],"var events = require('events');\n\nexports.print = function () {};\nexports.puts = function () {};\nexports.debug = function() {};\n\nvar formatRegExp = /%[sdj%]/g;\nexports.format = function(f) {\n if (typeof f !== 'string') {\n var objects = [];\n for (var i = 0; i < arguments.length; i++) {\n objects.push(inspect(arguments[i]));\n }\n return objects.join(' ');\n }\n\n var i = 1;\n var args = arguments;\n var len = args.length;\n var str = String(f).replace(formatRegExp, function(x) {\n if (x === '%%') return '%';\n if (i >= len) return x;\n switch (x) {\n case '%s': return String(args[i++]);\n case '%d': return Number(args[i++]);\n case '%j': return JSON.stringify(args[i++]);\n default:\n return x;\n }\n });\n for (var x = args[i]; i < len; x = args[++i]) {\n if (x === null || typeof x !== 'object') {\n str += ' ' + x;\n } else {\n str += ' ' + inspect(x);\n }\n }\n return str;\n};\n\n\n/**\n * Echos the value of a value. Trys to print the value out\n * in the best way possible given the different types.\n *\n * @param {Object} obj The object to print out.\n * @param {Boolean} showHidden Flag that shows hidden (not enumerable)\n * properties of objects.\n * @param {Number} depth Depth in which to descend in object. Default is 2.\n * @param {Boolean} colors Flag to turn on ANSI escape codes to color the\n * output. Default is false (no coloring).\n */\nfunction inspect(obj, showHidden, depth, colors) {\n var ctx = {\n showHidden: showHidden,\n seen: [],\n stylize: colors ? stylizeWithColor : stylizeNoColor\n };\n return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));\n}\nexports.inspect = inspect;\n\n\n// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics\nvar colors = {\n 'bold' : [1, 22],\n 'italic' : [3, 23],\n 'underline' : [4, 24],\n 'inverse' : [7, 27],\n 'white' : [37, 39],\n 'grey' : [90, 39],\n 'black' : [30, 39],\n 'blue' : [34, 39],\n 'cyan' : [36, 39],\n 'green' : [32, 39],\n 'magenta' : [35, 39],\n 'red' : [31, 39],\n 'yellow' : [33, 39]\n};\n\n// Don't use 'blue' not visible on cmd.exe\nvar styles = {\n 'special': 'cyan',\n 'number': 'yellow',\n 'boolean': 'yellow',\n 'undefined': 'grey',\n 'null': 'bold',\n 'string': 'green',\n 'date': 'magenta',\n // \"name\": intentionally not styling\n 'regexp': 'red'\n};\n\n\nfunction stylizeWithColor(str, styleType) {\n var style = styles[styleType];\n\n if (style) {\n return '\\u001b[' + colors[style][0] + 'm' + str +\n '\\u001b[' + colors[style][1] + 'm';\n } else {\n return str;\n }\n}\n\n\nfunction stylizeNoColor(str, styleType) {\n return str;\n}\n\n\nfunction arrayToHash(array) {\n var hash = {};\n\n array.forEach(function(val, idx) {\n hash[val] = true;\n });\n\n return hash;\n}\n\n\nfunction formatValue(ctx, value, recurseTimes) {\n // Provide a hook for user-specified inspect functions.\n // Check that value is an object with an inspect function on it\n if (value && typeof value.inspect === 'function' &&\n // Filter out the util module, it's inspect function is special\n value.inspect !== exports.inspect &&\n // Also filter out any prototype objects using the circular check.\n !(value.constructor && value.constructor.prototype === value)) {\n return String(value.inspect(recurseTimes));\n }\n\n // Primitive types cannot have properties\n var primitive = formatPrimitive(ctx, value);\n if (primitive) {\n return primitive;\n }\n\n // Look up the keys of the object.\n var keys = Object_keys(value);\n var visibleKeys = arrayToHash(keys);\n\n if (ctx.showHidden) {\n keys = Object_getOwnPropertyNames(value);\n }\n\n // Some type of object without properties can be shortcutted.\n if (keys.length === 0) {\n if (typeof value === 'function') {\n var name = value.name ? ': ' + value.name : '';\n return ctx.stylize('[Function' + name + ']', 'special');\n }\n if (isRegExp(value)) {\n return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');\n }\n if (isDate(value)) {\n return ctx.stylize(Date.prototype.toString.call(value), 'date');\n }\n if (isError(value)) {\n return formatError(value);\n }\n }\n\n var base = '', array = false, braces = ['{', '}'];\n\n // Make Array say that they are Array\n if (isArray(value)) {\n array = true;\n braces = ['[', ']'];\n }\n\n // Make functions say that they are functions\n if (typeof value === 'function') {\n var n = value.name ? ': ' + value.name : '';\n base = ' [Function' + n + ']';\n }\n\n // Make RegExps say that they are RegExps\n if (isRegExp(value)) {\n base = ' ' + RegExp.prototype.toString.call(value);\n }\n\n // Make dates with properties first say the date\n if (isDate(value)) {\n base = ' ' + Date.prototype.toUTCString.call(value);\n }\n\n // Make error with message first say the error\n if (isError(value)) {\n base = ' ' + formatError(value);\n }\n\n if (keys.length === 0 && (!array || value.length == 0)) {\n return braces[0] + base + braces[1];\n }\n\n if (recurseTimes < 0) {\n if (isRegExp(value)) {\n return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');\n } else {\n return ctx.stylize('[Object]', 'special');\n }\n }\n\n ctx.seen.push(value);\n\n var output;\n if (array) {\n output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);\n } else {\n output = keys.map(function(key) {\n return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);\n });\n }\n\n ctx.seen.pop();\n\n return reduceToSingleString(output, base, braces);\n}\n\n\nfunction formatPrimitive(ctx, value) {\n switch (typeof value) {\n case 'undefined':\n return ctx.stylize('undefined', 'undefined');\n\n case 'string':\n var simple = '\\'' + JSON.stringify(value).replace(/^\"|\"$/g, '')\n .replace(/'/g, \"\\\\'\")\n .replace(/\\\\\"/g, '\"') + '\\'';\n return ctx.stylize(simple, 'string');\n\n case 'number':\n return ctx.stylize('' + value, 'number');\n\n case 'boolean':\n return ctx.stylize('' + value, 'boolean');\n }\n // For some reason typeof null is \"object\", so special case here.\n if (value === null) {\n return ctx.stylize('null', 'null');\n }\n}\n\n\nfunction formatError(value) {\n return '[' + Error.prototype.toString.call(value) + ']';\n}\n\n\nfunction formatArray(ctx, value, recurseTimes, visibleKeys, keys) {\n var output = [];\n for (var i = 0, l = value.length; i < l; ++i) {\n if (Object.prototype.hasOwnProperty.call(value, String(i))) {\n output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,\n String(i), true));\n } else {\n output.push('');\n }\n }\n keys.forEach(function(key) {\n if (!key.match(/^\\d+$/)) {\n output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,\n key, true));\n }\n });\n return output;\n}\n\n\nfunction formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {\n var name, str, desc;\n desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };\n if (desc.get) {\n if (desc.set) {\n str = ctx.stylize('[Getter/Setter]', 'special');\n } else {\n str = ctx.stylize('[Getter]', 'special');\n }\n } else {\n if (desc.set) {\n str = ctx.stylize('[Setter]', 'special');\n }\n }\n if (!visibleKeys.hasOwnProperty(key)) {\n name = '[' + key + ']';\n }\n if (!str) {\n if (ctx.seen.indexOf(desc.value) < 0) {\n if (recurseTimes === null) {\n str = formatValue(ctx, desc.value, null);\n } else {\n str = formatValue(ctx, desc.value, recurseTimes - 1);\n }\n if (str.indexOf('\\n') > -1) {\n if (array) {\n str = str.split('\\n').map(function(line) {\n return ' ' + line;\n }).join('\\n').substr(2);\n } else {\n str = '\\n' + str.split('\\n').map(function(line) {\n return ' ' + line;\n }).join('\\n');\n }\n }\n } else {\n str = ctx.stylize('[Circular]', 'special');\n }\n }\n if (typeof name === 'undefined') {\n if (array && key.match(/^\\d+$/)) {\n return str;\n }\n name = JSON.stringify('' + key);\n if (name.match(/^\"([a-zA-Z_][a-zA-Z_0-9]*)\"$/)) {\n name = name.substr(1, name.length - 2);\n name = ctx.stylize(name, 'name');\n } else {\n name = name.replace(/'/g, \"\\\\'\")\n .replace(/\\\\\"/g, '\"')\n .replace(/(^\"|\"$)/g, \"'\");\n name = ctx.stylize(name, 'string');\n }\n }\n\n return name + ': ' + str;\n}\n\n\nfunction reduceToSingleString(output, base, braces) {\n var numLinesEst = 0;\n var length = output.reduce(function(prev, cur) {\n numLinesEst++;\n if (cur.indexOf('\\n') >= 0) numLinesEst++;\n return prev + cur.length + 1;\n }, 0);\n\n if (length > 60) {\n return braces[0] +\n (base === '' ? '' : base + '\\n ') +\n ' ' +\n output.join(',\\n ') +\n ' ' +\n braces[1];\n }\n\n return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];\n}\n\n\nfunction isArray(ar) {\n return ar instanceof Array ||\n Array.isArray(ar) ||\n (ar && ar !== Object.prototype && isArray(ar.__proto__));\n}\n\n\nfunction isRegExp(re) {\n return re instanceof RegExp ||\n (typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]');\n}\n\n\nfunction isDate(d) {\n if (d instanceof Date) return true;\n if (typeof d !== 'object') return false;\n var properties = Date.prototype && Object_getOwnPropertyNames(Date.prototype);\n var proto = d.__proto__ && Object_getOwnPropertyNames(d.__proto__);\n return JSON.stringify(proto) === JSON.stringify(properties);\n}\n\nfunction isError(e) {\n return typeof e === 'object' && objectToString(e) === '[object Error]';\n}\nexports.isError = isError;\n\nfunction objectToString(o) {\n return Object.prototype.toString.call(o);\n}\n\n\nfunction pad(n) {\n return n < 10 ? '0' + n.toString(10) : n.toString(10);\n}\n\nvar months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',\n 'Oct', 'Nov', 'Dec'];\n\n// 26 Feb 16:19:34\nfunction timestamp() {\n var d = new Date();\n var time = [pad(d.getHours()),\n pad(d.getMinutes()),\n pad(d.getSeconds())].join(':');\n return [d.getDate(), months[d.getMonth()], time].join(' ');\n}\n\nexports.log = function (msg) {};\n\nexports.pump = null;\n\nvar Object_keys = Object.keys || function (obj) {\n var res = [];\n for (var key in obj) res.push(key);\n return res;\n};\n\nvar Object_getOwnPropertyNames = Object.getOwnPropertyNames || function (obj) {\n var res = [];\n for (var key in obj) {\n if (Object.hasOwnProperty.call(obj, key)) res.push(key);\n }\n return res;\n};\n\nvar Object_create = Object.create || function (prototype, properties) {\n // from es5-shim\n var object;\n if (prototype === null) {\n object = { '__proto__' : null };\n }\n else {\n if (typeof prototype !== 'object') {\n throw new TypeError(\n 'typeof prototype[' + (typeof prototype) + '] != \\'object\\''\n );\n }\n var Type = function () {};\n Type.prototype = prototype;\n object = new Type();\n object.__proto__ = prototype;\n }\n if (typeof properties !== 'undefined' && Object.defineProperties) {\n Object.defineProperties(object, properties);\n }\n return object;\n};\n\nexports.inherits = function(ctor, superCtor) {\n ctor.super_ = superCtor;\n ctor.prototype = Object_create(superCtor.prototype, {\n constructor: {\n value: ctor,\n enumerable: false,\n writable: true,\n configurable: true\n }\n });\n};\n\n//@ sourceURL=util"));
-require.define("/player/widget.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = Widget\n\nfunction Widget() {\n \n \n return {\n appendTo: appendTo\n }\n\n function appendTo() {}\n}\n//@ sourceURL=/player/widget.js"));
+require.define("/player/index.js",Function(['require','module','exports','__dirname','__filename','process'],"var ArrowKeys = require(\"arrow-keys\")\n , Widget = require(\"./widget\")\n , DeltaStream = require(\"delta-stream\")\n , PositionChangeStream = require(\"./positionChange\")\n , duplex = require(\"duplexer\")\n , SPEED = 1\n\nmodule.exports = Player\n\n/*\n A player is a stream which emits requested changes in state and which when\n written to changes the actual state.\n\n Generally you hook the input up to the change requests and you hook the\n state upto the widget for rendering\n*/\nfunction Player(x, y) {\n var input = ArrowKeys()\n , widget = Widget(x, y)\n , change = PositionChangeStream(SPEED)\n , state = DeltaStream()\n , player = duplex(state, change)\n\n player.appendTo = widget.appendTo\n player.x = x\n player.y = y\n\n input.pipe(change)\n\n state.pipe(widget)\n\n return player\n}\n//@ sourceURL=/player/index.js"));
+
+require.define("/node_modules/arrow-keys/package.json",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = {\"main\":\"index\"}\n//@ sourceURL=/node_modules/arrow-keys/package.json"));
+
+require.define("/node_modules/arrow-keys/index.js",Function(['require','module','exports','__dirname','__filename','process'],"var through = require(\"through\")\n , KEYS = {\n \"37\": \"left\"\n , \"38\": \"up\"\n , \"39\": \"right\"\n , \"40\": \"down\"\n }\n \nmodule.exports = ArrowKeys\n\nfunction ArrowKeys() {\n var stream = through()\n\n window.addEventListener(\"keydown\", listenOnKeys)\n\n return stream\n\n function listenOnKeys(event) {\n var key = KEYS[event.which]\n \n if (key) {\n stream.write(key)\n }\n }\n}\n//@ sourceURL=/node_modules/arrow-keys/index.js"));
+
+require.define("/player/widget.js",Function(['require','module','exports','__dirname','__filename','process'],"var Element = require(\"svg\")\n , svg = require(\"./player\")\n , AttributeStream = require(\"./attribute\")\n\nmodule.exports = Widget\n\nfunction Widget(x, y) {\n var elem = Element(svg)\n , stream = AttributeStream(elem)\n\n elem.setAttribute(\"x\", x)\n elem.setAttribute(\"y\", y)\n\n stream.appendTo = appendTo\n\n return stream\n\n function appendTo(other) {\n other.appendChild(elem)\n }\n}\n//@ sourceURL=/player/widget.js"));
+
+require.define("/node_modules/svg/package.json",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = {\"main\":\"index\"}\n//@ sourceURL=/node_modules/svg/package.json"));
+
+require.define("/node_modules/svg/index.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = Element\n\nfunction Element(svgText) {\n var parser = new DOMParser()\n , xmlText = \"<svg xmlns=\\'http://www.w3.org/2000/svg\\'>\" +\n svgText + \"</svg>\"\n , docElem = parser.parseFromString(xmlText, \"text/xml\").documentElement\n\n var node = docElem.firstChild\n document.importNode(node, true)\n return node\n}\n//@ sourceURL=/node_modules/svg/index.js"));
+
+require.define("/player/player.svg",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = '<rect width=\"20\" height=\"20\" fill=\"red\" stroke=\"black\" />'\n//@ sourceURL=/player/player.svg"));
+
+require.define("/player/attribute.js",Function(['require','module','exports','__dirname','__filename','process'],"var forEach = require(\"iterators\").forEachSync\n , through = require(\"through\")\n\nmodule.exports = AttributeStream\n\nfunction AttributeStream(elem) {\n var stream = through(updateAttribute)\n\n return stream\n\n function updateAttribute(data) {\n var changes = data[0]\n\n forEach(changes, setAttribute)\n }\n\n function setAttribute(value, key) {\n elem.setAttribute(key, value)\n }\n}\n//@ sourceURL=/player/attribute.js"));
+
+require.define("/node_modules/iterators/package.json",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = {\"main\":\"index\"}\n//@ sourceURL=/node_modules/iterators/package.json"));
+
+require.define("/node_modules/iterators/index.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = {\n // sync\n forEachSync: require(\"./lib/sync/forEach\")\n , filterSync: require(\"./lib/sync/filter\")\n , mapSync: require(\"./lib/sync/map\")\n , reduceSync: require(\"./lib/sync/reduce\")\n , reduceRightSync: require(\"./lib/sync/reduceRight\")\n , everySync: require(\"./lib/sync/every\")\n , someSync: require(\"./lib/sync/some\")\n // async\n , forEach: require(\"./lib/async/forEach\")\n , filter: require(\"./lib/async/filter\")\n , map: require(\"./lib/async/map\")\n , reduce: require(\"./lib/async/reduce\")\n , reduceRight: require(\"./lib/async/reduceRight\")\n , every: require(\"./lib/async/every\")\n , some: require(\"./lib/async/some\")\n}\n//@ sourceURL=/node_modules/iterators/index.js"));
+
+require.define("/node_modules/iterators/lib/sync/forEach.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = forEach\n\nfunction forEach(list, iterator, context) {\n var keys = Object.keys(list)\n\n if (arguments.length < 3) {\n context = this\n }\n\n for (var i = 0, len = keys.length; i < len; i++) {\n var key = keys[i]\n , value = list[key]\n \n iterator.call(context, value, key, list)\n }\n}\n//@ sourceURL=/node_modules/iterators/lib/sync/forEach.js"));
+
+require.define("/node_modules/iterators/lib/sync/filter.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = filter\n\nfunction filter(list, iterator, context) {\n var returnValue = Array.isArray(list) ? [] : {}\n , keys = Object.keys(list)\n\n if (arguments.length < 3) {\n context = this\n }\n\n for (var i = 0, len = keys.length; i < len; i++) {\n var key = keys[i]\n , value = list[key]\n , keepValue = iterator.call(context, value, key, list)\n\n if (keepValue) {\n if (Array.isArray(returnValue)) {\n returnValue.push(value)\n } else {\n returnValue[key] = value\n }\n }\n }\n\n return returnValue\n}\n//@ sourceURL=/node_modules/iterators/lib/sync/filter.js"));
+
+require.define("/node_modules/iterators/lib/sync/map.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = map\n\nfunction map(list, iterator, context) {\n var returnValue = Array.isArray(list) ? [] : {}\n , keys = Object.keys(list)\n\n if (arguments.length < 3) {\n context = this\n }\n\n for (var i = 0, len = keys.length; i < len; i++) {\n var key = keys[i]\n , value = list[key]\n , newValue = iterator.call(context, value, key, list)\n\n returnValue[key] = newValue\n }\n\n return returnValue\n}\n//@ sourceURL=/node_modules/iterators/lib/sync/map.js"));
+
+require.define("/node_modules/iterators/lib/sync/reduce.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = reduce\n\nfunction reduce(list, iterator, context, accumulator) {\n var keys = Object.keys(list)\n , i = 0\n\n if (arguments.length === 2) {\n context = this\n accumulator = list[0]\n i = 1\n } else if (arguments.length === 3) {\n accumulator = context\n context = this\n }\n\n for (var len = keys.length; i < len; i++) {\n var key = keys[i]\n , value = list[key]\n\n accumulator = iterator.call(context, accumulator, value, key, list)\n }\n\n return accumulator\n}\n//@ sourceURL=/node_modules/iterators/lib/sync/reduce.js"));
+
+require.define("/node_modules/iterators/lib/sync/reduceRight.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = reduceRight\n\nfunction reduceRight(list, iterator, context, accumulator) {\n var keys = Object.keys(list)\n , len = keys.length\n , i = len - 1\n\n if (arguments.length === 2) {\n context = this\n accumulator = list[i]\n i--\n } else if (arguments.length === 3) {\n accumulator = context\n context = this\n }\n\n for (; i >= 0; i--) {\n var key = keys[i]\n , value = list[key]\n\n accumulator = iterator.call(context, accumulator, value, key, list)\n }\n\n return accumulator\n}\n//@ sourceURL=/node_modules/iterators/lib/sync/reduceRight.js"));
+
+require.define("/node_modules/iterators/lib/sync/every.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = every\n\nfunction every(list, iterator, context) {\n var keys = Object.keys(list)\n , result\n\n if (arguments.length < 3) {\n context = this\n }\n\n for (var i = 0, len = keys.length; i < len; i++) {\n var key = keys[i]\n , value = list[key]\n \n result = iterator.call(context, value, key, list)\n\n if (!result) {\n return result\n }\n }\n\n return result\n}\n//@ sourceURL=/node_modules/iterators/lib/sync/every.js"));
+
+require.define("/node_modules/iterators/lib/sync/some.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = some\n\nfunction some(list, iterator, context) {\n var keys = Object.keys(list)\n , result = false\n\n if (arguments.length < 3) {\n context = this\n }\n\n for (var i = 0, len = keys.length; i < len; i++) {\n var key = keys[i]\n , value = list[key]\n \n result = iterator.call(context, value, key, list)\n\n if (result) {\n return result\n }\n }\n\n return result\n}\n//@ sourceURL=/node_modules/iterators/lib/sync/some.js"));
+
+require.define("/node_modules/iterators/lib/async/forEach.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = forEach\n\nfunction forEach(list, iterator, context, callback) {\n var keys = Object.keys(list)\n , count = keys.length\n\n if (typeof context === \"function\") {\n callback = context\n context = this\n }\n\n for (var i = 0, len = keys.length; i < len; i++) {\n var key = keys[i]\n , value = list[key]\n \n invokeIterator(iterator, next, context, value, key, list)\n }\n\n function next(err) {\n if (err) {\n return callback && callback(err)\n }\n\n if (--count === 0) {\n callback && callback(null)\n }\n }\n}\n\nfunction invokeIterator(iterator, done, context, value, key, list) {\n var length = iterator.length\n\n if (length === 1) {\n iterator.call(context, done)\n } else if (length === 2) {\n iterator.call(context, value, done)\n } else if (length === 3) {\n iterator.call(context, value, key, done)\n } else {\n iterator.call(context, value, key, list, done)\n }\n}\n//@ sourceURL=/node_modules/iterators/lib/async/forEach.js"));
+
+require.define("/node_modules/iterators/lib/async/filter.js",Function(['require','module','exports','__dirname','__filename','process'],"var partial = require(\"ap\").partial\n\nmodule.exports = filter\n\nfunction filter(list, iterator, context, callback) {\n var keys = Object.keys(list)\n , returnValue = Array.isArray(list) ? [] : {}\n , count = keys.length\n\n if (typeof context === \"function\") {\n callback = context\n context = this\n }\n\n for (var i = 0, len = keys.length; i < len; i++) {\n var key = keys[i]\n , value = list[key]\n \n invokeIterator(iterator,\n partial(next, value, key), context, value, key, list)\n }\n\n function next(value, key, err, keepValue) {\n if (err) {\n return callback && callback(err)\n }\n\n if (keepValue) {\n if (Array.isArray(returnValue)) {\n returnValue.push(value)\n } else {\n returnValue[key] = value\n }\n }\n\n if (--count === 0) {\n callback && callback(null, returnValue)\n }\n }\n}\n\nfunction invokeIterator(iterator, done, context, value, key, list) {\n var length = iterator.length\n\n if (length === 1) {\n iterator.call(context, done)\n } else if (length === 2) {\n iterator.call(context, value, done)\n } else if (length === 3) {\n iterator.call(context, value, key, done)\n } else {\n iterator.call(context, value, key, list, done)\n }\n}\n//@ sourceURL=/node_modules/iterators/lib/async/filter.js"));
+
+require.define("/node_modules/iterators/node_modules/ap/package.json",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = {\"main\":\"./index.js\"}\n//@ sourceURL=/node_modules/iterators/node_modules/ap/package.json"));
+
+require.define("/node_modules/iterators/node_modules/ap/index.js",Function(['require','module','exports','__dirname','__filename','process'],"exports = module.exports = ap;\nfunction ap (args, fn) {\n return function () {\n return fn.apply(this, args.concat.apply(args, arguments));\n };\n}\n\nexports.pa = pa;\nfunction pa (args, fn) {\n return function () {\n return fn.apply(this, [].slice.call(arguments).concat(args));\n };\n}\n\nexports.apa = apa;\nfunction apa (left, right, fn) {\n return function () {\n return fn.apply(this,\n left.concat.apply(left, arguments).concat(right)\n );\n };\n}\n\nexports.partial = partial;\nfunction partial (fn) {\n var args = [].slice.call(arguments, 1);\n return ap(args, fn);\n}\n\nexports.partialRight = partialRight;\nfunction partialRight (fn) {\n var args = [].slice.call(arguments, 1);\n return pa(args, fn);\n}\n\nexports.curry = curry;\nfunction curry (fn) {\n return partial(partial, fn);\n}\n\nexports.curryRight = function curryRight (fn) {\n return partial(partialRight, fn);\n}\n\n//@ sourceURL=/node_modules/iterators/node_modules/ap/index.js"));
+
+require.define("/node_modules/iterators/lib/async/map.js",Function(['require','module','exports','__dirname','__filename','process'],"var partial = require(\"ap\").partial\n\nmodule.exports = map\n\nfunction map(list, iterator, context, callback) {\n var keys = Object.keys(list)\n , returnValue = Array.isArray(list) ? [] : {}\n , count = keys.length\n\n if (typeof context === \"function\") {\n callback = context\n context = this\n }\n\n for (var i = 0, len = keys.length; i < len; i++) {\n var key = keys[i]\n , value = list[key]\n \n invokeIterator(iterator,\n partial(next, key), context, value, key, list)\n }\n\n function next(key, err, newValue) {\n if (err) {\n return callback && callback(err)\n }\n\n returnValue[key] = newValue\n\n if (--count === 0) {\n callback && callback(null, returnValue)\n }\n }\n}\n\nfunction invokeIterator(iterator, done, context, value, key, list) {\n var length = iterator.length\n\n if (length === 1) {\n iterator.call(context, done)\n } else if (length === 2) {\n iterator.call(context, value, done)\n } else if (length === 3) {\n iterator.call(context, value, key, done)\n } else {\n iterator.call(context, value, key, list, done)\n }\n}\n//@ sourceURL=/node_modules/iterators/lib/async/map.js"));
+
+require.define("/node_modules/iterators/lib/async/reduce.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = reduce\n\nfunction reduce(list, iterator, context, accumulator, callback) {\n var keys = Object.keys(list)\n , count = keys.length\n\n if (arguments.length === 3) {\n callback = context\n context = this\n accumulator = list[0]\n keys.shift()\n count--\n } else if (arguments.length === 4) {\n callback = accumulator\n accumulator = context\n context = this\n }\n\n go()\n\n function go() {\n var key = keys.shift()\n , value = list[key]\n\n invokeIterator(iterator, next, context, accumulator, value, key, list)\n }\n\n function next(err, value) {\n if (err) {\n return callback && callback(err)\n }\n\n accumulator = value\n\n if (--count === 0) {\n callback && callback(null, accumulator)\n } else {\n go()\n }\n }\n}\n\nfunction invokeIterator(iterator, done, context, acc, value, key, list) {\n var length = iterator.length\n\n if (length === 1) {\n iterator.call(context, done)\n } else if (length === 2) {\n iterator.call(context, acc, done)\n } else if (length === 3) {\n iterator.call(context, acc, value, done)\n } else if (length === 4) {\n iterator.call(context, acc, value, key, done)\n } else {\n iterator.call(context, acc, value, key, list, done)\n }\n}\n//@ sourceURL=/node_modules/iterators/lib/async/reduce.js"));
+
+require.define("/node_modules/iterators/lib/async/reduceRight.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = forEach\n\nfunction forEach(list, iterator, context, accumulator, callback) {\n var keys = Object.keys(list)\n , len = keys.length\n , count = keys.length\n\n if (arguments.length === 3) {\n callback = context\n context = this\n accumulator = list[len - 1]\n keys.pop()\n count--\n } else if (arguments.length === 4) {\n callback = accumulator\n accumulator = context\n context = this\n }\n\n go()\n\n function go() {\n var key = keys.pop()\n , value = list[key]\n\n invokeIterator(iterator, next, context, accumulator, value, key, list)\n }\n\n function next(err, value) {\n if (err) {\n return callback && callback(err)\n }\n\n accumulator = value\n\n if (--count === 0) {\n callback && callback(null, accumulator)\n } else {\n go()\n }\n }\n}\n\nfunction invokeIterator(iterator, done, context, acc, value, key, list) {\n var length = iterator.length\n\n if (length === 1) {\n iterator.call(context, done)\n } else if (length === 2) {\n iterator.call(context, acc, done)\n } else if (length === 3) {\n iterator.call(context, acc, value, done)\n } else if (length === 4) {\n iterator.call(context, acc, value, key, done)\n } else {\n iterator.call(context, acc, value, key, list, done)\n }\n}\n//@ sourceURL=/node_modules/iterators/lib/async/reduceRight.js"));
+
+require.define("/node_modules/iterators/lib/async/every.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = every\n\nfunction every(list, iterator, context, callback) {\n var keys = Object.keys(list)\n , count = keys.length\n\n if (typeof context === \"function\") {\n callback = context\n context = this\n }\n\n for (var i = 0, len = keys.length; i < len; i++) {\n var key = keys[i]\n , value = list[key]\n \n invokeIterator(iterator, next, context, value, key, list)\n }\n\n function next(err, result) {\n if (err) {\n return callback && callback(err)\n }\n\n if (!result) {\n return callback && callback(null, result)\n }\n\n if (--count === 0) {\n callback && callback(null, result)\n }\n }\n}\n\nfunction invokeIterator(iterator, done, context, value, key, list) {\n var length = iterator.length\n\n if (length === 1) {\n iterator.call(context, done)\n } else if (length === 2) {\n iterator.call(context, value, done)\n } else if (length === 3) {\n iterator.call(context, value, key, done)\n } else {\n iterator.call(context, value, key, list, done)\n }\n}\n//@ sourceURL=/node_modules/iterators/lib/async/every.js"));
+
+require.define("/node_modules/iterators/lib/async/some.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = forEach\n\nfunction forEach(list, iterator, context, callback) {\n var keys = Object.keys(list)\n , count = keys.length\n\n if (typeof context === \"function\") {\n callback = context\n context = this\n }\n\n for (var i = 0, len = keys.length; i < len; i++) {\n var key = keys[i]\n , value = list[key]\n \n invokeIterator(iterator, next, context, value, key, list)\n }\n\n function next(err, result) {\n if (err) {\n return callback && callback(err)\n }\n\n if (result) {\n return callback && callback(null, result)\n }\n\n if (--count === 0) {\n callback && callback(null, result)\n }\n }\n}\n\nfunction invokeIterator(iterator, done, context, value, key, list) {\n var length = iterator.length\n\n if (length === 1) {\n iterator.call(context, done)\n } else if (length === 2) {\n iterator.call(context, value, done)\n } else if (length === 3) {\n iterator.call(context, value, key, done)\n } else {\n iterator.call(context, value, key, list, done)\n }\n}\n//@ sourceURL=/node_modules/iterators/lib/async/some.js"));
require.define("/node_modules/delta-stream/package.json",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = {\"main\":\"index\"}\n//@ sourceURL=/node_modules/delta-stream/package.json"));
@@ -298,18 +344,24 @@ require.define("/node_modules/delta-stream/node_modules/ap/index.js",Function(['
require.define("/node_modules/delta-stream/interfaces/observable.js",Function(['require','module','exports','__dirname','__filename','process'],"var DeltaStream = require(\"../index\")\n , uuid = require(\"node-uuid\")\n , EventEmitter = require(\"events\").EventEmitter\n\nObservable.from = createStream\n\nmodule.exports = Observable\n\nfunction Observable(stream) {\n var observable = new EventEmitter()\n , state = {}\n\n observable.set = set\n observable.get = get\n observable.toJSON = toJSON\n observable.createStream = createStream\n observable.sync = sync\n\n if (stream) {\n observable.id = stream.id\n bind(observable, stream)\n } else {\n observable.id = uuid()\n }\n\n return observable\n\n function set(key, value, source) {\n var changes = {}\n\n state[key] = value\n changes[key] = value\n\n observable.emit(\"change\", changes, source)\n observable.emit(\"change:\" + key, value)\n }\n\n function get(key) {\n if (key) {\n return state[key]\n }\n\n return state\n }\n\n function toJSON() {\n return state\n }\n\n function sync(other) {\n Object.keys(state).forEach(callSet)\n\n function callSet(key) {\n other.set(key, state[key])\n }\n }\n\n}\n\nfunction createStream(observable) {\n var stream = DeltaStream(observable.id)\n\n bind(observable, stream)\n\n return stream\n}\n\nfunction bind(observable, stream) {\n observable.on(\"change\", onchange)\n\n stream.other.on(\"data\", ondata)\n\n function ondata(data) {\n var changes = data[0]\n , source = data[2]\n\n Object.keys(changes).forEach(applyChanges)\n\n function applyChanges(key) {\n var value = changes[key]\n observable.set(key, value, source)\n }\n }\n\n function onchange(changes, source) {\n var ts = Date.now()\n , data = [changes, ts, source]\n\n stream.other.write(data)\n }\n}\n//@ sourceURL=/node_modules/delta-stream/interfaces/observable.js"));
+require.define("/player/positionChange.js",Function(['require','module','exports','__dirname','__filename','process'],"var through = require(\"through\")\n , uuid = require(\"node-uuid\")\n\nmodule.exports = PositionChangeStream\n\nfunction PositionChangeStream(speed) {\n var id = uuid()\n return through(translateInput)\n\n function translateInput(type) {\n var changes = {}\n if (type === \"left\") {\n changes.x = -speed\n } else if (type === \"right\") {\n changes.x = +speed\n } else if (type === \"up\") {\n changes.y = -speed\n } else if (type === \"down\") {\n changes.y = +speed\n }\n\n this.emit(\"data\", [changes, Date.now(), id])\n }\n}\n//@ sourceURL=/player/positionChange.js"));
+
+require.define("/node_modules/node-uuid/package.json",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = {\"main\":\"./uuid.js\"}\n//@ sourceURL=/node_modules/node-uuid/package.json"));
+
+require.define("/node_modules/node-uuid/uuid.js",Function(['require','module','exports','__dirname','__filename','process'],"// node-uuid/uuid.js\n//\n// Copyright (c) 2010 Robert Kieffer\n// Dual licensed under the MIT and GPL licenses.\n// Documentation and details at https://github.com/broofa/node-uuid\n(function() {\n var _global = this;\n\n // Unique ID creation requires a high quality random # generator, but\n // Math.random() does not guarantee \"cryptographic quality\". So we feature\n // detect for more robust APIs, normalizing each method to return 128-bits\n // (16 bytes) of random data.\n var mathRNG, nodeRNG, whatwgRNG;\n\n // Math.random()-based RNG. All platforms, very fast, unknown quality\n var _rndBytes = new Array(16);\n mathRNG = function() {\n var r, b = _rndBytes, i = 0;\n\n for (var i = 0, r; i < 16; i++) {\n if ((i & 0x03) == 0) r = Math.random() * 0x100000000;\n b[i] = r >>> ((i & 0x03) << 3) & 0xff;\n }\n\n return b;\n }\n\n // WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto\n // WebKit only (currently), moderately fast, high quality\n if (_global.crypto && crypto.getRandomValues) {\n var _rnds = new Uint32Array(4);\n whatwgRNG = function() {\n crypto.getRandomValues(_rnds);\n\n for (var c = 0 ; c < 16; c++) {\n _rndBytes[c] = _rnds[c >> 2] >>> ((c & 0x03) * 8) & 0xff;\n }\n return _rndBytes;\n }\n }\n\n // Node.js crypto-based RNG - http://nodejs.org/docs/v0.6.2/api/crypto.html\n // Node.js only, moderately fast, high quality\n try {\n var _rb = require('crypto').randomBytes;\n nodeRNG = _rb && function() {\n return _rb(16);\n };\n } catch (e) {}\n\n // Select RNG with best quality\n var _rng = nodeRNG || whatwgRNG || mathRNG;\n\n // Buffer class to use\n var BufferClass = typeof(Buffer) == 'function' ? Buffer : Array;\n\n // Maps for number <-> hex string conversion\n var _byteToHex = [];\n var _hexToByte = {};\n for (var i = 0; i < 256; i++) {\n _byteToHex[i] = (i + 0x100).toString(16).substr(1);\n _hexToByte[_byteToHex[i]] = i;\n }\n\n // **`parse()` - Parse a UUID into it's component bytes**\n function parse(s, buf, offset) {\n var i = (buf && offset) || 0, ii = 0;\n\n buf = buf || [];\n s.toLowerCase().replace(/[0-9a-f]{2}/g, function(byte) {\n if (ii < 16) { // Don't overflow!\n buf[i + ii++] = _hexToByte[byte];\n }\n });\n\n // Zero out remaining bytes if string was short\n while (ii < 16) {\n buf[i + ii++] = 0;\n }\n\n return buf;\n }\n\n // **`unparse()` - Convert UUID byte array (ala parse()) into a string**\n function unparse(buf, offset) {\n var i = offset || 0, bth = _byteToHex;\n return bth[buf[i++]] + bth[buf[i++]] +\n bth[buf[i++]] + bth[buf[i++]] + '-' +\n bth[buf[i++]] + bth[buf[i++]] + '-' +\n bth[buf[i++]] + bth[buf[i++]] + '-' +\n bth[buf[i++]] + bth[buf[i++]] + '-' +\n bth[buf[i++]] + bth[buf[i++]] +\n bth[buf[i++]] + bth[buf[i++]] +\n bth[buf[i++]] + bth[buf[i++]];\n }\n\n // **`v1()` - Generate time-based UUID**\n //\n // Inspired by https://github.com/LiosK/UUID.js\n // and http://docs.python.org/library/uuid.html\n\n // random #'s we need to init node and clockseq\n var _seedBytes = _rng();\n\n // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)\n var _nodeId = [\n _seedBytes[0] | 0x01,\n _seedBytes[1], _seedBytes[2], _seedBytes[3], _seedBytes[4], _seedBytes[5]\n ];\n\n // Per 4.2.2, randomize (14 bit) clockseq\n var _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff;\n\n // Previous uuid creation time\n var _lastMSecs = 0, _lastNSecs = 0;\n\n // See https://github.com/broofa/node-uuid for API details\n function v1(options, buf, offset) {\n var i = buf && offset || 0;\n var b = buf || [];\n\n options = options || {};\n\n var clockseq = options.clockseq != null ? options.clockseq : _clockseq;\n\n // UUID timestamps are 100 nano-second units since the Gregorian epoch,\n // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so\n // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'\n // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.\n var msecs = options.msecs != null ? options.msecs : new Date().getTime();\n\n // Per 4.2.1.2, use count of uuid's generated during the current clock\n // cycle to simulate higher resolution clock\n var nsecs = options.nsecs != null ? options.nsecs : _lastNSecs + 1;\n\n // Time since last uuid creation (in msecs)\n var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;\n\n // Per 4.2.1.2, Bump clockseq on clock regression\n if (dt < 0 && options.clockseq == null) {\n clockseq = clockseq + 1 & 0x3fff;\n }\n\n // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new\n // time interval\n if ((dt < 0 || msecs > _lastMSecs) && options.nsecs == null) {\n nsecs = 0;\n }\n\n // Per 4.2.1.2 Throw error if too many uuids are requested\n if (nsecs >= 10000) {\n throw new Error('uuid.v1(): Can\\'t create more than 10M uuids/sec');\n }\n\n _lastMSecs = msecs;\n _lastNSecs = nsecs;\n _clockseq = clockseq;\n\n // Per 4.1.4 - Convert from unix epoch to Gregorian epoch\n msecs += 12219292800000;\n\n // `time_low`\n var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;\n b[i++] = tl >>> 24 & 0xff;\n b[i++] = tl >>> 16 & 0xff;\n b[i++] = tl >>> 8 & 0xff;\n b[i++] = tl & 0xff;\n\n // `time_mid`\n var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;\n b[i++] = tmh >>> 8 & 0xff;\n b[i++] = tmh & 0xff;\n\n // `time_high_and_version`\n b[i++] = tmh >>> 24 & 0xf | 0x10; // include version\n b[i++] = tmh >>> 16 & 0xff;\n\n // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)\n b[i++] = clockseq >>> 8 | 0x80;\n\n // `clock_seq_low`\n b[i++] = clockseq & 0xff;\n\n // `node`\n var node = options.node || _nodeId;\n for (var n = 0; n < 6; n++) {\n b[i + n] = node[n];\n }\n\n return buf ? buf : unparse(b);\n }\n\n // **`v4()` - Generate random UUID**\n\n // See https://github.com/broofa/node-uuid for API details\n function v4(options, buf, offset) {\n // Deprecated - 'format' argument, as supported in v1.2\n var i = buf && offset || 0;\n\n if (typeof(options) == 'string') {\n buf = options == 'binary' ? new BufferClass(16) : null;\n options = null;\n }\n options = options || {};\n\n var rnds = options.random || (options.rng || _rng)();\n\n // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n\n // Copy bytes to buffer, if provided\n if (buf) {\n for (var ii = 0; ii < 16; ii++) {\n buf[i + ii] = rnds[ii];\n }\n }\n\n return buf || unparse(rnds);\n }\n\n // Export public API\n var uuid = v4;\n uuid.v1 = v1;\n uuid.v4 = v4;\n uuid.parse = parse;\n uuid.unparse = unparse;\n uuid.BufferClass = BufferClass;\n\n // Export RNG options\n uuid.mathRNG = mathRNG;\n uuid.nodeRNG = nodeRNG;\n uuid.whatwgRNG = whatwgRNG;\n\n if (typeof(module) != 'undefined') {\n // Play nice with node.js\n module.exports = uuid;\n } else {\n // Play nice with browsers\n var _previousRoot = _global.uuid;\n\n // **`noConflict()` - (browser only) to reset global 'uuid' var**\n uuid.noConflict = function() {\n _global.uuid = _previousRoot;\n return uuid;\n }\n _global.uuid = uuid;\n }\n}());\n\n//@ sourceURL=/node_modules/node-uuid/uuid.js"));
+
+require.define("/node_modules/duplexer/package.json",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = {\"main\":\"index\"}\n//@ sourceURL=/node_modules/duplexer/package.json"));
+
+require.define("/node_modules/duplexer/index.js",Function(['require','module','exports','__dirname','__filename','process'],"var Stream = require(\"stream\")\n , writeMethods = [\"write\", \"end\", \"destroy\"]\n , readMethods = [\"resume\", \"pause\"]\n , readEvents = [\"data\", \"close\"]\n , slice = Array.prototype.slice\n\nmodule.exports = duplex\n\nfunction duplex(writer, reader) {\n var stream = new Stream()\n , ended = false\n\n Object.defineProperties(stream, {\n writable: {\n get: getWritable\n }\n , readable: {\n get: getReadable\n }\n })\n\n writeMethods.forEach(proxyWriter)\n\n readMethods.forEach(proxyReader)\n\n readEvents.forEach(proxyStream)\n\n reader.on(\"end\", handleEnd)\n\n writer.on(\"error\", reemit)\n reader.on(\"error\", reemit)\n\n return stream\n\n function getWritable() {\n return writer.writable\n }\n\n function getReadable() {\n return reader.readable\n }\n\n function proxyWriter(methodName) {\n stream[methodName] = method\n\n function method() {\n return writer[methodName].apply(writer, arguments)\n }\n }\n\n function proxyReader(methodName) {\n stream[methodName] = method\n\n function method() {\n stream.emit(methodName)\n var func = reader[methodName]\n if (func) {\n return func.apply(reader, arguments)\n }\n reader.emit(methodName)\n }\n }\n\n function proxyStream(methodName) {\n reader.on(methodName, reemit)\n\n function reemit() {\n var args = slice.call(arguments)\n args.unshift(methodName)\n stream.emit.apply(stream, args)\n }\n }\n\n function handleEnd() {\n if (ended) {\n return\n }\n ended = true\n var args = slice.call(arguments)\n args.unshift(\"end\")\n stream.emit.apply(stream, args)\n }\n\n function reemit(err) {\n stream.emit(\"error\", err)\n }\n}\n//@ sourceURL=/node_modules/duplexer/index.js"));
+
require.define("/levels/index.js",Function(['require','module','exports','__dirname','__filename','process'],"var Wall = require(\"../wall\")\n , SIZE = 20\n , tileTypes = {\n \"E\": noop\n , \"W\": Wall\n }\n\n/* map is 600 x 400. Size is 20 so we have 30 x 20 tiles */\nvar visual = [\n \"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WEEEEEEEEEEEEEEEEEEEEEEEEEEEEW\"\n , \"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\"\n]\n\nmodule.exports = Level\n\nfunction Level(map) {\n visual.forEach(function (row, y) {\n for (var x = 0; x < row.length; x++) {\n var block = tileTypes[row[x]](x * SIZE, y * SIZE)\n if (block) {\n map.addBlock(block)\n }\n }\n })\n}\n\nfunction noop() {}\n//@ sourceURL=/levels/index.js"));
require.define("/wall/index.js",Function(['require','module','exports','__dirname','__filename','process'],"var Widget = require(\"./widget\")\n\nmodule.exports = Widget\n//@ sourceURL=/wall/index.js"));
-require.define("/wall/widget.js",Function(['require','module','exports','__dirname','__filename','process'],"var svg = require(\"./wall.svg\")\n , Element = require(\"svg\")\n\nmodule.exports = Widget\n\nfunction Widget(x, y) {\n var elem = Element(svg, \"svg\")\n elem.setAttribute(\"x\", x)\n elem.setAttribute(\"y\", y)\n\n return {\n appendTo: appendTo\n }\n \n function appendTo(other) {\n other.appendChild(elem)\n }\n}\n//@ sourceURL=/wall/widget.js"));
+require.define("/wall/widget.js",Function(['require','module','exports','__dirname','__filename','process'],"var svg = require(\"./wall.svg\")\n , Element = require(\"svg\")\n\nmodule.exports = Widget\n\nfunction Widget(x, y) {\n var elem = Element(svg, \"svg\")\n elem.setAttribute(\"x\", x)\n elem.setAttribute(\"y\", y)\n\n return {\n appendTo: appendTo\n , x: x\n , y: y\n }\n \n function appendTo(other) {\n other.appendChild(elem)\n }\n}\n//@ sourceURL=/wall/widget.js"));
require.define("/wall/wall.svg",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = '<rect width=\"20\" height=\"20\" fill=\"grey\" stroke=\"black\" />'\n//@ sourceURL=/wall/wall.svg"));
-require.define("/node_modules/svg/package.json",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = {\"main\":\"index\"}\n//@ sourceURL=/node_modules/svg/package.json"));
-
-require.define("/node_modules/svg/index.js",Function(['require','module','exports','__dirname','__filename','process'],"module.exports = Element\n\nfunction Element(svgText) {\n var parser = new DOMParser()\n , xmlText = \"<svg xmlns=\\'http://www.w3.org/2000/svg\\'>\" +\n svgText + \"</svg>\"\n , docElem = parser.parseFromString(xmlText, \"text/xml\").documentElement\n\n var node = docElem.firstChild\n document.importNode(node, true)\n return node\n}\n//@ sourceURL=/node_modules/svg/index.js"));
-
-require.define("/index.js",Function(['require','module','exports','__dirname','__filename','process'],"var Map = require(\"./map\")\n , Player = require(\"./player\")\n , level = require(\"./levels\")\n , body = document.body\n\nvar map = Map()\n , player = Player()\n\nmap.addEntity(player)\n\nmap.appendTo(body)\n\nlevel(map)\n//@ sourceURL=/index.js"));
+require.define("/index.js",Function(['require','module','exports','__dirname','__filename','process'],"var Map = require(\"./map\")\n , Player = require(\"./player\")\n , level = require(\"./levels\")\n , body = document.body\n\nvar map = Map()\n , player = Player(50, 50)\n\nmap.addEntity(player)\n\nmap.appendTo(body)\n\nlevel(map)\n//@ sourceURL=/index.js"));
require("/index.js");
})();
View
2 wall/widget.js
@@ -10,6 +10,8 @@ function Widget(x, y) {
return {
appendTo: appendTo
+ , x: x
+ , y: y
}
function appendTo(other) {

0 comments on commit a224785

Please sign in to comment.
Something went wrong with that request. Please try again.