diff options
Diffstat (limited to 'assets/javascripts')
| -rw-r--r-- | assets/javascripts/rectangles/engine/scenery.js | 61 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/models/wall.js | 11 |
2 files changed, 55 insertions, 17 deletions
diff --git a/assets/javascripts/rectangles/engine/scenery.js b/assets/javascripts/rectangles/engine/scenery.js index e25805b..6aba7f4 100644 --- a/assets/javascripts/rectangles/engine/scenery.js +++ b/assets/javascripts/rectangles/engine/scenery.js @@ -82,25 +82,31 @@ var scenery = new function(){ if (! dragging) return if (new_wall.uid == wall.uid) return if (! new_wall.fits(img)) return + bounds = new_wall.bounds_for(img) center = new_wall.center_for(img) -// if (this.side & FRONT_BACK) { -// major_axis = this.rect.x -// minor_axis = this.rect.y -// } -// else { -// major_axis = this.rect.y -// minor_axis = this.rect.x -// } x = center.a - z = center.b + z = center.b - cursor.a = cursor.b + var direction = compare_sides(bounds) + +// switch (direction) { +// case FRONT: +// break +// case BACK: +// break +// case LEFT: +// break +// case RIGHT: +// break +// } + + cursor.x.a = cursor.x.b mx_img.move({ - x: center.a, - z: center.b, + x: x, + z: z, rotationY: wall_rotation[ new_wall.side ] }) @@ -130,7 +136,36 @@ var scenery = new function(){ document.body.classList.remove("dragging") }) } - + + function compare_sides (a, b) { + if (a === b) return 0 + if ((a | b) === FRONT_BACK) return 0 + if ((a | b) === LEFT_RIGHT) return 0 + switch (a) { + case FRONT: + return b & LEFT ? -1 : 1 + case BACK: + return b & RIGHT ? -1 : 1 + case LEFT: + return b & FRONT ? -1 : 1 + case RIGHT: + return b & BACK ? -1 : 1 + } + } + +// console.log([ +// compare_sides( LEFT, RIGHT ), +// compare_sides( FRONT, BACK ), +// compare_sides( FRONT, LEFT ), +// compare_sides( FRONT, RIGHT ), +// compare_sides( BACK, RIGHT ), +// compare_sides( BACK, LEFT ), +// compare_sides( LEFT, FRONT ), +// compare_sides( LEFT, BACK ), +// compare_sides( RIGHT, BACK ), +// compare_sides( RIGHT, FRONT ), +// ].join("\n")) + return base } diff --git a/assets/javascripts/rectangles/models/wall.js b/assets/javascripts/rectangles/models/wall.js index 8a3784b..73b98b8 100644 --- a/assets/javascripts/rectangles/models/wall.js +++ b/assets/javascripts/rectangles/models/wall.js @@ -1,5 +1,7 @@ window.Wall = (function(){ + var PAINTING_DISTANCE_FROM_WALL = 5 + var Wall = function(opt){ this.id = opt.id this.uid = Uid() @@ -40,6 +42,7 @@ window.Wall = (function(){ }, mousedown: function(){ base.randomize_colors() + console.log(sidesToString(base.side)) } }) } @@ -74,18 +77,18 @@ window.Wall = (function(){ switch (this.side) { case FRONT: x = major_axis.midpoint() - z = minor_axis.a + 10 + z = minor_axis.a + PAINTING_DISTANCE_FROM_WALL break case BACK: x = major_axis.midpoint() - z = minor_axis.b - 10 + z = minor_axis.b - PAINTING_DISTANCE_FROM_WALL break case LEFT: - x = minor_axis.a + 10 + x = minor_axis.a + PAINTING_DISTANCE_FROM_WALL z = major_axis.midpoint() break case RIGHT: - x = minor_axis.b - 10 + x = minor_axis.b - PAINTING_DISTANCE_FROM_WALL z = major_axis.midpoint() break } |
