diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-08-05 14:31:56 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-08-05 14:31:56 -0400 |
| commit | a8307b74bd429227fe1f2a06d8fac5d61530608f (patch) | |
| tree | 68118c2f01fbc187c78e3ce3d791b27593205dc3 | |
| parent | e2e1565f5cd3154c0f515dbe3d88c9943dd0580e (diff) | |
test bounds
7 files changed, 115 insertions, 52 deletions
diff --git a/public/assets/javascripts/rectangles/engine/rooms/builder.js b/public/assets/javascripts/rectangles/engine/rooms/builder.js index 6b2e65a..f321f71 100644 --- a/public/assets/javascripts/rectangles/engine/rooms/builder.js +++ b/public/assets/javascripts/rectangles/engine/rooms/builder.js @@ -293,7 +293,7 @@ el.side = 0 el.rect = null el.destroy = function(){ - this.el = this.rect = null + this.el = this.rect = this.face = null } // possible if walls are opaque diff --git a/public/assets/javascripts/rectangles/engine/rooms/grouper.js b/public/assets/javascripts/rectangles/engine/rooms/grouper.js index 532146d..ba081e3 100644 --- a/public/assets/javascripts/rectangles/engine/rooms/grouper.js +++ b/public/assets/javascripts/rectangles/engine/rooms/grouper.js @@ -1,7 +1,9 @@ (function(){ - var Rooms, UidGenerator, Wall, sort + var vec2, Rect, Rooms, UidGenerator, Wall, sort if ('window' in this) { + vec2 = window.vec2 + Rect = window.Rect Rooms = window.Rooms UidGenerator = window.UidGenerator Wall = window.Wall @@ -10,6 +12,8 @@ else { Rooms = require('./_rooms') UidGenerator = require('../../util/uid') + vec2 = require('../../models/vec2') + Rect = require('../../models/rect') Wall = require('../../models/wall') sort = require('../../util/sort') FRONT = 0x1, BACK = 0x2, LEFT = 0x4, RIGHT = 0x8, FLOOR = 0x10, CEILING = 0x20 @@ -71,28 +75,25 @@ var useX = side & FRONT_BACK var useA = side & (FRONT | RIGHT) var last_mx + var widthVec, heightVec collection.sort( useX ? sort.compare_zx : sort.compare_xz ) collection.forEach(function(mx){ if (last_mx && last_mx.rect.eq(mx.rect)) { -// console.log( mx.y - mx.height/2 ) -// console.log( last_mx.y - last_mx.height/2 ) -// console.log(last_mx.y, mx.y) -// console.log(last_mx.height, mx.height) -// console.log(Rooms.list[ last_mx.rect.id ].height, Rooms.list[ mx.rect.id ].height) -// console.log("___") -// last_mx.height += mx.height/2 -// last_mx.y += mx.height/4 if (last_mx.rect.id == mx.rect.id) { last_mx.height += mx.height/2 last_mx.y += mx.height/4 + last_mx.face.y.b += mx.height/2 } last_mx.side = side - mx.culled = true + mx.destroy() scene.remove(mx) return } + widthVec = mx.rect[useX ? 'x' : 'y'].clone() + heightVec = new vec2( mx.y - mx.height/2, mx.y + mx.height/2 ) + mx.face = new Rect( widthVec, heightVec ) last_mx = mx }) }) @@ -114,20 +115,23 @@ if (useX && wall.vec.b == mx.rect.x.a) { wall.vec.b = mx.rect.x.b wall.mx.push(mx) + wall.faces.push(mx.face) return } else if (! useX && wall.vec.b == mx.rect.y.a) { wall.vec.b = mx.rect.y.b wall.mx.push(mx) + wall.faces.push(mx.face) return } } wall = new Wall ({ - id: base.uid(), - side: side, - vec: mx.rect[ useX ? 'x' : 'y' ].clone(), - edge: mx.rect[useX ? 'y' : 'x' ][ useA ? 'a' : 'b' ], - el: mx, + id: base.uid(), + side: side, + mx: [ mx ], + faces: [ mx.face ], + vec: mx.rect[ useX ? 'x' : 'y' ].clone(), + edge: mx.rect[ useX ? 'y' : 'x' ][ useA ? 'a' : 'b' ], }) walls.push(wall) }) diff --git a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js index fe5f037..137c74a 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js +++ b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js @@ -12,25 +12,29 @@ var Scenery = new function(){ base.resize.init() } - base.add = function(wall, media, id){ + base.add = function(opt){ var scene_media switch (media.type) { case 'image': - scene_media = new Scenery.types.image ({ media: media, wall: wall, id: id }) + scene_media = new Scenery.types.image (opt) break case 'video': case 'youtube': case 'vimeo': - scene_media = new Scenery.types.video ({ media: media, wall: wall, id: id }) + scene_media = new Scenery.types.video (opt) break } base.list[scene_media.id] = scene_media return scene_media } - base.addNextToWall = function(wall){ - base.add(wall, base.nextMedia) + base.addNextToWall = function(wall, mx){ + base.add({ + wall: wall, + media: base.nextMedia, + mx: mx + }) base.nextMedia = null } @@ -64,7 +68,11 @@ var Scenery = new function(){ base.deserialize = function(scenery_data){ scenery_data.forEach(function(data){ var wall = Rooms.walls[data.wall_id] - var scene_media = base.add(wall, data.media, data.id) + var scene_media = base.add({ + wall: wall, + media: data.media, + id: data.id + }) scene_media.deserialize(data) }) } diff --git a/public/assets/javascripts/rectangles/engine/scenery/move.js b/public/assets/javascripts/rectangles/engine/scenery/move.js index 94a4e52..cc5b014 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/move.js +++ b/public/assets/javascripts/rectangles/engine/scenery/move.js @@ -69,7 +69,7 @@ Scenery.move = function(base){ function switch_wall (e, new_wall, cursor){ if (! dragging) return - if (new_wall.uid == base.wall.uid) return + if (new_wall.id == base.wall.id) return if (! new_wall.fits(base.media, base.scale)) return var old_wall_side = base.wall.side diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js index 7202ce0..aa1fefb 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js @@ -12,7 +12,7 @@ Scenery.types.base = Fiber.extend(function(base){ this.scale = this.media.scale if (opt.wall) { - this.set_wall(opt.wall) + this.set_wall(opt.wall, opt.mx) } }, @@ -60,7 +60,7 @@ Scenery.types.base = Fiber.extend(function(base){ } }, - set_wall: function(wall){ + set_wall: function(wall, mx){ this.wall = wall || this.wall this.bounds = this.wall.bounds_for(this.media, this.scale) this.center = this.wall.center() diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js index 41d7235..bbe6b97 100644 --- a/public/assets/javascripts/rectangles/models/wall.js +++ b/public/assets/javascripts/rectangles/models/wall.js @@ -11,18 +11,14 @@ Rect = require('./rect') UidGenerator = require('../util/uid') } - var wall_uid = new UidGenerator({}) var Wall = function(opt){ this.id = opt.id - this.uid = wall_uid this.vec = opt.vec this.edge = opt.edge this.side = opt.side - this.mx = [] - if (opt.el) { - this.mx.push(opt.el) - } + this.faces = opt.faces + this.mx = opt.mx } Wall.prototype.toString = function(){ @@ -42,27 +38,30 @@ Wall.prototype.bind = function(){ var base = this base.$walls = $( this.mx.map(function(mx){ return mx.el }) ) - base.$walls.bind({ - mouseover: function(){ - }, - mouseenter: function(e){ - Scenery.mouse.mouseenter(e, base) - }, - mousemove: function(e){ - }, - mousedown: function(){ - // base.randomize_colors() - // console.log(sidesToString(base.side)) - if (Scenery.nextMedia) { - Scenery.addNextToWall(base) - } - else if (Scenery.nextWallpaper) { - base.wallpaper() - } - else { - app.controller.hideExtras() + + this.mx.forEach(function(mx){ + $(mx.el).bind({ + mouseover: function(){ + }, + mouseenter: function(e){ + Scenery.mouse.mouseenter(e, base, mx) + }, + mousemove: function(e){ + }, + mousedown: function(){ + // base.randomize_colors() + // console.log(sidesToString(base.side)) + if (Scenery.nextMedia) { + Scenery.addNextToWall(base, mx) + } + else if (Scenery.nextWallpaper) { + base.wallpaper() + } + else { + app.controller.hideExtras() + } } - } + }) }) this.outline() } @@ -77,6 +76,12 @@ new vec2( halfHeight, Rooms.list[this.room].height - halfHeight ) ) } + Wall.prototype.bounds_for_mx = function(img, scale, mx) { + // + } + Wall.prototype.fits_mx = function(img, scale, mx) { + } + Wall.prototype.fits = function(img, scale){ if (this.side & FRONT_BACK && this.rect.x.length() < img.width * scale) { return false @@ -165,7 +170,7 @@ mx.outlined = true canvas.width = mx.width canvas.height = mx.height - ctx.fillStyle = "rgba(255,255,255,0.9)" + ctx.fillStyle = "rgba(255,255,255,0.95)" ctx.fillRect(0, 0, canvas.width, canvas.height) ctx.fillStyle = "rgba(0,0,0,1.0)" diff --git a/test/06-test-grouper.js b/test/06-test-grouper.js index 41ed0b0..5388875 100644 --- a/test/06-test-grouper.js +++ b/test/06-test-grouper.js @@ -29,6 +29,9 @@ var east = new Rect( new vec(2,6), new vec(1,5) ) var corner = new Rect( new vec(3,7), new vec(3,7) ) var peninsula = new Rect( new vec(4,6), new vec(6,8) ) +var big_rect = new Rect( new vec(1,5), new vec(1,5) ) +var hall_rect = new Rect( new vec(3,4), new vec(4,8) ) + var rect_room = new Room({ id: "rect", rect: rect, height: 2 }) var east_room = new Room({ id: "east", rect: east, height: 2 }) var corner_room = new Room({ id: "corner", rect: corner, height: 2 }) @@ -38,6 +41,9 @@ var peninsula_shorter = new Room({ id: "peninsula", rect: peninsula, height: 1 } var taller_room = new Room({ id: "taller", rect: rect, height: 3 }) +var big_room = new Room({ id: "big_room", rect: big_rect, height: 4 }) +var hallway = new Room({ id: "hallway", rect: hall_rect, height: 2 }) + function report(a) { console.log( a.join("\n") ) } @@ -230,6 +236,7 @@ describe('grouper(rect,corner,peninsula_taller)', function(){ }) it("right has 5 walls", function(){ assert.equal(5, right_walls.length) + // console.log(right_walls.map(function(m){ return m.vec + " " + m.edge + " " + m.faces+"" })) }) it("front has 3 walls", function(){ assert.equal(3, front_walls.length) @@ -240,3 +247,42 @@ describe('grouper(rect,corner,peninsula_taller)', function(){ }) }) +describe('grouper(room,hallway)', function(){ + reset() + Rooms.add( big_room ) + Rooms.add( hallway ) + rebuild() + + var collections = Rooms.grouper.collect() + + describe('#collect(room,hallway)', function(){ + it("should find an appropriate number of wall segments", function(){ + assert.equal(3, collections[FRONT].length) + assert.equal(4, collections[BACK].length) + assert.equal(3, collections[LEFT].length) + assert.equal(3, collections[RIGHT].length) + }) + }) + + describe('#group(rect,corner,peninsula_taller)', function(){ + var front_walls = Rooms.grouper.group([], collections, FRONT) + var back_walls = Rooms.grouper.group([], collections, BACK) + var left_walls = Rooms.grouper.group([], collections, LEFT) + var right_walls = Rooms.grouper.group([], collections, RIGHT) + + it("left has 2 walls", function(){ + assert.equal(2, left_walls.length) + }) + it("right has 2 walls", function(){ + assert.equal(2, right_walls.length) + }) + it("front has 1 wall", function(){ + assert.equal(1, front_walls.length) + }) + it("back has 2 walls", function(){ + assert.equal(2, back_walls.length) + // console.log(back_walls.map(function(m){ return m.vec + " " + m.edge + " " + m.faces+"" })) + }) + }) +}) + |
