diff options
7 files changed, 51 insertions, 37 deletions
diff --git a/public/assets/javascripts/mx/primitives/mx.image.js b/public/assets/javascripts/mx/primitives/mx.image.js index a640620..575e9c0 100644 --- a/public/assets/javascripts/mx/primitives/mx.image.js +++ b/public/assets/javascripts/mx/primitives/mx.image.js @@ -10,7 +10,7 @@ MX.Image = MX.Object3D.extend({ this.z = ops.z || 0 this.scale = ops.scale || 1 this.backface = ops.backface || false - + ops.className && this.el.classList.add(ops.className) this.backface && this.el.classList.add("backface-visible") this.el.classList.add("image") @@ -27,6 +27,7 @@ MX.Image = MX.Object3D.extend({ var image = new Image() image.onload = function(){ + if (! layer.ops) return layer.scale = layer.ops.scale || 1 layer.width = layer.ops.width || image.naturalWidth layer.height = layer.ops.height || image.naturalHeight diff --git a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js index 58592d4..119391d 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js +++ b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js @@ -35,8 +35,14 @@ var Scenery = new function(){ var scene_media = base.add(opt) // test if scenery was placed here - base.nextMedia = null - return scene_media + if (! scene_media.bounds) { + base.remove( scene_media.id ) + return null + } + else { + base.nextMedia = null + return scene_media + } } base.find = function(id){ @@ -44,9 +50,9 @@ var Scenery = new function(){ } base.remove = function(id){ - var media = base.list[id] + var scene_media = base.list[id] delete base.list[id] - media && media.destroy() + scene_media && scene_media.destroy() } base.uid = new UidGenerator(base.list) diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js index 7b716f6..effee2a 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js @@ -28,14 +28,11 @@ Scenery.types.base = Fiber.extend(function(base){ }, recenter: function () { + if (! this.bounds) return var center = this.bounds.center() center.a -= this.dimensions.a / 2 center.b -= this.dimensions.b / 2 - console.log(center+"") var mx_position = this.wall.positionToMx( center, this.dimensions ) - console.log(mx_position) - console.log(this.wall.surface.faces.join("\n")) - // also supply scale? this.mx.move(mx_position) this.position.assign(center) }, diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/image.js b/public/assets/javascripts/rectangles/engine/scenery/types/image.js index 1582e0f..3bee827 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/image.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/image.js @@ -12,11 +12,20 @@ Scenery.types.image = Scenery.types.base.extend(function(base){ this.bind() if (opt.data) { + console.log(opt.wall) + // console.log(opt.data.position) + if (opt.wall) { + var position = opt.wall.mxToPosition(opt.data.position) + console.log(position.a) + opt.index = opt.wall.surface.index_for_x( position.a, 0 ) + console.log(opt.index) + } + this.set_wall(opt) this.deserialize(opt.data) } else { this.set_wall(opt) - this.recenter() + this.bounds && this.recenter() } }, diff --git a/public/assets/javascripts/rectangles/models/surface.js b/public/assets/javascripts/rectangles/models/surface.js index a700fd4..9c45eaf 100644 --- a/public/assets/javascripts/rectangles/models/surface.js +++ b/public/assets/javascripts/rectangles/models/surface.js @@ -150,9 +150,6 @@ Surface.prototype.index_for_x = function(x, min_i){ min_i = min_i || 0 - if (x < 0 || x > this.width) { - return -1 - } for (var i = min_i; i < this.faces.length; i++) { if (this.faces[i].x.contains(x)) { return i diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js index a8bcbd8..f6742ad 100644 --- a/public/assets/javascripts/rectangles/models/wall.js +++ b/public/assets/javascripts/rectangles/models/wall.js @@ -51,9 +51,7 @@ }, mousemove: function(e){ }, - mousedown: function(){ - // base.randomize_colors() - // console.log(sidesToString(base.side)) + mousedown: function(e){ if (Scenery.nextMedia) { var scenery = Scenery.addNextToWall({ wall: base, @@ -61,7 +59,10 @@ }) // scenery was not placed - if (! scenery) return + if (! scenery) { + e.stopPropagation() + return + } UndoStack.push({ type: 'create-scenery', @@ -125,22 +126,18 @@ var position = new vec2(0,0) switch (this.side) { case FRONT: - position.a = mx.x - mx.width / 2 - position.b = mx.y - mx.height / 2 - break case BACK: - position.a = mx.x - mx.width / 2 - position.b = mx.y - mx.height / 2 + position.a = mx.x + position.b = mx.y break case LEFT: - position.a = mx.z - mx.width / 2 - position.b = mx.y - mx.height / 2 - break case RIGHT: - position.a = mx.z - mx.width / 2 - position.b = mx.y - mx.height / 2 + position.a = mx.z + position.b = mx.y break } +// if (mx.width) { position.a -= mx.width / 2 } +// if (mx.height) { position.b -= mx.height / 2 } return position } diff --git a/public/assets/javascripts/ui/editor/MediaViewer.js b/public/assets/javascripts/ui/editor/MediaViewer.js index 5540023..40bfe80 100644 --- a/public/assets/javascripts/ui/editor/MediaViewer.js +++ b/public/assets/javascripts/ui/editor/MediaViewer.js @@ -133,7 +133,9 @@ var MediaViewer = ModalView.extend({ var $floatingImg = $('.floatingImg'); Scenery.nextMedia = media - console.log(media.type) + +// console.log(media.type) + switch (media.type) { case "video": $floatingImg.attr('src', '/assets/img/playbutton.png') @@ -150,18 +152,23 @@ var MediaViewer = ModalView.extend({ function _followCursor(e) { $floatingImg.parent().css({ top: (e.pageY - (height / 2)) + 'px', - left: (e.pageX - (width / 2)) + 'px' + left: (e.pageX - (width / 2)) + 'px', }); } - $(window).on('mousemove', _followCursor); - $(window).one('click', function () { + function _hideCursor (e) { + if (Scenery.nextMedia) { + return + } var $floatingImg = $('.floatingImg') - $floatingImg.attr('src', ''); - $(window).off('mousemove', _followCursor); - $floatingImg.parent().removeClass('edit'); - }); - $ants.addClass('edit'); - _followCursor(e); + $floatingImg.attr('src', '') + $(window).off('mousemove', _followCursor) + $(window).off('mousedown', _hideCursor) + $floatingImg.parent().removeClass('edit') + } + $(window).on('mousemove', _followCursor) + $(window).on('mousedown', _hideCursor) + $ants.addClass('edit') + _followCursor(e) }, }) |
