diff options
Diffstat (limited to 'public/assets/javascripts/rectangles/models/wall.js')
| -rw-r--r-- | public/assets/javascripts/rectangles/models/wall.js | 40 |
1 files changed, 25 insertions, 15 deletions
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() } |
