summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-08-18 20:05:56 -0400
committerJules Laplace <jules@okfoc.us>2015-08-18 20:05:56 -0400
commit40fa450839a171cbfa1d9c8470d25eeeba337a27 (patch)
tree0aded62c6ac2af50cf62f071f42ee34dfc88edc8
parentbbd62d9c7f3838d07e42e46c244c317a5dbdb5ae (diff)
serialize/deserialize polyline
-rw-r--r--public/assets/javascripts/rectangles/engine/shapes/polyline.js10
-rw-r--r--public/assets/javascripts/rectangles/engine/shapes/shapelist.js11
2 files changed, 19 insertions, 2 deletions
diff --git a/public/assets/javascripts/rectangles/engine/shapes/polyline.js b/public/assets/javascripts/rectangles/engine/shapes/polyline.js
index 7e3c04c..e853592 100644
--- a/public/assets/javascripts/rectangles/engine/shapes/polyline.js
+++ b/public/assets/javascripts/rectangles/engine/shapes/polyline.js
@@ -1,9 +1,12 @@
var Polyline = Fiber.extend(function(base){
var exports = {}
- exports.init = function(){
- this.points = []
+ exports.init = function(points){
+ this.points = points
this.mx_points = []
this.closed = false
+ if (points) {
+ this.build()
+ }
}
exports.add = function(p){
this.points.push( p )
@@ -134,6 +137,9 @@ var Polyline = Fiber.extend(function(base){
exports.rebuild = function(){
this.mx.rebuild()
}
+ exports.serialize = function(){
+ return this.points
+ }
exports.reset = function(){
this.mx_points.forEach(function(mx){ scene.remove(mx) })
this.mx_points.length = 0
diff --git a/public/assets/javascripts/rectangles/engine/shapes/shapelist.js b/public/assets/javascripts/rectangles/engine/shapes/shapelist.js
index e86c5d6..c3b5758 100644
--- a/public/assets/javascripts/rectangles/engine/shapes/shapelist.js
+++ b/public/assets/javascripts/rectangles/engine/shapes/shapelist.js
@@ -64,5 +64,16 @@ var ShapeList = Fiber.extend(function(base){
exports.forEach = function(fn){
this.shapes.forEach(fn)
}
+ exports.serialize = function(){
+ return this.shapes.map(function(shape){
+ return shape.serialize()
+ })
+ }
+ exports.deserialize = function(data){
+ data.forEach(function(points){
+ var line = new Polyline(points)
+ this.add(line)
+ }.bind(this))
+ }
return exports
}) \ No newline at end of file