diff options
Diffstat (limited to 'public/assets/javascripts/rectangles/engine/scenery/move.js')
| -rw-r--r-- | public/assets/javascripts/rectangles/engine/scenery/move.js | 81 |
1 files changed, 50 insertions, 31 deletions
diff --git a/public/assets/javascripts/rectangles/engine/scenery/move.js b/public/assets/javascripts/rectangles/engine/scenery/move.js index ef9bc32..93bccb0 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/move.js +++ b/public/assets/javascripts/rectangles/engine/scenery/move.js @@ -1,7 +1,7 @@ Scenery.move = function(base){ - var x, y, z, bounds + var x, y, z, position, dimension, bounds var dragging = false var oldState @@ -30,6 +30,9 @@ Scenery.move = function(base){ redo: { id: base.id }, }) + // TODO: watch individual scenery object here + Minotaur.watch( app.router.editorView.settings ) + Scenery.remove(base.id) return } @@ -45,7 +48,11 @@ Scenery.move = function(base){ x = base.mx.x y = base.mx.y z = base.mx.z + bounds = base.bounds + dimension = base.dimensions + position = base.wall.mxToPosition( base.mx, dimension ) + oldState = base.serialize() document.body.classList.add("dragging") } @@ -53,18 +60,28 @@ Scenery.move = function(base){ function drag (e, cursor){ if (! dragging) return - base.mx.y = bounds.y.clamp( y - cursor.y.magnitude()*cursor_amp ) + var flipX = base.wall.side & (FRONT | RIGHT) + + var delta = cursor.delta() + delta.mul( cursor_amp ) // TODO: this should be proportional to your distance from the wall + if (flipX) { delta.a *= -1 } + delta.b *= -1 + + var new_bounds = base.wall.surface.translate( bounds, dimension, position, delta ) + if (new_bounds) bounds = new_bounds + if (flipX) { delta.a *= -1 } + + base.mx.y = position.b + delta.b + dimension.b / 2 switch (base.wall.side) { case FRONT: case BACK: - base.mx.x = bounds.x.clamp( x + cos(wall_rotation[base.wall.side]) * cursor.x.magnitude()*cursor_amp ) + base.mx.x = position.a + delta.a * cos(wall_rotation[base.wall.side]) + dimension.a / 2 break case LEFT: case RIGHT: - base.mx.z = bounds.x.clamp( z + sin(wall_rotation[base.wall.side]) * cursor.x.magnitude()*cursor_amp ) + base.mx.z = position.a + delta.a * sin(wall_rotation[base.wall.side]) + dimension.a / 2 break } - if (editor.permissions.resize) { Scenery.resize.move_dots() } @@ -76,60 +93,62 @@ Scenery.move = function(base){ dragging = false document.body.classList.remove("dragging") - console.log("pushing", oldState, base.serialize()) - UndoStack.push({ type: 'update-scenery', undo: oldState, redo: base.serialize(), }) - + + // TODO: watch individual scenery object here + Minotaur.watch( app.router.editorView.settings ) + oldState = null } - function switch_wall (e, new_wall, cursor){ + function switch_wall (e, target, cursor){ if (! dragging) return - if (new_wall.uid == base.wall.uid) return - if (! new_wall.fits(base.media, base.scale)) return - + if (target.wall.id == base.wall.id) 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 + var new_bounds = target.wall.surface.bounds_at_index_with_dimensions(target.index || 0, dimension) - base.set_wall(new_wall) + if (! new_bounds) return - 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) { + base.wall = target.wall + base.bounds = bounds = new_bounds + + position.a = bounds.x.midpoint() - dimension.a / 2 + + 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 + position.a = bounds.x.a + dimension.a / 2 break case BACK: - z = bounds.x.b + position.a = bounds.x.b - dimension.a / 2 break case LEFT: - x = bounds.x.a + position.a = bounds.x.a + dimension.a / 2 break case RIGHT: - x = bounds.x.b + position.a = bounds.x.b - dimension.a / 2 break } } - cursor.x.a = cursor.x.b - - base.mx.move({ - x: x, - z: z, - rotationY: wall_rotation[ new_wall.side ] - }) + var mx_delta = base.wall.positionToMx( position, dimension ) + base.mx.move(mx_delta) if (editor.permissions.resize) { Scenery.resize.rotate_dots() - Scenery.resize.move_dots() +// Scenery.resize.move_dots() } + + cursor.x.a = cursor.x.b + //var delta = cursor.delta() + drag(e, cursor) + } return this |
