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 /public/assets/javascripts | |
| parent | e2e1565f5cd3154c0f515dbe3d88c9943dd0580e (diff) | |
test bounds
Diffstat (limited to 'public/assets/javascripts')
6 files changed, 69 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)" |
