summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/engine/rooms/grouper.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/rectangles/engine/rooms/grouper.js')
-rw-r--r--public/assets/javascripts/rectangles/engine/rooms/grouper.js34
1 files changed, 19 insertions, 15 deletions
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)
})