summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/models
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-06-10 16:34:52 -0400
committerJules Laplace <jules@okfoc.us>2014-06-10 16:52:14 -0400
commit08421d8921fcc9842ea70d2e5c6439d1154e6d73 (patch)
tree4d6d9059f912aa5c6ba931383e3f55051bce3c18 /public/assets/javascripts/rectangles/models
parenta5ba8d536afe5c96c6e01763296de2a407f81aa8 (diff)
serialization functions
Diffstat (limited to 'public/assets/javascripts/rectangles/models')
-rw-r--r--public/assets/javascripts/rectangles/models/rect.js3
-rw-r--r--public/assets/javascripts/rectangles/models/room.js12
-rw-r--r--public/assets/javascripts/rectangles/models/vec2.js3
3 files changed, 16 insertions, 2 deletions
diff --git a/public/assets/javascripts/rectangles/models/rect.js b/public/assets/javascripts/rectangles/models/rect.js
index 7a2ac6f..cb14e66 100644
--- a/public/assets/javascripts/rectangles/models/rect.js
+++ b/public/assets/javascripts/rectangles/models/rect.js
@@ -94,6 +94,9 @@ window.Rect = (function(){
var s = "[" + this.x.toString() + " " + this.y.toString() + "] " + sides
return s
}
+ Rect.prototype.serialize = function(){
+ return { x: this.x.serialize(), y: this.y.serialize() }
+ }
Rect.prototype.quantize = function(n){
this.x.quantize(n)
this.y.quantize(n)
diff --git a/public/assets/javascripts/rectangles/models/room.js b/public/assets/javascripts/rectangles/models/room.js
index 256889d..d0478b3 100644
--- a/public/assets/javascripts/rectangles/models/room.js
+++ b/public/assets/javascripts/rectangles/models/room.js
@@ -1,7 +1,7 @@
window.Room = (function(){
var Room = function(opt){
- this.id = opt.id || _.uniqueId("room")
+ this.id = opt.id || Rooms.uid("room_")
this.rect = opt.rect
this.regions = []
this.walls = []
@@ -15,7 +15,15 @@ window.Room = (function(){
Room.prototype.toString = function(){
return this.rect.toString()
}
-
+
+ Room.prototype.serialize = function(){
+ return {
+ id: this.id,
+ rect: this.rect.serialize(),
+ height: ~~this.height,
+ }
+ }
+
Room.prototype.reset = function(){
var copy = this.rect.clone()
copy.id = this.id
diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js
index 9b0447c..e56a010 100644
--- a/public/assets/javascripts/rectangles/models/vec2.js
+++ b/public/assets/javascripts/rectangles/models/vec2.js
@@ -91,6 +91,9 @@ vec2.prototype.intersection = function(v){
vec2.prototype.toString = function(){
return "[" + ~~this.a + " " + ~~this.b + "]"
}
+vec2.prototype.serialize = function(){
+ return [ ~~this.a, ~~this.b ]
+}
vec2.prototype.quantize = function(n){
n = n || 10
this.a = quantize(this.a, n)