var once = require("once")

var Player = require("./player")

module.exports = renderPlayer

function renderPlayer(paper, absolute, row) {
    var create = once(createEntity)

    row.on("change", function (changes) {
        if ("x" in row.state && "y" in row.state) {
            create()
        }

        absolute(changes)
    })

    function createEntity() {
        console.log("renderPlayer")
        var entity = Player(paper, {
            x: 300
            , y: 240
        })

        entity.on("change", function (changes) {
            var pos = {
                x: absolute.x
                , y: absolute.y
            }

            if (changes.x) {
                pos.x += changes.x
            }

            if (changes.y) {
                pos.y += changes.y
            }

            row.set(pos)
        })
    }
}

@@ -140,235 +140,36 @@
     
-var create = once(createEntity)%0A%0A    row.on(%22change%22, function (changes) %7B%0A        if (%22x%22 in row.state && %22y%22 in row.state) %7B%0A            create()%0A        %7D%0A%0A        absolute(changes)%0A    %7D)%0A%0A    function createEntity() %7B%0A    
+row.on(%22change%22, absolute)%0A%0A
     
@@ -196,28 +196,24 @@
 layer%22)%0A    
- 
-   
 var entity =
@@ -241,35 +241,57 @@
     
-    x: 300%0A            , y:
+x: row.state.x %7C%7C 300%0A        , y: row.state.y %7C%7C
  240
@@ -299,20 +299,16 @@
     
-  
-  
 %7D)%0A%0A    
     
@@ -303,20 +303,16 @@
 %7D)%0A%0A    
-  
-  
 entity.o
@@ -352,20 +352,16 @@
         
-    
 var pos 
@@ -364,20 +364,16 @@
 pos = %7B%0A
-    
         
@@ -398,28 +398,24 @@
             
-    
 , y: absolut
@@ -418,36 +418,32 @@
 olute.y%0A        
-    
 %7D%0A%0A            i
@@ -429,36 +429,32 @@
      %7D%0A%0A        
- 
-   
 if (changes.x) %7B
@@ -450,28 +450,24 @@
 hanges.x) %7B%0A
-    
             
@@ -489,35 +489,27 @@
 s.x%0A        
-   
- 
 %7D%0A%0A
-    
         if (
@@ -517,28 +517,24 @@
 hanges.y) %7B%0A
-    
             
@@ -556,35 +556,27 @@
 s.y%0A        
-    %7D%0A%0A    
+%7D%0A%0A
         row.
@@ -592,19 +592,9 @@
     
-    %7D)%0A    
 %7D
+)
 %0A%7D%0A

fix player rendering