summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulie Lala <jules@okfoc.us>2014-08-22 12:11:40 -0400
committerJulie Lala <jules@okfoc.us>2014-08-22 12:11:40 -0400
commit978634c1c323240f36548468703a9512710c60e7 (patch)
treef86d2dda3772bc2b662462e9842780ca4f289596
parenta48beac4e7e93f78ef7229b0b1e4776dc04cac92 (diff)
wall placement
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/_scenery.js14
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/move.js14
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/types/_object.js58
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/types/image.js5
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/types/video.js4
-rw-r--r--public/assets/javascripts/rectangles/models/wall.js40
-rw-r--r--public/assets/javascripts/rectangles/util/mouse.js8
7 files changed, 76 insertions, 67 deletions
diff --git a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js
index 5d36b4f..58592d4 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js
@@ -29,14 +29,14 @@ var Scenery = new function(){
return scene_media
}
- base.addNextToWall = function(wall, index){
- base.add({
- wall: wall,
- media: base.nextMedia,
- index: index || 0,
- })
+ base.addNextToWall = function(opt){
+ opt.media = base.nextMedia
+ opt.index = opt.index || 0
+ var scene_media = base.add(opt)
+
+ // test if scenery was placed here
base.nextMedia = null
- return media
+ return scene_media
}
base.find = function(id){
diff --git a/public/assets/javascripts/rectangles/engine/scenery/move.js b/public/assets/javascripts/rectangles/engine/scenery/move.js
index f2d37d8..47e155b 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/move.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/move.js
@@ -91,21 +91,21 @@ Scenery.move = function(base){
oldState = null
}
- function switch_wall (e, new_wall, cursor){
+ function switch_wall (e, target, cursor){
if (! dragging) return
- if (new_wall.id == base.wall.id) return
- if (! new_wall.fits(base.media, base.scale)) return
+ if (target.wall.id == base.wall.id) return
+ if (! target.wall.fits(base.media, base.scale)) return
var old_wall_side = base.wall.side
- var wall_group = old_wall_side | new_wall.side
+ var wall_group = old_wall_side | target.wall.side
- base.set_wall(new_wall)
+ base.set_wall(target)
bounds = base.bounds
x = base.center.a
z = base.center.b
- if (old_wall_side !== new_wall.side && wall_group !== FRONT_BACK && wall_group !== LEFT_RIGHT) {
+ if (old_wall_side !== target.wall.side && wall_group !== FRONT_BACK && wall_group !== LEFT_RIGHT) {
switch (old_wall_side) {
case FRONT:
z = bounds.x.a
@@ -127,7 +127,7 @@ Scenery.move = function(base){
base.mx.move({
x: x,
z: z,
- rotationY: wall_rotation[ new_wall.side ]
+ rotationY: wall_rotation[ target.wall.side ]
})
if (editor.permissions.resize) {
diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js
index 70d1d26..7b716f6 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js
@@ -8,20 +8,36 @@ Scenery.types.base = Fiber.extend(function(base){
this.id = opt.id || Scenery.uid("scenery")
this.move = new Scenery.move (this)
this.media = opt.media
- this.dimensions = new vec2(this.media.width, this.media.height)
- this.scale = this.media.scale
+ this.naturalDimensions = new vec2(this.media.width, this.media.height)
- this.scaleDimensions = this.dimensions.clone().mul(this.media.scale)
+ this.set_scale( opt.scale || this.media.scale || 1.0 )
this.position = new vec2(0,0)
- if (opt.data && opt.data.position) {
- // position is the coordinate of one of the corners with respect to a
- // wall surface
- // subtract x/z offset of wall
- }
+ },
- if (opt.wall) {
- this.set_wall(opt.wall, index)
+ set_wall: function(opt){
+ this.wall = opt.wall || this.wall
+ this.bounds = this.wall.surface.bounds_at_index_with_dimensions(opt.index || 0, this.dimensions)
+ },
+
+ set_scale: function(scale){
+ this.scale = scale || 1.0
+ if (this.mx) {
+ this.mx.scale = this.mx.ops.scale = this.scale
}
+ this.dimensions = this.naturalDimensions.clone().mul(this.scale)
+ },
+
+ recenter: function () {
+ var center = this.bounds.center()
+ center.a -= this.dimensions.a / 2
+ center.b -= this.dimensions.b / 2
+ console.log(center+"")
+ var mx_position = this.wall.positionToMx( center, this.dimensions )
+ console.log(mx_position)
+ console.log(this.wall.surface.faces.join("\n"))
+ // also supply scale?
+ this.mx.move(mx_position)
+ this.position.assign(center)
},
bind: function(){
@@ -49,6 +65,7 @@ Scenery.types.base = Fiber.extend(function(base){
this.move = null
this.media = null
this.dimensions = null
+ this.naturalDimensions = null
this.wall = null
this.bounds = null
this.center = null
@@ -68,26 +85,6 @@ Scenery.types.base = Fiber.extend(function(base){
}
},
- set_wall: function(wall, index){
- this.wall = wall || this.wall
- // this.bounds = this.wall.bounds_for(this.media, this.scale)
- // this.center = this.wall.center()
- },
-
- set_scale: function(scale){
- this.scale = this.mx.scale = this.mx.ops.scale = scale || 1.0
- },
-
- recenter: function(){
- this.mx.move({
- x: this.center.a,
- y: Rooms.list[this.wall.room].height/2 - 20,
- z: this.center.b,
- scale: this.scale,
- rotationY: wall_rotation[ this.wall.side ],
- })
- },
-
serialize: function(){
var data = {
id: this.id,
@@ -95,6 +92,7 @@ Scenery.types.base = Fiber.extend(function(base){
side: this.wall && this.wall.side,
dimensions: this.dimensions.serialize(),
position: app.position(this.mx),
+ scale: this.scale,
media: this.media,
}
return data
diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/image.js b/public/assets/javascripts/rectangles/engine/scenery/types/image.js
index 576242e..1582e0f 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/types/image.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/types/image.js
@@ -4,17 +4,18 @@ Scenery.types.image = Scenery.types.base.extend(function(base){
var exports = {
init: function(opt){
+ opt.scale = opt.scale || 300 / max(300, opt.media.width)
+
base.init.call(this, opt)
- this.scale = 300 / max(300, this.media.width)
this.build()
this.bind()
- this.set_wall()
if (opt.data) {
this.deserialize(opt.data)
}
else {
+ this.set_wall(opt)
this.recenter()
}
},
diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/video.js b/public/assets/javascripts/rectangles/engine/scenery/types/video.js
index 0bd5c06..e8bc7f7 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/types/video.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/types/video.js
@@ -4,12 +4,12 @@ Scenery.types.video = Scenery.types.base.extend(function(base){
var exports = {
init: function(opt){
+ opt.scale = opt.scale || 300 / max(300, opt.media.width)
+
base.init.call(this, opt)
- this.scale = this.media.scale = 300 / max(300, this.media.width)
this.build()
this.bind()
- this.set_wall()
if (opt.data) {
this.deserialize(opt.data)
diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js
index 3afe49a..a8bcbd8 100644
--- a/public/assets/javascripts/rectangles/models/wall.js
+++ b/public/assets/javascripts/rectangles/models/wall.js
@@ -44,7 +44,10 @@
mouseover: function(){
},
mouseenter: function(e){
- Scenery.mouse.mouseenter(e, base, mx)
+ Scenery.mouse.mouseenter(e, {
+ wall: base,
+ index: index,
+ })
},
mousemove: function(e){
},
@@ -52,7 +55,13 @@
// base.randomize_colors()
// console.log(sidesToString(base.side))
if (Scenery.nextMedia) {
- var scenery = Scenery.addNextToWall(base, index)
+ var scenery = Scenery.addNextToWall({
+ wall: base,
+ index: index
+ })
+
+ // scenery was not placed
+ if (! scenery) return
UndoStack.push({
type: 'create-scenery',
@@ -80,53 +89,55 @@
// side: corresponds to the orientation of this wall
// vec: equivalent to the bounds of the Surface
// edge: the coordinate of the normal of this surface
- // var useX = side & FRONT_BACK
+ // var useX = side & LEFT_RIGHT
// var useA = side & (FRONT | LEFT)
- // mx.rect[useX ? 'y': 'x'][ useA ? 'a': 'b']
- // surface: an ordered set of contiguous wall regions
+ // edge = mx.rect[useX ? 'x': 'y'][ useA ? 'a': 'b']
+ // surface: an ordered set of contiguous wall regions, corresponding to mx objects
Wall.prototype.positionToMx = function(position, dimension) {
+ var x, z
switch (this.side) {
case FRONT:
- x = this.vec.a + position.a + dimension.a / 2
+ x = position.a + dimension.a / 2
z = this.edge + painting_distance_from_wall
break
case BACK:
- x = this.vec.a + position.a + dimension.a / 2
+ x = position.a + dimension.a / 2
z = this.edge - painting_distance_from_wall
break
case LEFT:
x = this.edge + painting_distance_from_wall
- z = this.vec.a + position.a + dimension.a / 2
+ z = position.a + dimension.a / 2
break
case RIGHT:
x = this.edge - painting_distance_from_wall
- z = this.vec.a + position.a + dimension.a / 2
+ z = position.a + dimension.a / 2
break
}
return {
x: x,
- y: position.b + dimension.b / 2
+ y: position.b + dimension.b / 2,
z: z,
+ rotationY: wall_rotation[ this.side ],
}
}
Wall.prototype.mxToPosition = function(mx) {
var position = new vec2(0,0)
switch (this.side) {
case FRONT:
- position.a = mx.x - mx.width / 2 - this.vec.a
+ position.a = mx.x - mx.width / 2
position.b = mx.y - mx.height / 2
break
case BACK:
- position.a = mx.x - mx.width / 2 - this.vec.a
+ position.a = mx.x - mx.width / 2
position.b = mx.y - mx.height / 2
break
case LEFT:
- position.a = mx.z - mx.width / 2 - this.vec.a
+ position.a = mx.z - mx.width / 2
position.b = mx.y - mx.height / 2
break
case RIGHT:
- position.a = mx.z - mx.width / 2 - this.vec.a
+ position.a = mx.z - mx.width / 2
position.b = mx.y - mx.height / 2
break
}
@@ -200,7 +211,6 @@
var shouldFlip = this.side & (LEFT | BACK)
var mx = this.mx
- // console.log( sidesToString(this.side), mx.length )
if (! shouldFlip) {
mx = mx.reverse()
}
diff --git a/public/assets/javascripts/rectangles/util/mouse.js b/public/assets/javascripts/rectangles/util/mouse.js
index fea3376..34d3f5e 100644
--- a/public/assets/javascripts/rectangles/util/mouse.js
+++ b/public/assets/javascripts/rectangles/util/mouse.js
@@ -138,15 +138,15 @@ function mouse (opt) {
base.tube("move", e, base.cursor)
}
}
- base.mouseenter = function(e, el){
+ base.mouseenter = function(e, target, index){
if (! base.down) return
if (opt.use_offset && ! offset) return
- base.tube("enter", e, el, base.cursor)
+ base.tube("enter", e, target, base.cursor)
}
- base.mouseleave = function(e, el){
+ base.mouseleave = function(e, target){
if (! base.down) return
if (opt.use_offset && ! offset) return
- base.tube("leave", e, el, base.cursor)
+ base.tube("leave", e, target, base.cursor)
}
base.mouseup = function(e){
var pos, new_cursor