diff options
| author | Julie Lala <jules@okfoc.us> | 2014-07-25 02:01:54 -0400 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-07-25 02:01:54 -0400 |
| commit | c11322210bc5ca2932f8e208d57b9ec3254b8b06 (patch) | |
| tree | 66a88d2c0c66f90dd3be7071a545678cb94b4abd | |
| parent | eb026c75c729f857703474b416a1358ad67574ca (diff) | |
half-walls tests and overflow
| -rw-r--r-- | public/assets/javascripts/rectangles/engine/rooms/builder.js | 24 | ||||
| -rwxr-xr-x | public/assets/stylesheets/app.css | 2 | ||||
| -rw-r--r-- | test/04-test-builder.js | 155 |
3 files changed, 147 insertions, 34 deletions
diff --git a/public/assets/javascripts/rectangles/engine/rooms/builder.js b/public/assets/javascripts/rectangles/engine/rooms/builder.js index 492a8c6..c1cba39 100644 --- a/public/assets/javascripts/rectangles/engine/rooms/builder.js +++ b/public/assets/javascripts/rectangles/engine/rooms/builder.js @@ -149,22 +149,17 @@ this.build_floors = function (room){ var list = [], el = null - + var constructed = room.intersects.filter(function(room){ return room.constructed }) sort.rooms_by_height(constructed) - + if (constructed.length > 0) { // render the regions that don't intersect with anything we've already rendered // if the height is different, calculate the overlapping sides and render half-walls room.regions.forEach(function(region){ var intersected = false for (var i = 0; i < constructed.length; i++) { - if (constructed[i].rect.contains(region)) { - intersected = true - // r.sides = 0xf - // half_sides - } - else if (constructed[i].rect.intersects(region)) { + if (constructed[i].rect.overlaps(region)) { intersected = true if (room.height < constructed[i].height) { var ceiling_walls = this.make_ceiling_walls( room, constructed[i], region ) @@ -181,7 +176,7 @@ list.push( el ) room.mx_ceiling.push(el) } - }) + }.bind(this)) } else { @@ -206,7 +201,7 @@ var depth = region.y.length() var height = hi.height - lo.height - if (! (region.half_sides & LEFT) && region.x.a == hi.rect.x.a) { + if (! (region.half_sides & LEFT) && region.x.a != lo.rect.x.a && region.x.a == hi.rect.x.a) { el = this.make_wall('.left') el.rotationY = HALF_PI el.height = height @@ -221,7 +216,8 @@ el.half_side = LEFT } - if (! (region.half_sides & RIGHT) && region.x.b == hi.rect.x.b) { + if (! (region.half_sides & RIGHT) && region.x.b != lo.rect.x.b && region.x.b == hi.rect.x.b) { +console.log("right") el = this.make_wall('.right') el.rotationY = -HALF_PI el.height = height @@ -236,7 +232,8 @@ el.half_side = RIGHT } - if (! (region.half_sides & FRONT) && region.y.a == hi.rect.y.a) { + if (! (region.half_sides & FRONT) && region.y.a != lo.rect.y.a && region.y.a == hi.rect.y.a) { +console.log("front") el = this.make_wall('.front') el.width = width el.height = height @@ -251,7 +248,8 @@ el.half_side = FRONT } - if (! (region.half_sides & BACK) && region.y.b == hi.rect.y.b) { + if (! (region.half_sides & BACK) && region.y.b != lo.rect.y.b && region.y.b == hi.rect.y.b) { +console.log("back") el = this.make_wall('.back') el.width = width el.height = height diff --git a/public/assets/stylesheets/app.css b/public/assets/stylesheets/app.css index 9072542..a5b1733 100755 --- a/public/assets/stylesheets/app.css +++ b/public/assets/stylesheets/app.css @@ -468,6 +468,8 @@ iframe.embed { .profilepage .bio span:last-of-type:after { display: none; } .templates { + overflow: auto; + max-height: 80%; } .no-templates { display: none; diff --git a/test/04-test-builder.js b/test/04-test-builder.js index f1c0f71..6863e5d 100644 --- a/test/04-test-builder.js +++ b/test/04-test-builder.js @@ -28,13 +28,40 @@ 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 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 }) +var peninsula_room = new Room({ id: "peninsula", rect: peninsula, height: 2 }) + +var taller_room = new Room({ id: "taller", rect: rect, height: 3 }) + function report(a) { console.log( a.join("\n") ) } function reportSides(walls) { console.log(walls.map(function(w){ return sidesToString(w.side) }).join("\n")) } +function count_wall_sides (wall_groups) { + var wall_sides = {} + wall_sides[LEFT] = 0 + wall_sides[RIGHT] = 0 + wall_sides[FRONT] = 0 + wall_sides[BACK] = 0 + wall_sides[TOP] = 0 + wall_sides[BOTTOM] = 0 + wall_sides.total = 0 + wall_groups.map(function(walls){ + walls.forEach(function(wall){ + wall_sides[wall.side] += 1 + wall_sides.total += 1 + }) + }) + return wall_sides +} function reset(){ + Rooms.forEach(function(room){ + room.reset() + }) Rooms.list = {} Rooms.regions = [] } @@ -48,7 +75,7 @@ function rebuild(){ describe('builder', function(){ reset() - var rect_room = Rooms.add_with_rect( rect ) + Rooms.add( rect_room ) rebuild() describe('#build_walls(rect)', function(){ @@ -72,42 +99,128 @@ describe('builder', function(){ }) }) - // + // rect vs east reset() - var rect_room = Rooms.add_with_rect( rect ) - var rect_east = Rooms.add_with_rect( east ) + Rooms.add( rect_room ) + Rooms.add( east_room ) var regions = rebuild() -console.log("\n\n") -console.log(regions.join("\n")) -console.log("\n\n") - describe('#build_walls(rect, east)', function(){ - var walls = regions.map(Rooms.builder.build_walls.bind(Rooms.builder)) - walls.map(function(w){ reportSides(w); console.log("--") }) + var wall_groups = regions.map(Rooms.builder.build_walls.bind(Rooms.builder)) + var wall_sides = count_wall_sides(wall_groups) - it("should return 3 walls", function(){ - assert.equal(4, walls.length) + // reportSides(w); console.log("--") + + it("should return 8 walls", function(){ + assert.equal(8, wall_sides.total) }) - it("should have one side per wall", function(){ - assert.equal(1, bitcount(walls[0].side)) - assert.equal(1, bitcount(walls[1].side)) - assert.equal(1, bitcount(walls[2].side)) - assert.equal(1, bitcount(walls[3].side)) + it("should have 3 front walls", function(){ + assert.equal(3, wall_sides[FRONT]) + }) + it("should have 3 back walls", function(){ + assert.equal(3, wall_sides[BACK]) + }) + it("should have 1 left wall", function(){ + assert.equal(1, wall_sides[LEFT]) + }) + it("should have 1 right wall", function(){ + assert.equal(1, wall_sides[RIGHT]) }) }) describe('#build_floors(rect, east)', function(){ - var floors = Rooms.builder.build_floors(rect_room) - it("should make 2 floors", function(){ - assert.equal(2, floors.length) + var fg = Rooms.builder.build_floors(rect_room) + var fg2 = Rooms.builder.build_floors(east_room) + var fg_floors = fg.filter(function(r){ return ! r.half_side }) + var fg_halves = fg.filter(function(r){ return r.half_side }) + var fg2_floors = fg2.filter(function(r){ return ! r.half_side }) + var fg2_halves = fg2.filter(function(r){ return r.half_side }) + + it("should make 4 floors", function(){ + assert.equal(2, fg_floors.length) + assert.equal(2, fg2_floors.length) + }) + it("should make 0 half-walls", function(){ + assert.equal(0, fg_halves.length) + assert.equal(0, fg2_halves.length) + }) + }) + + // rect vs corner + + reset() + Rooms.add( rect_room ) + Rooms.add( corner_room ) + var regions = rebuild() + + describe('#build_walls(rect, corner)', function(){ + + var wall_groups = regions.map(Rooms.builder.build_walls.bind(Rooms.builder)) + var wall_sides = count_wall_sides(wall_groups) + + // reportSides(w); console.log("--") + + it("should return 12 walls", function(){ + assert.equal(12, wall_sides.total) + }) + it("should have 3 front walls", function(){ + assert.equal(3, wall_sides[FRONT]) + }) + it("should have 3 back walls", function(){ + assert.equal(3, wall_sides[BACK]) + }) + it("should have 3 left wall", function(){ + assert.equal(3, wall_sides[LEFT]) + }) + it("should have 3 right wall", function(){ + assert.equal(3, wall_sides[RIGHT]) }) - // reportSides(floors) }) + describe('#build_floors(rect, corner)', function(){ + var fg = Rooms.builder.build_floors(rect_room) + var fg2 = Rooms.builder.build_floors(corner_room) + var fg_floors = fg.filter(function(r){ return ! r.half_side }) + var fg_halves = fg.filter(function(r){ return r.half_side }) + var fg2_floors = fg2.filter(function(r){ return ! r.half_side }) + var fg2_halves = fg2.filter(function(r){ return r.half_side }) + it("should make 4 floors", function(){ + assert.equal(1, fg_floors.length) + assert.equal(3, fg2_floors.length) + }) + it("should make 2 half-walls", function(){ + assert.equal(0, fg_halves.length) + assert.equal(2, fg2_halves.length) + }) + }) + + // taller (rect) vs east + + reset() + Rooms.add( taller_room ) + Rooms.add( east_room ) + var regions = rebuild() + + describe('#build_floors(taller, east)', function(){ + var fg = Rooms.builder.build_floors(taller_room) + var fg2 = Rooms.builder.build_floors(east_room) + var fg_floors = fg.filter(function(r){ return ! r.half_side }) + var fg_halves = fg.filter(function(r){ return r.half_side }) + var fg2_floors = fg2.filter(function(r){ return ! r.half_side }) + var fg2_halves = fg2.filter(function(r){ return r.half_side }) + + it("should make 4 floors", function(){ + assert.equal(2, fg_floors.length) + assert.equal(2, fg2_floors.length) + }) + it("should make 1 half-wall", function(){ + assert.equal(0, fg_halves.length) + assert.equal(1, fg2_halves.length) + }) + }) |
