diff options
Diffstat (limited to 'assets/javascripts/rectangles/models')
| -rw-r--r-- | assets/javascripts/rectangles/models/room.js | 61 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/models/wall.js | 20 |
2 files changed, 68 insertions, 13 deletions
diff --git a/assets/javascripts/rectangles/models/room.js b/assets/javascripts/rectangles/models/room.js index 34eed6a..f7c52d4 100644 --- a/assets/javascripts/rectangles/models/room.js +++ b/assets/javascripts/rectangles/models/room.js @@ -53,23 +53,64 @@ window.Room = (function(){ Room.prototype.group_walls = function(){ var base = this - var array_groups = {}, rect_groups = [] + var side_groups = {}, walls = [] + + base.walls.forEach(function(wall){ - sort_wall_els_by_x_then_z(base.walls) + // ignore half-walls for now + if (! wall.side) return; - base.walls.forEach(function(wall){ - var w = array_groups[ wall.side ] - if (w) { - w.forEach(function(ww){ - - }) + if (side_groups[ wall.side ]) { + side_groups[ wall.side ].push(wall) + } + else { + side_groups[ wall.side ] = [wall] + } + }) + + pairs(side_groups).forEach(function(pair){ + var side = pair[0], els = pair[1] + + console.log(sidesToString(side)) + if (side & LEFT_RIGHT) { + els.sort(compare_x) + console.log(els.map(function(r){ return r.rect+"" }).join("\n")) } else { - array_groups[ wall.side ] = [[wall]] + console.log(els.map(function(r){ return r.rect+"" }).join("\n")) } + + var wall = new_wall(els.shift()) + walls.push(wall) + + els.forEach(function(el){ + console.log(wall.rect.x.b, el.rect.x.a, el.rect.sides & LEFT_RIGHT) + if (side & FRONT_BACK && wall.rect.x.b == el.rect.x.a) { + wall.rect.x.b = el.rect.x.b + wall.mx.push(el) + } + else if (side & LEFT_RIGHT && wall.rect.y.b == el.rect.y.a) { + wall.rect.y.b = el.rect.y.b + wall.mx.push(el) + } + else { + wall = new_wall(el) + walls.push(wall) + } + }) + console.log(walls.length) }) - return groups + function new_wall (el) { + return new Wall ({ + room: base.id, + side: el.side, + rect: el.rect.clone(), + el: el, + }) + } + + return walls } Room.prototype.clipTo = function(r){ diff --git a/assets/javascripts/rectangles/models/wall.js b/assets/javascripts/rectangles/models/wall.js index b9705a2..50ae0e8 100644 --- a/assets/javascripts/rectangles/models/wall.js +++ b/assets/javascripts/rectangles/models/wall.js @@ -3,9 +3,14 @@ window.Wall = (function(){ var Wall = function(opt){ this.id = opt.id this.room = opt.room - this.rect = opt.rect + this.rect = opt.rect || new Rect (0,0,0,0) + this.rect.sides = opt.side + this.side = opt.side this.mx = [] this.els = [] + if (opt.el) { + this.mx.push(opt.el) + } } Wall.prototype.toString = function(){ @@ -14,15 +19,24 @@ window.Wall = (function(){ Wall.prototype.reset = function(){ } + Wall.prototype.destroy = function(){ + this.mx.forEach(function(mx){ + mx.destroy && mx.destroy() + }) + this.room = this.rect = this.mx = this.els = null + } Wall.prototype.bind = function(){ - this.$walls.bind({ + var base = this + base.$walls = $( this.mx.map(function(mx){ return mx.el }) ) + base.$walls.bind({ mouseover: function(){ }, mousemove: function(e){ }, mousedown: function(){ - $(this).css("background-color", choice(window.palettes.colors)) + base.$walls.css("background-color", choice(window.palettes.colors)) + console.log("zz") } }) } |
