summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/rectangles')
-rw-r--r--public/assets/javascripts/rectangles/engine/rooms/builder.js18
-rw-r--r--public/assets/javascripts/rectangles/models/room.js76
-rw-r--r--public/assets/javascripts/rectangles/models/wall.js37
3 files changed, 28 insertions, 103 deletions
diff --git a/public/assets/javascripts/rectangles/engine/rooms/builder.js b/public/assets/javascripts/rectangles/engine/rooms/builder.js
index dfabc86..1f21636 100644
--- a/public/assets/javascripts/rectangles/engine/rooms/builder.js
+++ b/public/assets/javascripts/rectangles/engine/rooms/builder.js
@@ -7,7 +7,7 @@
}
else {
MX = require('../../../../../../test/mocks/mx.js')
- scene = MX.scene
+ scene = MX.Scene
Rooms = require('./_rooms')
sort = require('../../util/sort')
FRONT = 0x1, BACK = 0x2, LEFT = 0x4, RIGHT = 0x8, FLOOR = 0x10, CEILING = 0x20
@@ -43,7 +43,7 @@
if (window.scene) {
base.clear()
base.build()
- base.bind_walls()
+ Rooms.grouper.group()
}
}
@@ -62,18 +62,7 @@
})
}.bind(this))
}
-
- base.bind_walls = function (){
- Rooms.forEach(function(room){
- room.walls = room.group_mx_walls()
- room.walls.forEach(function(wall){
- Rooms.walls[ wall.id ] = wall
- wall.bind()
- wall.randomize_colors()
- })
- })
- }
-
+
base.clear = function (){
els.forEach(function(el){
scene.remove(el)
@@ -84,7 +73,6 @@
this.build_walls = function (region) {
var room = Rooms.list[ region.id ]
-
var list = [], el = null
var width = region.x.length()
diff --git a/public/assets/javascripts/rectangles/models/room.js b/public/assets/javascripts/rectangles/models/room.js
index c2850ba..937c928 100644
--- a/public/assets/javascripts/rectangles/models/room.js
+++ b/public/assets/javascripts/rectangles/models/room.js
@@ -85,83 +85,7 @@
})
})
}
-
- Room.prototype.group_mx_walls = function(){
- var base = this
- var side_groups = {}, walls = []
-
- // group the walls by side
- base.mx_walls.forEach(function(wall){
-
- // ignore half-walls for now
- var side = wall.side || wall.half_side
-
- if (side_groups[side]) {
- side_groups[side].push(wall)
- }
- else {
- side_groups[side] = [wall]
- }
- })
-
- // sort the subgroups, and then combine mx objects under wall objects
- pairs(side_groups).forEach(function(pair){
- var side = pair[0], els = pair[1]
-
- if (side & LEFT_RIGHT) {
- els.sort(sort.compare_rect_x)
- }
- else if (side & FRONT_BACK) {
- els.sort(sort.compare_rect_y)
- }
-
- // wall holds state for the last wall we created/saw..
- // right now we keep walls subdivided where there are half-walls to simplify
- // calculations involving placing media on walls, calculating wall boundaries, etc..
- // one consequence of this is we can't place things on the walls above "doorways".
- // in the future, we should have more robust placement algorithm, which takes
- // this into account, and only use one wall "object" per plane
- var wall
- els.forEach(function(el){
- if (el.half_side) {
- wall = new_wall(el)
- walls.push(wall)
- wall = null
- }
- else if (! wall) {
- wall = new_wall(el)
- walls.push(wall)
- }
- else 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)
- }
- })
- })
-
- function new_wall (el) {
- return new Wall ({
- id: base.id + "_" + (el.side | el.half_side) + "_" + walls.length,
- room: base.id,
- side: el.side | el.half_side,
- half_side: el.half_side,
- rect: el.rect.clone(),
- el: el,
- })
- }
-
- return walls
- }
-
Room.prototype.clipTo = function(r){
// for each of this rect's regions split the region if necessary
var regions = this.regions
diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js
index 027d5f5..f2b8bca 100644
--- a/public/assets/javascripts/rectangles/models/wall.js
+++ b/public/assets/javascripts/rectangles/models/wall.js
@@ -1,21 +1,31 @@
-window.Wall = (function(){
+(function(){
+ var vec2, Rect, sort
+ if ('window' in this) {
+ vec2 = window.vec2
+ Rect = window.Rect
+ sort = window.sort
+ }
+ else {
+ vec2 = require('./vec2')
+ Rect = require('./rect')
+ UidGenerator = require('../util/uid')
+ }
+ var wall_uid = new UidGenerator({})
+
var Wall = function(opt){
this.id = opt.id
- this.uid = Uid()
- this.room = opt.room
- this.rect = opt.rect || new Rect (0,0,0,0)
- this.rect.sides = opt.side
+ this.uid = wall_uid
+ this.vec = opt.vec
this.side = opt.side
this.mx = []
- this.els = []
if (opt.el) {
this.mx.push(opt.el)
}
}
Wall.prototype.toString = function(){
- return this.rect.toString()
+ return this.vec.toString()
}
Wall.prototype.reset = function(){
@@ -25,7 +35,7 @@ window.Wall = (function(){
this.mx.forEach(function(mx){
mx.destroy && mx.destroy()
})
- this.room = this.rect = this.mx = this.els = null
+ this.room = this.vec = this.mx = null
}
Wall.prototype.bind = function(){
@@ -146,8 +156,6 @@ window.Wall = (function(){
if (shouldFlip) {
sortedWalls = sortedWalls.reverse()
}
-
-console.log(sortedWalls.map(function(z){return useX ? z.x : z.z}).join(" "))
var len = sortedWalls.length
@@ -184,7 +192,6 @@ console.log(sortedWalls.map(function(z){return useX ? z.x : z.z}).join(" "))
mx.el.style.backgroundImage = "url(" + dataUrl + ")"
})
- window.zz += 1
}
Wall.prototype.siblings = function(){
@@ -222,6 +229,12 @@ console.log(sortedWalls.map(function(z){return useX ? z.x : z.z}).join(" "))
})
}
- return Wall
+ if ('window' in this) {
+ window.Wall = Wall
+ }
+ else {
+ module.exports = Wall
+ }
+
})()