Permalink
Browse files

go streams go

  • Loading branch information...
Raynos committed Aug 26, 2012
1 parent 9ac1cd4 commit a2247859b7ce61f6060ac3718ce7b994c4036352
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
@@ -4,7 +4,7 @@ var Map = require("./map")
, body = document.body
var map = Map()
- , player = Player()
+ , player = Player(50, 50)
map.addEntity(player)
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -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.