Scenery.move = function(base){ var x, y, z, bounds var dragging = false this.bind = function(){ Scenery.mouse.bind_el(base.mx.el) Scenery.mouse.on("down", down) Scenery.mouse.on("enter", switch_wall) Scenery.mouse.on("drag", drag) Scenery.mouse.on("up", up) } this.unbind = function(){ Scenery.mouse.unbind_el(base.mx.el) Scenery.mouse.off("down", down) Scenery.mouse.off("enter", switch_wall) Scenery.mouse.off("drag", drag) Scenery.mouse.off("up", up) } function down (e, cursor){ if (e.target != base.mx.el) return; if (editor.permissions.destroy) { Scenery.remove(base.id) return } // load the modal app.controller.pick(base) if (! (editor.permissions.move || editor.permissions.resize) ) { e.clickAccepted = false return } dragging = true x = base.mx.x y = base.mx.y z = base.mx.z bounds = base.bounds document.body.classList.add("dragging") } function drag (e, cursor){ if (! dragging) return base.mx.y = bounds.y.clamp( y - cursor.y.magnitude()*cursor_amp ) 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 ) break case LEFT: case RIGHT: base.mx.z = bounds.x.clamp( z + sin(wall_rotation[base.wall.side]) * cursor.x.magnitude()*cursor_amp ) break } if (editor.permissions.resize) { Scenery.resize.move_dots() } } function up (e, cursor){ dragging = false document.body.classList.remove("dragging") } function switch_wall (e, new_wall, cursor){ if (! dragging) 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 var wall_group = old_wall_side | new_wall.side base.set_wall(new_wall) 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) { switch (old_wall_side) { case FRONT: z = bounds.x.a break case BACK: z = bounds.x.b break case LEFT: x = bounds.x.a break case RIGHT: x = bounds.x.b break } } cursor.x.a = cursor.x.b base.mx.move({ x: x, z: z, rotationY: wall_rotation[ new_wall.side ] }) if (editor.permissions.resize) { Scenery.resize.rotate_dots() Scenery.resize.move_dots() } } return this }