diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-06-03 16:24:10 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-06-03 16:24:28 -0400 |
| commit | 607f69c67a5b4dc72d2754192e3cdf67d0ad11d0 (patch) | |
| tree | 6556e7922c5bedb274bb1650e5dd100643a7895d /client/assets/javascripts/rectangles/engine/scenery/image/move.js | |
| parent | d31259291d807c851de4396921e0c26b6dd8dce2 (diff) | |
partitioning client and serveR
Diffstat (limited to 'client/assets/javascripts/rectangles/engine/scenery/image/move.js')
| -rw-r--r-- | client/assets/javascripts/rectangles/engine/scenery/image/move.js | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/client/assets/javascripts/rectangles/engine/scenery/image/move.js b/client/assets/javascripts/rectangles/engine/scenery/image/move.js new file mode 100644 index 0000000..e79ede9 --- /dev/null +++ b/client/assets/javascripts/rectangles/engine/scenery/image/move.js @@ -0,0 +1,103 @@ + + +Scenery.image.move = function(base){ + + var x, y, z, bounds + var dragging = false + + this.bind = function(){ + Scenery.mouse.bind_el(base.mx_img.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.bind_el(base.mx_img.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_img.el) return; + dragging = true + x = base.mx_img.x + y = base.mx_img.y + z = base.mx_img.z + bounds = base.bounds + document.body.classList.add("dragging") + } + + function drag (e, cursor){ + if (! dragging) return + + base.mx_img.y = bounds.y.clamp( y - cursor.y.magnitude()*cursor_amp ) + switch (base.wall.side) { + case FRONT: + case BACK: + base.mx_img.x = bounds.x.clamp( x + cos(wall_rotation[base.wall.side]) * cursor.x.magnitude()*cursor_amp ) + break + case LEFT: + case RIGHT: + base.mx_img.z = bounds.x.clamp( z + sin(wall_rotation[base.wall.side]) * cursor.x.magnitude()*cursor_amp ) + break + } + + 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.uid == base.wall.uid) return + if (! new_wall.fits(base.img)) return + + base.bounds = bounds = new_wall.bounds_for(base.img) + base.center = new_wall.center() + + x = base.center.a + z = base.center.b + + var wall_group = base.wall.side | new_wall.side + + if (base.wall.side !== new_wall.side && wall_group !== FRONT_BACK && wall_group !== LEFT_RIGHT) { + switch (base.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_img.move({ + x: x, + z: z, + rotationY: wall_rotation[ new_wall.side ] + }) + + base.wall = new_wall + + Scenery.resize.rotate_dots() + Scenery.resize.move_dots() + } + + return this + +}
\ No newline at end of file |
