diff options
| author | Julie Lala <jules@okfoc.us> | 2014-06-10 19:46:53 -0400 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-06-10 19:46:53 -0400 |
| commit | 4e4b5b5668835097f335efaf55dfe837eec7dc3c (patch) | |
| tree | 5cd6cb12a203c5dd7c8cf9f62b9cd9235e52513c /public/assets/javascripts/rectangles/models | |
| parent | 3074488306e041718dec221ff9142748e2e68916 (diff) | |
| parent | b231af3e38b8f066f18031fd69b0fdb30a5e244a (diff) | |
Merge branch 'master' of github.com:okfocus/vvalls
Diffstat (limited to 'public/assets/javascripts/rectangles/models')
| -rw-r--r-- | public/assets/javascripts/rectangles/models/rect.js | 3 | ||||
| -rw-r--r-- | public/assets/javascripts/rectangles/models/room.js | 12 | ||||
| -rw-r--r-- | public/assets/javascripts/rectangles/models/vec2.js | 3 |
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 731411c..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 || Rooms.list.length + 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) |
