From befeb2ed9b7f7086ec0861cbfe4ab6450e1987af Mon Sep 17 00:00:00 2001 From: Julie Lala Date: Fri, 20 Jun 2014 01:00:35 -0400 Subject: disarm delete after upload --- public/assets/javascripts/rectangles/engine/scenery/resize.js | 6 ++++-- public/assets/javascripts/rectangles/engine/scenery/types/image.js | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'public/assets/javascripts/rectangles/engine') diff --git a/public/assets/javascripts/rectangles/engine/scenery/resize.js b/public/assets/javascripts/rectangles/engine/scenery/resize.js index 2a400f5..33efd05 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/resize.js +++ b/public/assets/javascripts/rectangles/engine/scenery/resize.js @@ -164,13 +164,15 @@ Scenery.resize = new function(){ var translation = new vec2( x_sign * cursor.x.magnitude() * cursor_amp, y_sign * cursor.y.magnitude() * cursor_amp ) + // resize using scale here instead of width and height + if (selected_dot.side & LEFT_RIGHT) { - obj.mx.width = dimensions.a + translation.a +// obj.mx.width = dimensions.a + translation.a obj.mx.x = position.a + x_sign * cos(rotationY) * translation.a/2 * obj.mx.scale obj.mx.z = position.c + x_sign * sin(rotationY) * translation.a/2 * obj.mx.scale } if (selected_dot.side & TOP_BOTTOM) { - obj.mx.height = dimensions.b + translation.b +// obj.mx.height = dimensions.b + translation.b obj.mx.y = position.b - y_sign * translation.b/2 * obj.mx.scale } diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/image.js b/public/assets/javascripts/rectangles/engine/scenery/types/image.js index 98b26f4..b5b5551 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/image.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/image.js @@ -16,6 +16,7 @@ Scenery.types.image = Scenery.types.base.extend(function(base){ build: function(){ this.mx = new MX.Image({ src: this.media.url, + scale: this.scale, y: this.scale * this.media.height/2, backface: false, }) @@ -24,12 +25,14 @@ Scenery.types.image = Scenery.types.base.extend(function(base){ serialize: function(){ var data = base.serialize.call(this) - console.log(data) +// console.log(data) return data }, deserialize: function(data){ this.mx.move(data.position) + this.mx.ops.width = data.dimensions.a + this.mx.ops.height = data.dimensions.b }, } -- cgit v1.2.3-70-g09d2 From 1a1009d5cbfb1deb7cc110bacf3fd76236cf25a9 Mon Sep 17 00:00:00 2001 From: Julie Lala Date: Fri, 20 Jun 2014 01:40:43 -0400 Subject: resize based on magnitude.. --- .../assets/javascripts/rectangles/engine/scenery/resize.js | 14 ++++++++------ public/assets/javascripts/rectangles/models/rect.js | 3 +++ public/assets/javascripts/rectangles/models/vec2.js | 3 +++ 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'public/assets/javascripts/rectangles/engine') diff --git a/public/assets/javascripts/rectangles/engine/scenery/resize.js b/public/assets/javascripts/rectangles/engine/scenery/resize.js index 33efd05..50c97bd 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/resize.js +++ b/public/assets/javascripts/rectangles/engine/scenery/resize.js @@ -161,19 +161,21 @@ Scenery.resize = new function(){ var x_sign = selected_dot.side & LEFT ? -1 : selected_dot.side & RIGHT ? 1 : 0 var y_sign = selected_dot.side & TOP ? -1 : selected_dot.side & BOTTOM ? 1 : 0 - - var translation = new vec2( x_sign * cursor.x.magnitude() * cursor_amp, y_sign * cursor.y.magnitude() * cursor_amp ) - // resize using scale here instead of width and height + var mag = cursor.magnitude() + + // fix resizing here +// obj.mx.scale = obj.media.scale +// var translation = new vec2( x_sign * cursor.x.magnitude() * cursor_amp, y_sign * cursor.y.magnitude() * cursor_amp ) if (selected_dot.side & LEFT_RIGHT) { // obj.mx.width = dimensions.a + translation.a - obj.mx.x = position.a + x_sign * cos(rotationY) * translation.a/2 * obj.mx.scale - obj.mx.z = position.c + x_sign * sin(rotationY) * translation.a/2 * obj.mx.scale + obj.mx.x = position.a + x_sign * cos(rotationY) * mag/2 * obj.mx.scale + obj.mx.z = position.c + x_sign * sin(rotationY) * mag/2 * obj.mx.scale } if (selected_dot.side & TOP_BOTTOM) { // obj.mx.height = dimensions.b + translation.b - obj.mx.y = position.b - y_sign * translation.b/2 * obj.mx.scale + obj.mx.y = position.b - y_sign * mag/2 * obj.mx.scale } // bounds = obj.wall.bounds_for(dimensions) diff --git a/public/assets/javascripts/rectangles/models/rect.js b/public/assets/javascripts/rectangles/models/rect.js index cb14e66..0bab0e4 100644 --- a/public/assets/javascripts/rectangles/models/rect.js +++ b/public/assets/javascripts/rectangles/models/rect.js @@ -25,6 +25,9 @@ window.Rect = (function(){ Rect.prototype.area = function(){ return this.x.length() * this.y.length() } + Rect.prototype.magnitude = function(){ + return dist(this.x.a, this.y.a, this.x.b, this.y.b) + } Rect.prototype.mul = function(n){ this.x.mul(n) diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js index e56a010..5cdd54c 100644 --- a/public/assets/javascripts/rectangles/models/vec2.js +++ b/public/assets/javascripts/rectangles/models/vec2.js @@ -8,6 +8,9 @@ vec2.prototype.magnitude = function(){ vec2.prototype.length = function(){ return abs(this.b-this.a) } +vec2.prototype.dist = function(){ + return dist(0,this.a,0,this.b) +} vec2.prototype.clone = function(){ return new vec2(this.a, this.b) } -- cgit v1.2.3-70-g09d2 From 8aede8cb98669537213eb267e8602dc3e8266c97 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 20 Jun 2014 12:14:51 -0400 Subject: preserve proportions on scale (also smoother now) --- .../javascripts/mx/extensions/mx.movements.js | 2 +- .../javascripts/rectangles/engine/scenery/move.js | 4 +- .../rectangles/engine/scenery/resize.js | 50 +++++++++------------- .../rectangles/engine/scenery/types/_object.js | 3 +- .../rectangles/engine/scenery/types/image.js | 3 +- .../assets/javascripts/rectangles/models/rect.js | 3 ++ .../assets/javascripts/rectangles/models/wall.js | 13 +++--- 7 files changed, 36 insertions(+), 42 deletions(-) (limited to 'public/assets/javascripts/rectangles/engine') diff --git a/public/assets/javascripts/mx/extensions/mx.movements.js b/public/assets/javascripts/mx/extensions/mx.movements.js index d02b2d2..f176e8b 100644 --- a/public/assets/javascripts/mx/extensions/mx.movements.js +++ b/public/assets/javascripts/mx/extensions/mx.movements.js @@ -25,7 +25,7 @@ MX.Movements = function (cam, viewHeight) { vx = vy = vz = 0, creepFactor = 0.3 - var DEFAULT_SCALE = scale = 1.0 + var DEFAULT_SCALE = 1.0, scale = DEFAULT_SCALE var pos = { x: 0, y: 0, z: 0, rotationX: 0, rotationY: 0 } diff --git a/public/assets/javascripts/rectangles/engine/scenery/move.js b/public/assets/javascripts/rectangles/engine/scenery/move.js index ce4f297..8acc1c2 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/move.js +++ b/public/assets/javascripts/rectangles/engine/scenery/move.js @@ -56,11 +56,11 @@ Scenery.move = function(base){ function switch_wall (e, new_wall, cursor){ if (! dragging) return if (new_wall.uid == base.wall.uid) return - if (! new_wall.fits(base.media)) 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 diff --git a/public/assets/javascripts/rectangles/engine/scenery/resize.js b/public/assets/javascripts/rectangles/engine/scenery/resize.js index 50c97bd..ac13326 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/resize.js +++ b/public/assets/javascripts/rectangles/engine/scenery/resize.js @@ -6,7 +6,7 @@ Scenery.resize = new function(){ var obj var x, y, z, bounds var dragging = false - var dimensions, position + var dimensions, position, scale var dots = [], dot, selected_dot @@ -147,58 +147,48 @@ Scenery.resize = new function(){ selected_dot = selection[0] dragging = true - dimensions = new vec2(obj.mx.width, obj.mx.height) + dimensions = obj.dimensions position = new vec3(obj.mx.x, obj.mx.y, obj.mx.z) + scale = obj.mx.scale - console.log("down on", sidesToString(selected_dot.side)) - document.body.classList.add("dragging") } function drag (e, cursor){ if (! dragging) return - // cursor.x.magnitude()*cursor_amp var x_sign = selected_dot.side & LEFT ? -1 : selected_dot.side & RIGHT ? 1 : 0 var y_sign = selected_dot.side & TOP ? -1 : selected_dot.side & BOTTOM ? 1 : 0 - + var width = cursor.x.magnitude() + var height = cursor.y.magnitude() var mag = cursor.magnitude() - - // fix resizing here -// obj.mx.scale = obj.media.scale -// var translation = new vec2( x_sign * cursor.x.magnitude() * cursor_amp, y_sign * cursor.y.magnitude() * cursor_amp ) + var old_width = dimensions.a * scale + + if (abs(width) > abs(height)) { + mag = x_sign * mag * sign(width) + } + else { + mag = y_sign * mag * sign(height) + } + + obj.mx.scale = scale * (old_width + mag) / old_width if (selected_dot.side & LEFT_RIGHT) { -// obj.mx.width = dimensions.a + translation.a - obj.mx.x = position.a + x_sign * cos(rotationY) * mag/2 * obj.mx.scale - obj.mx.z = position.c + x_sign * sin(rotationY) * mag/2 * obj.mx.scale + obj.mx.x = position.a + cos(rotationY) * mag/2 * (x_sign) + obj.mx.z = position.c + sin(rotationY) * mag/2 * (x_sign) } if (selected_dot.side & TOP_BOTTOM) { -// obj.mx.height = dimensions.b + translation.b - obj.mx.y = position.b - y_sign * mag/2 * obj.mx.scale + obj.mx.y = position.b - mag/2 * y_sign } - -// bounds = obj.wall.bounds_for(dimensions) - -// 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 -// } base.move_dots() - } function up (e, cursor){ dragging = false selected_dot = null + obj.scale = obj.mx.ops.scale = obj.mx.scale + obj.set_wall() document.body.classList.remove("dragging") } diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js index f892c0c..1aa037c 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js @@ -8,6 +8,7 @@ Scenery.types.base = Fiber.extend(function(base){ this.move = new Scenery.move (this) this.media = opt.media this.dimensions = new vec2(this.media.width, this.media.height) + this.scale = this.media.scale if (opt.wall) { this.set_wall(opt.wall) @@ -42,7 +43,7 @@ Scenery.types.base = Fiber.extend(function(base){ set_wall: function(wall){ this.wall = wall || this.wall - this.bounds = this.wall.bounds_for(this.media) + this.bounds = this.wall.bounds_for(this.media, this.scale) this.center = this.wall.center() }, diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/image.js b/public/assets/javascripts/rectangles/engine/scenery/types/image.js index b5b5551..b668e6a 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/image.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/image.js @@ -5,7 +5,7 @@ Scenery.types.image = Scenery.types.base.extend(function(base){ init: function(opt){ base.init.call(this, opt) - this.scale = this.media.scale = 300 / max(300, this.media.width) + this.scale = 300 / max(300, this.media.width) this.build() this.bind() @@ -25,7 +25,6 @@ Scenery.types.image = Scenery.types.base.extend(function(base){ serialize: function(){ var data = base.serialize.call(this) -// console.log(data) return data }, diff --git a/public/assets/javascripts/rectangles/models/rect.js b/public/assets/javascripts/rectangles/models/rect.js index 0bab0e4..a4fbd87 100644 --- a/public/assets/javascripts/rectangles/models/rect.js +++ b/public/assets/javascripts/rectangles/models/rect.js @@ -28,6 +28,9 @@ window.Rect = (function(){ Rect.prototype.magnitude = function(){ return dist(this.x.a, this.y.a, this.x.b, this.y.b) } + Rect.prototype.maxDimension = function(){ + return abs(this.width) > abs(this.height) ? this.width : this.height + } Rect.prototype.mul = function(n){ this.x.mul(n) diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js index e327070..d0a2045 100644 --- a/public/assets/javascripts/rectangles/models/wall.js +++ b/public/assets/javascripts/rectangles/models/wall.js @@ -49,19 +49,20 @@ window.Wall = (function(){ }) } - Wall.prototype.bounds_for = function(img) { + Wall.prototype.bounds_for = function(img, scale) { + scale = scale || 1 var coord = this.side & FRONT_BACK ? this.rect.x : this.rect.y - var halfWidth = img.width/2 * img.scale - var halfHeight = img.height/2 * img.scale + var halfWidth = img.width/2 * scale + var halfHeight = img.height/2 * scale return new Rect( new vec2( coord.a + halfWidth, coord.b - halfWidth ), new vec2( halfHeight, Rooms.list[this.room].height - halfHeight ) ) } - Wall.prototype.fits = function(img){ - if (this.side & FRONT_BACK && this.rect.x.length() < img.width * img.scale) { + Wall.prototype.fits = function(img, scale){ + if (this.side & FRONT_BACK && this.rect.x.length() < img.width * scale) { return false } - if (this.side & LEFT_RIGHT && this.rect.y.length() < img.width * img.scale) { + if (this.side & LEFT_RIGHT && this.rect.y.length() < img.width * scale) { return false } return true -- cgit v1.2.3-70-g09d2 From 4d41eaa24d04fe61233c024ece899731aaf9f1e8 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 20 Jun 2014 12:38:35 -0400 Subject: better wall colors --- .../assets/javascripts/rectangles/engine/scenery/_scenery.js | 1 - public/assets/javascripts/rectangles/models/wall.js | 7 ++++--- public/assets/javascripts/rectangles/util/colors.js | 10 +++++++--- public/assets/javascripts/ui/SiteRouter.js | 2 +- public/assets/javascripts/ui/editor/EditorToolbar.js | 2 +- public/assets/javascripts/ui/site/LayoutsModal.js | 5 +++++ public/assets/stylesheets/app.css | 4 ++-- views/partials/header.ejs | 2 +- views/partials/scripts.ejs | 2 +- 9 files changed, 22 insertions(+), 13 deletions(-) (limited to 'public/assets/javascripts/rectangles/engine') diff --git a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js index 0a3187c..3fe6b66 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js +++ b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js @@ -45,7 +45,6 @@ var Scenery = new function(){ var scenery = base.media.map(function(media){ return media.serialize() }) - console.log(scenery) return scenery } diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js index d0a2045..b2a5b12 100644 --- a/public/assets/javascripts/rectangles/models/wall.js +++ b/public/assets/javascripts/rectangles/models/wall.js @@ -40,8 +40,8 @@ window.Wall = (function(){ mousemove: function(e){ }, mousedown: function(){ - base.randomize_colors() - console.log(sidesToString(base.side)) + // base.randomize_colors() + // console.log(sidesToString(base.side)) if (Scenery.nextMedia) { Scenery.addNextToWall(base) } @@ -58,6 +58,7 @@ window.Wall = (function(){ return new Rect( new vec2( coord.a + halfWidth, coord.b - halfWidth ), new vec2( halfHeight, Rooms.list[this.room].height - halfHeight ) ) } + Wall.prototype.fits = function(img, scale){ if (this.side & FRONT_BACK && this.rect.x.length() < img.width * scale) { return false @@ -118,7 +119,7 @@ window.Wall = (function(){ } Wall.prototype.randomize_colors = function(){ - var color = choice(window.colors) + var color = window.grayColors[ this.side | this.half_side ] this.siblings().forEach(function(w){ w.color(color) }) } diff --git a/public/assets/javascripts/rectangles/util/colors.js b/public/assets/javascripts/rectangles/util/colors.js index 58553b1..c590072 100644 --- a/public/assets/javascripts/rectangles/util/colors.js +++ b/public/assets/javascripts/rectangles/util/colors.js @@ -16,10 +16,10 @@ "rgba(0,0,0,0.4)", ], bone: [ - "hsla(0,0%,90%,0.95)", - "hsla(0,0%,80%,0.95)", + "hsla(0,0%,91%,0.95)", + "hsla(0,0%,88%,0.95)", "hsla(0,0%,85%,0.95)", - "hsla(0,0%,75%,0.95)", + "hsla(0,0%,82%,0.95)", ], colors: [ "rgba(255,0,0,0.5)", @@ -53,5 +53,9 @@ }) window.colors = color_palettes[select ? select.value : 'bone'] + window.grayColors = {} + _.zip([FRONT, LEFT, BACK, RIGHT], color_palettes.bone).map(function(pair){ + window.grayColors[pair[0]] = pair[1] + }) window.palettes = color_palettes })() diff --git a/public/assets/javascripts/ui/SiteRouter.js b/public/assets/javascripts/ui/SiteRouter.js index f0c5530..dae2131 100644 --- a/public/assets/javascripts/ui/SiteRouter.js +++ b/public/assets/javascripts/ui/SiteRouter.js @@ -12,6 +12,7 @@ var SiteRouter = Router.extend({ "click [data-role='edit-document-modal']": 'editDocument', "click [data-role='delete-document-modal']": 'destroyDocument', "click [data-role='show-layouts-modal']": 'layoutPicker', + "click [data-role='show-projects-modal']": 'projectPicker', }, routes: { @@ -61,7 +62,6 @@ var SiteRouter = Router.extend({ this.layoutsModal.load() }, - projectPicker: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/project") diff --git a/public/assets/javascripts/ui/editor/EditorToolbar.js b/public/assets/javascripts/ui/editor/EditorToolbar.js index 76218fe..f966ab6 100644 --- a/public/assets/javascripts/ui/editor/EditorToolbar.js +++ b/public/assets/javascripts/ui/editor/EditorToolbar.js @@ -7,9 +7,9 @@ var EditorToolbar = View.extend({ "click [data-role='toggle-project-settings']": 'toggleSettings', "click [data-role='open-media-viewer']": 'openMediaViewer', "click [data-role='resize-media']": 'resize', + "click [data-role='delete-media']": 'deleteMedia', "click [data-role='toggle-wallpaper-panel']": 'toggleWallpaper', "click [data-role='toggle-light-control']": 'toggleLightControl', - "click [data-role='delete-media']": 'deleteMedia', "click [data-role='edit-wall-text']": 'editWallText', }, diff --git a/public/assets/javascripts/ui/site/LayoutsModal.js b/public/assets/javascripts/ui/site/LayoutsModal.js index 47fa193..46ed634 100644 --- a/public/assets/javascripts/ui/site/LayoutsModal.js +++ b/public/assets/javascripts/ui/site/LayoutsModal.js @@ -52,6 +52,11 @@ var ProjectsModal = ModalView.extend(LayoutsIndex.prototype).extend({ // actually do window.location.pathname = "/project/" + $layout.data("slug") + }, + + newProject: function(e){ + e && e.preventDefault() + window.location.pathname = "/project/new" } }) diff --git a/public/assets/stylesheets/app.css b/public/assets/stylesheets/app.css index 93d68ca..cb56a68 100755 --- a/public/assets/stylesheets/app.css +++ b/public/assets/stylesheets/app.css @@ -748,10 +748,10 @@ h5 { background-image:url(https://s3.amazonaws.com/luckyplop/735c46b0268cd511a22c37bc0c11e9f60c4459b2.png)!important; cursor:move; } -.deleteActive .image { +.deleteActive .mx-object3d.image { cursor:pointer; } -.deleteActive .image:after { +.deleteActive .mx-object3d.image:after { content: "\e68f"; font-family: 'ionicons'; speak: none; diff --git a/views/partials/header.ejs b/views/partials/header.ejs index 55505ed..e83f42a 100644 --- a/views/partials/header.ejs +++ b/views/partials/header.ejs @@ -7,7 +7,7 @@ Layouts [[ } ]] - Projects + Projects [[ if (profile && String(user._id) == String(profile._id)) { ]] Edit Profile diff --git a/views/partials/scripts.ejs b/views/partials/scripts.ejs index 2d34480..df80d95 100644 --- a/views/partials/scripts.ejs +++ b/views/partials/scripts.ejs @@ -10,8 +10,8 @@ - + -- cgit v1.2.3-70-g09d2 From 3e261676b2f836d272f094e73b0b26c55ef674db Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 20 Jun 2014 13:22:12 -0400 Subject: minimap --- public/assets/javascripts/rectangles/_env.js | 3 +- .../javascripts/rectangles/engine/map/_map.js | 47 ++++++-- .../javascripts/rectangles/engine/map/draw.js | 17 ++- .../assets/javascripts/rectangles/engine/map/ui.js | 131 -------------------- .../javascripts/rectangles/engine/map/ui_editor.js | 132 ++++++++++++++++++++ .../rectangles/engine/map/ui_minimap.js | 133 +++++++++++++++++++++ public/assets/javascripts/ui/editor/EditorView.js | 10 +- public/assets/stylesheets/app.css | 2 +- views/editor.ejs | 2 - views/partials/scripts.ejs | 3 +- 10 files changed, 327 insertions(+), 153 deletions(-) delete mode 100644 public/assets/javascripts/rectangles/engine/map/ui.js create mode 100644 public/assets/javascripts/rectangles/engine/map/ui_editor.js create mode 100644 public/assets/javascripts/rectangles/engine/map/ui_minimap.js (limited to 'public/assets/javascripts/rectangles/engine') diff --git a/public/assets/javascripts/rectangles/_env.js b/public/assets/javascripts/rectangles/_env.js index 1b95989..63d3609 100644 --- a/public/assets/javascripts/rectangles/_env.js +++ b/public/assets/javascripts/rectangles/_env.js @@ -22,8 +22,6 @@ environment.init = function(){ app.movements.gravity(true) - // $("#map").hide() - Rooms.init() Scenery.init() @@ -32,5 +30,6 @@ environment.init = function(){ } environment.update = function(t){ map.update() + window.minimap && window.minimap.update && minimap.update() z = false } diff --git a/public/assets/javascripts/rectangles/engine/map/_map.js b/public/assets/javascripts/rectangles/engine/map/_map.js index c27c159..0623d05 100644 --- a/public/assets/javascripts/rectangles/engine/map/_map.js +++ b/public/assets/javascripts/rectangles/engine/map/_map.js @@ -1,42 +1,67 @@ /* */ -var Map = function(){ +var Map = function(opt){ + + opt = defaults(opt, { + type: "editor", + el: document.querySelector("#map"), + width: window.innerWidth, + height: window.innerHeight, + zoom: -2, + }) + var base = this - base.el = document.querySelector("#map") + base.el = opt.el if (! base.el) return - base.dimensions = new vec2(window.innerWidth, window.innerHeight) + base.dimensions = new vec2(opt.width, opt.height) base.center = new vec2(0,0) - base.sides = function(){ + base.sides_for_center = function(){ var sides = base.dimensions.clone().div(2).div(base.zoom) return new Rect( base.center.a - sides.a, -base.center.b - sides.b, base.center.a + sides.a, -base.center.b + sides.b ) } + base.sides_for_camera = function(){ + var sides = base.dimensions.clone().div(2).div(base.zoom) + return new Rect( scene.camera.x - sides.a, scene.camera.z - sides.b, + scene.camera.x + sides.a, scene.camera.z + sides.b ) + } + - base.zoom = 1/4 - base.zoom_exponent = -2 base.set_zoom = function (n) { base.zoom_exponent = n - base.zoom = pow(2, base.zoom_exponent) + base.zoom = pow(2, n) } + base.set_zoom(opt.zoom) var canvas = base.canvas = document.createElement("canvas") canvas.width = base.dimensions.a canvas.height = base.dimensions.b - document.querySelector("#map").appendChild(canvas) + base.el.appendChild(canvas) - base.draw = new MapDraw (base) - base.ui = new MapUI (base) + switch (opt.type) { + case "editor": + base.draw = new MapDraw (base) + base.ui = new Map.UI.Editor (base) + base.sides = base.sides_for_center + $(window).resize(base.resize) + break + + case "minimap": + base.draw = new MapDraw (base, { center: scene.camera }) + base.ui = new Map.UI.Minimap (base) + base.sides = base.sides_for_camera + break + } base.resize = function(){ canvas.width = base.dimensions.a = window.innerWidth canvas.height = base.dimensions.b = window.innerHeight } - $(window).resize(base.resize) base.update = function(){ base.draw.animate() diff --git a/public/assets/javascripts/rectangles/engine/map/draw.js b/public/assets/javascripts/rectangles/engine/map/draw.js index a441de4..9a3651c 100644 --- a/public/assets/javascripts/rectangles/engine/map/draw.js +++ b/public/assets/javascripts/rectangles/engine/map/draw.js @@ -1,5 +1,7 @@ -var MapDraw = function(map){ +var MapDraw = function(map, opt){ + + opt = defaults(opt, {}) var draw = this @@ -8,11 +10,16 @@ var MapDraw = function(map){ draw.animate = function(){ ctx.save() draw.clear() - draw.ruler() + // draw.ruler() ctx.translate( map.dimensions.a * 1/2, map.dimensions.b * 1/2) ctx.scale( map.zoom, map.zoom ) - ctx.translate( map.center.a, map.center.b) + if (opt.center) { + ctx.translate( opt.center.x, - opt.center.z ) + } + else { + ctx.translate( map.center.a, map.center.b ) + } ctx.scale( -1, 1 ) draw.regions(Rooms.regions, colors) @@ -29,7 +36,7 @@ var MapDraw = function(map){ ctx.translate( map.dimensions.a * 1/2, map.dimensions.b * 1/2) ctx.scale( map.zoom, map.zoom ) - ctx.translate( map.center.a, map.center.b) + ctx.translate( map.center.a, map.center.b ) ctx.scale( -1, 1 ) draw.regions(Rooms.regions, ["#fff"]) @@ -109,6 +116,7 @@ var MapDraw = function(map){ } draw.coords = function(){ + /* ctx.fillStyle = "#888"; dot_at(0,0) ctx.fillStyle = "#bbb"; @@ -120,6 +128,7 @@ var MapDraw = function(map){ ctx.fillStyle = "#eee"; dot_at(300,0) dot_at(0,300) + */ ctx.strokeStyle = "rgba(0,0,0,0.1)" ctx.lineWidth = 1/map.zoom diff --git a/public/assets/javascripts/rectangles/engine/map/ui.js b/public/assets/javascripts/rectangles/engine/map/ui.js deleted file mode 100644 index 7890c9b..0000000 --- a/public/assets/javascripts/rectangles/engine/map/ui.js +++ /dev/null @@ -1,131 +0,0 @@ - -var MapUI = function(map){ - - var base = this - - base.creating = base.dragging = base.resizing = false - - base.mouse = new mouse({ - el: map.el, - down: down, - move: move, - drag: drag, - up: up, - rightclick: rightclick, - }) - - base.wheel = new wheel({ - el: map.el, - update: mousewheel, - }) - - // - - function down (e, cursor){ - cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) - cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) - - if (e.ctrlKey || e.which === 3) { - cursor.quantize(1/map.zoom) - map.center.a = cursor.x.a - map.center.b = -cursor.y.a - console.log(map.center+"") - cursor.x.b = cursor.x.a - cursor.y.b = cursor.y.a - base.mouse.down = false - e.preventDefault() - e.stopPropagation() - return - } - - var intersects = Rooms.filter(function(r){ - return r.focused = r.rect.contains(cursor.x.a, cursor.y.a) - }) - - if (intersects.length) { - base.dragging = intersects[0] - base.resizing = base.dragging.rect.nearEdge(cursor.x.a, cursor.y.a, resize_margin / map.zoom) - base.dragging.rect.translation.sides = base.resizing - } - else { - base.creating = true - } - - if (e.shiftKey && base.dragging) { - base.dragging.rect.quantize(10/map.zoom) - } - } - - function move (e, cursor) { - cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) - cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) - } - - function drag (e, cursor) { - cursor.x.b = ((cursor.x.b/map.dimensions.a)+0.5) * map.dimensions.a / map.zoom + map.center.a - cursor.y.b = ((cursor.y.b/map.dimensions.b)-0.5) * map.dimensions.b / map.zoom - map.center.b - - if (base.resizing) { - var x_length = base.dragging.rect.x.length(), - y_length = base.dragging.rect.y.length() - - if (base.resizing & LEFT) { - base.dragging.rect.translation.a = clamp( cursor.x.magnitude(), x_length - side_max, x_length - side_min ) - } - if (base.resizing & RIGHT) { - base.dragging.rect.translation.a = clamp( cursor.x.magnitude(), side_min - x_length, side_max - x_length ) - } - if (base.resizing & FRONT) { - base.dragging.rect.translation.b = clamp( cursor.y.magnitude(), y_length - side_max, y_length - side_min ) - } - if (base.resizing & BACK) { - base.dragging.rect.translation.b = clamp( cursor.y.magnitude(), side_min - y_length, side_max - y_length ) - } - } - else if (base.dragging) { - base.dragging.rect.translation.a = cursor.x.magnitude() - base.dragging.rect.translation.b = cursor.y.magnitude() - } - } - - function up (e, cursor, new_cursor) { - new_cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) - new_cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) - - if (base.creating) { - if (cursor.height() > side_min && cursor.width() > side_min) { - cursor.x.abs().quantize(1) - cursor.y.abs().quantize(1) - Rooms.add_with_rect( cursor ) - } - } - - if (base.resizing) { - base.dragging.rect.resize() - } - else if (base.dragging) { - base.dragging.rect.translate() - } - - base.creating = base.dragging = base.resizing = false - } - - function mousewheel (e, val, delta){ - var cursor = base.mouse.cursor - - var intersects = Rooms.filter(function(r){ - return r.focused = r.rect.contains(cursor.x.a, cursor.y.a) - }) - - if (intersects.length) { - intersects[0].height = clamp( ~~(intersects[0].height - delta), height_min, height_max ) - Rooms.clipper.update() - } - else { - map.set_zoom(map.zoom_exponent - delta/20) - } - } - - function rightclick (e){ - } -} diff --git a/public/assets/javascripts/rectangles/engine/map/ui_editor.js b/public/assets/javascripts/rectangles/engine/map/ui_editor.js new file mode 100644 index 0000000..262272b --- /dev/null +++ b/public/assets/javascripts/rectangles/engine/map/ui_editor.js @@ -0,0 +1,132 @@ + +Map.UI = Map.UI || {} +Map.UI.Editor = function(map){ + + var base = this + + base.creating = base.dragging = base.resizing = false + + base.mouse = new mouse({ + el: map.el, + down: down, + move: move, + drag: drag, + up: up, + rightclick: rightclick, + }) + + base.wheel = new wheel({ + el: map.el, + update: mousewheel, + }) + + // + + function down (e, cursor){ + cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) + cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) + + if (e.ctrlKey || e.which === 3) { + cursor.quantize(1/map.zoom) + map.center.a = cursor.x.a + map.center.b = -cursor.y.a + console.log(map.center+"") + cursor.x.b = cursor.x.a + cursor.y.b = cursor.y.a + base.mouse.down = false + e.preventDefault() + e.stopPropagation() + return + } + + var intersects = Rooms.filter(function(r){ + return r.focused = r.rect.contains(cursor.x.a, cursor.y.a) + }) + + if (intersects.length) { + base.dragging = intersects[0] + base.resizing = base.dragging.rect.nearEdge(cursor.x.a, cursor.y.a, resize_margin / map.zoom) + base.dragging.rect.translation.sides = base.resizing + } + else { + base.creating = true + } + + if (e.shiftKey && base.dragging) { + base.dragging.rect.quantize(10/map.zoom) + } + } + + function move (e, cursor) { + cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) + cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) + } + + function drag (e, cursor) { + cursor.x.b = ((cursor.x.b/map.dimensions.a)+0.5) * map.dimensions.a / map.zoom + map.center.a + cursor.y.b = ((cursor.y.b/map.dimensions.b)-0.5) * map.dimensions.b / map.zoom - map.center.b + + if (base.resizing) { + var x_length = base.dragging.rect.x.length(), + y_length = base.dragging.rect.y.length() + + if (base.resizing & LEFT) { + base.dragging.rect.translation.a = clamp( cursor.x.magnitude(), x_length - side_max, x_length - side_min ) + } + if (base.resizing & RIGHT) { + base.dragging.rect.translation.a = clamp( cursor.x.magnitude(), side_min - x_length, side_max - x_length ) + } + if (base.resizing & FRONT) { + base.dragging.rect.translation.b = clamp( cursor.y.magnitude(), y_length - side_max, y_length - side_min ) + } + if (base.resizing & BACK) { + base.dragging.rect.translation.b = clamp( cursor.y.magnitude(), side_min - y_length, side_max - y_length ) + } + } + else if (base.dragging) { + base.dragging.rect.translation.a = cursor.x.magnitude() + base.dragging.rect.translation.b = cursor.y.magnitude() + } + } + + function up (e, cursor, new_cursor) { + new_cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) + new_cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) + + if (base.creating) { + if (cursor.height() > side_min && cursor.width() > side_min) { + cursor.x.abs().quantize(1) + cursor.y.abs().quantize(1) + Rooms.add_with_rect( cursor ) + } + } + + if (base.resizing) { + base.dragging.rect.resize() + } + else if (base.dragging) { + base.dragging.rect.translate() + } + + base.creating = base.dragging = base.resizing = false + } + + function mousewheel (e, val, delta){ + var cursor = base.mouse.cursor + + var intersects = Rooms.filter(function(r){ + return r.focused = r.rect.contains(cursor.x.a, cursor.y.a) + }) + + if (intersects.length) { + intersects[0].height = clamp( ~~(intersects[0].height - delta), height_min, height_max ) + Rooms.clipper.update() + } + else { + map.set_zoom(map.zoom_exponent - delta/20) + } + } + + function rightclick (e){ + } +} diff --git a/public/assets/javascripts/rectangles/engine/map/ui_minimap.js b/public/assets/javascripts/rectangles/engine/map/ui_minimap.js new file mode 100644 index 0000000..d8f39b0 --- /dev/null +++ b/public/assets/javascripts/rectangles/engine/map/ui_minimap.js @@ -0,0 +1,133 @@ + +Map.UI = Map.UI || {} + +Map.UI.Minimap = function(map){ + + var base = this + + base.creating = base.dragging = base.resizing = false + + base.mouse = new mouse({ + el: map.el, + down: down, + move: move, + drag: drag, + up: up, + rightclick: rightclick, + }) + + base.wheel = new wheel({ + el: map.el, + update: mousewheel, + }) + + // + + function down (e, cursor){ + cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) + cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) + + if (e.ctrlKey || e.which === 3) { + cursor.quantize(1/map.zoom) + map.center.a = cursor.x.a + map.center.b = -cursor.y.a + console.log(map.center+"") + cursor.x.b = cursor.x.a + cursor.y.b = cursor.y.a + base.mouse.down = false + e.preventDefault() + e.stopPropagation() + return + } + + var intersects = Rooms.filter(function(r){ + return r.focused = r.rect.contains(cursor.x.a, cursor.y.a) + }) + + if (intersects.length) { + base.dragging = intersects[0] + base.resizing = base.dragging.rect.nearEdge(cursor.x.a, cursor.y.a, resize_margin / map.zoom) + base.dragging.rect.translation.sides = base.resizing + } + else { + base.creating = true + } + + if (e.shiftKey && base.dragging) { + base.dragging.rect.quantize(10/map.zoom) + } + } + + function move (e, cursor) { + cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) + cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) + } + + function drag (e, cursor) { + cursor.x.b = ((cursor.x.b/map.dimensions.a)+0.5) * map.dimensions.a / map.zoom + map.center.a + cursor.y.b = ((cursor.y.b/map.dimensions.b)-0.5) * map.dimensions.b / map.zoom - map.center.b + + if (base.resizing) { + var x_length = base.dragging.rect.x.length(), + y_length = base.dragging.rect.y.length() + + if (base.resizing & LEFT) { + base.dragging.rect.translation.a = clamp( cursor.x.magnitude(), x_length - side_max, x_length - side_min ) + } + if (base.resizing & RIGHT) { + base.dragging.rect.translation.a = clamp( cursor.x.magnitude(), side_min - x_length, side_max - x_length ) + } + if (base.resizing & FRONT) { + base.dragging.rect.translation.b = clamp( cursor.y.magnitude(), y_length - side_max, y_length - side_min ) + } + if (base.resizing & BACK) { + base.dragging.rect.translation.b = clamp( cursor.y.magnitude(), side_min - y_length, side_max - y_length ) + } + } + else if (base.dragging) { + base.dragging.rect.translation.a = cursor.x.magnitude() + base.dragging.rect.translation.b = cursor.y.magnitude() + } + } + + function up (e, cursor, new_cursor) { + new_cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) + new_cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) + + if (base.creating) { + if (cursor.height() > side_min && cursor.width() > side_min) { + cursor.x.abs().quantize(1) + cursor.y.abs().quantize(1) + Rooms.add_with_rect( cursor ) + } + } + + if (base.resizing) { + base.dragging.rect.resize() + } + else if (base.dragging) { + base.dragging.rect.translate() + } + + base.creating = base.dragging = base.resizing = false + } + + function mousewheel (e, val, delta){ + var cursor = base.mouse.cursor + + var intersects = Rooms.filter(function(r){ + return r.focused = r.rect.contains(cursor.x.a, cursor.y.a) + }) + + if (intersects.length) { + intersects[0].height = clamp( ~~(intersects[0].height - delta), height_min, height_max ) + Rooms.clipper.update() + } + else { + map.set_zoom(map.zoom_exponent - delta/20) + } + } + + function rightclick (e){ + } +} diff --git a/public/assets/javascripts/ui/editor/EditorView.js b/public/assets/javascripts/ui/editor/EditorView.js index d4969c1..bcd4909 100644 --- a/public/assets/javascripts/ui/editor/EditorView.js +++ b/public/assets/javascripts/ui/editor/EditorView.js @@ -29,6 +29,15 @@ var EditorView = View.extend({ ready: function(data){ $("#map").hide() + + minimap = new Map ({ + type: "minimap", + el: document.querySelector("#minimap .el"), + width: 130, + height: 130, + zoom: -4 + }) + this.settings.load(data) }, @@ -37,6 +46,5 @@ var EditorView = View.extend({ this.ready(data) } - }) diff --git a/public/assets/stylesheets/app.css b/public/assets/stylesheets/app.css index cb56a68..684682c 100755 --- a/public/assets/stylesheets/app.css +++ b/public/assets/stylesheets/app.css @@ -978,7 +978,7 @@ h5 { left: 20px; color: black; cursor:pointer; - background:black; + background:white; -webkit-transform: translateY(0px); transform: translateY(0px); } diff --git a/views/editor.ejs b/views/editor.ejs index cd31b41..b3c1189 100755 --- a/views/editor.ejs +++ b/views/editor.ejs @@ -20,11 +20,9 @@ [[ include controls/editor/settings ]] - - - - - - - - - -
-- cgit v1.2.3-70-g09d2