summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-08-27 11:57:51 -0400
committerJules Laplace <jules@okfoc.us>2015-08-27 12:09:21 -0400
commit685d5fd7b32ac868a0b2d8ac8a2a1b4120f274cf (patch)
tree890537207a09374d4e2f2753f68407360d570c1a
parentc29a5363e3e4e0833e78958fe95b52811d0b0660 (diff)
fork orthopolyline
-rw-r--r--public/assets/javascripts/rectangles/engine/map/tools/ortho.js2
-rw-r--r--public/assets/javascripts/rectangles/engine/shapes/ortho.js41
-rw-r--r--public/assets/javascripts/rectangles/engine/shapes/polyline.js21
-rw-r--r--public/assets/javascripts/rectangles/engine/shapes/shapelist.js14
-rw-r--r--public/assets/javascripts/ui/blueprint/BlueprintSettings.js3
-rw-r--r--public/assets/javascripts/ui/blueprint/BlueprintUploader.js2
-rw-r--r--public/assets/javascripts/ui/blueprint/BlueprintView.js22
-rwxr-xr-xpublic/assets/stylesheets/app.css4
-rw-r--r--views/partials/header.ejs2
-rw-r--r--views/partials/scripts.ejs1
-rw-r--r--views/profile.ejs2
11 files changed, 99 insertions, 15 deletions
diff --git a/public/assets/javascripts/rectangles/engine/map/tools/ortho.js b/public/assets/javascripts/rectangles/engine/map/tools/ortho.js
index 6ced728..374c822 100644
--- a/public/assets/javascripts/rectangles/engine/map/tools/ortho.js
+++ b/public/assets/javascripts/rectangles/engine/map/tools/ortho.js
@@ -48,7 +48,7 @@ var OrthoPolylineTool = MapTool.extend(function (base) {
}
else {
map.ui.placing = true
- shapes.workline = new Polyline ()
+ shapes.workline = new OrthoPolyline ()
shapes.workline.add(p)
first_point = prev_point = p
horizontal = false
diff --git a/public/assets/javascripts/rectangles/engine/shapes/ortho.js b/public/assets/javascripts/rectangles/engine/shapes/ortho.js
new file mode 100644
index 0000000..8a8f928
--- /dev/null
+++ b/public/assets/javascripts/rectangles/engine/shapes/ortho.js
@@ -0,0 +1,41 @@
+// An OrthoPolyline is a Polyline where all angles are 90 degrees.
+
+var OrthoPolyline = Polyline.extend(function(base){
+ var exports = {}
+ exports.type = function(){
+ return "ortho"
+ }
+ exports.instantiate = function(){
+ return new OrthoPolyline
+ }
+ exports.canCloseWith = function(p){
+ return (this.points.length > 2 && this.points[0].distanceTo( p ) < 10/map.zoom)
+ }
+ exports.draw = function(ctx, fillStyle, strokeStyle){
+ var points = this.points
+ if (! points.length) return
+ if (points.length == 1) {
+ ctx.fillStyle = "#f80"
+ map.draw.dot_at(this.points[0].a, points[0].b, 5)
+ }
+ if (points.length > 1) {
+ ctx.fillStyle = fillStyle
+ ctx.strokeStyle = strokeStyle
+ ctx.lineWidth = 2 / map.zoom
+ ctx.beginPath()
+ ctx.moveTo(points[0].a, points[0].b)
+ points.forEach(function(point, i){
+ i && ctx.lineTo(point.a, point.b)
+ })
+ strokeStyle && ctx.stroke()
+ if (! map.ui.placing || this.closed) {
+ fillStyle && ctx.fill()
+ }
+ }
+ }
+ exports.close = function(){
+ this.points[this.points.length] = this.points[0]
+ this.closed = true
+ }
+ return exports
+})
diff --git a/public/assets/javascripts/rectangles/engine/shapes/polyline.js b/public/assets/javascripts/rectangles/engine/shapes/polyline.js
index fc6cad7..65e22ad 100644
--- a/public/assets/javascripts/rectangles/engine/shapes/polyline.js
+++ b/public/assets/javascripts/rectangles/engine/shapes/polyline.js
@@ -9,6 +9,12 @@ var Polyline = Fiber.extend(function(base){
this.mx_points = []
this.closed = false
}
+ exports.type = function(){
+ return "polyline"
+ }
+ exports.instantiate = function(){
+ return new Polyline
+ }
exports.add = function(p){
this.points.push( p )
this.mx_points.push( new MX.Point(p) )
@@ -25,19 +31,19 @@ var Polyline = Fiber.extend(function(base){
exports.getHeadAtIndex = function(index){
if (index == 0) { return null }
if (index == this.points.length-1) { return this.clone() }
- var head = new Polyline()
+ var head = this.instantiate()
head.points = this.points.slice(0, index+1)
return head
}
exports.getTailAtIndex = function(index){
if (index == this.points.length-1) { return null }
if (index == 0) { return this.clone() }
- var tail = new Polyline()
+ var tail = this.instantiate()
tail.points = this.points.slice(index, this.points.length)
return tail
}
exports.clone = function(){
- var clone = new Polyline()
+ var clone = this.instantiate()
clone.points = this.points.concat()
}
exports.hasPointNear = function(p){
@@ -148,10 +154,13 @@ var Polyline = Fiber.extend(function(base){
return segments
}
exports.serialize = function(){
- return this.points.map(function(point){ return [point.a, point.b] })
+ return {
+ type: this.type(),
+ points: this.points.map(function(point){ return [point.a, point.b] }),
+ }
}
- exports.deserialize = function(points){
- this.points = points.map(function(point){ return new vec2(point[0], point[1]) })
+ exports.deserialize = function(data){
+ this.points = (data.points || data).map(function(point){ return new vec2(point[0], point[1]) })
}
exports.reset = function(){
this.mx_points.forEach(function(mx){ scene.remove(mx) })
diff --git a/public/assets/javascripts/rectangles/engine/shapes/shapelist.js b/public/assets/javascripts/rectangles/engine/shapes/shapelist.js
index 75ecae6..e5a70fb 100644
--- a/public/assets/javascripts/rectangles/engine/shapes/shapelist.js
+++ b/public/assets/javascripts/rectangles/engine/shapes/shapelist.js
@@ -87,9 +87,17 @@ var ShapeList = Fiber.extend(function(base){
})
}
exports.deserialize = function(data){
- data && data.forEach(function(points){
- var line = new Polyline()
- line.deserialize(points)
+ data && data.forEach(function(shape_data){
+ var line
+ switch (shape_data.type) {
+ case 'ortho':
+ line = new OrthoPolyline()
+ break
+ default:
+ line = new Polyline()
+ break
+ }
+ line.deserialize(shape_data)
shapes.add(line)
}.bind(this))
}
diff --git a/public/assets/javascripts/ui/blueprint/BlueprintSettings.js b/public/assets/javascripts/ui/blueprint/BlueprintSettings.js
index 80c9355..8addb9c 100644
--- a/public/assets/javascripts/ui/blueprint/BlueprintSettings.js
+++ b/public/assets/javascripts/ui/blueprint/BlueprintSettings.js
@@ -93,10 +93,9 @@ var BlueprintSettings = FormView.extend(ToggleableView.prototype).extend({
fd.append( "_id", this.$id.val() )
fd.append( "name", this.$name.val() )
fd.append( "shapes", JSON.stringify( shapes.serialize() ) )
- fd.append( "startPosition", JSON.stringify( this.parent.startPosition ) )
+ fd.append( "startPosition", JSON.stringify( this.parent.quantizeStartPosition() ) )
fd.append( "wallHeight", this.parent.info.$height.unitVal() )
fd.append( "units", this.parent.info.$units.val() )
-
return fd
},
diff --git a/public/assets/javascripts/ui/blueprint/BlueprintUploader.js b/public/assets/javascripts/ui/blueprint/BlueprintUploader.js
index fe1073a..dc3c281 100644
--- a/public/assets/javascripts/ui/blueprint/BlueprintUploader.js
+++ b/public/assets/javascripts/ui/blueprint/BlueprintUploader.js
@@ -65,7 +65,7 @@ var BlueprintUploader = UploadView.extend({
var $el = $(e.currentTarget)
var media = $el.data("media")
this.hide()
- this.parent.scaler.pick(media, true)
+ this.parent.scaler.pick(media)
},
destroy: function(e){
diff --git a/public/assets/javascripts/ui/blueprint/BlueprintView.js b/public/assets/javascripts/ui/blueprint/BlueprintView.js
index ecbb536..19b9e84 100644
--- a/public/assets/javascripts/ui/blueprint/BlueprintView.js
+++ b/public/assets/javascripts/ui/blueprint/BlueprintView.js
@@ -29,6 +29,28 @@ var BlueprintView = View.extend({
orbiting: true,
startPosition: {},
+ quantizeStartPosition: function(){
+ //
+ var regions = RegionList.build()
+ var pos = this.startPosition
+ var startPositionIsInARoom = regions.some(function(region){
+ return region.contains(pos.x, pos.z)
+ })
+ if (startPositionIsInARoom) {
+ return this.startPosition
+ }
+ else {
+ var center = regions[0].center()
+ return {
+ x: center.a,
+ y: viewHeight,
+ z: center.b,
+ rotationX: 0,
+ rotationY: Math.PI/2,
+ }
+ }
+ },
+
buildMap: function(){
// i forget if this has to be global
map = new Map ({
diff --git a/public/assets/stylesheets/app.css b/public/assets/stylesheets/app.css
index 634ea60..e4f1b27 100755
--- a/public/assets/stylesheets/app.css
+++ b/public/assets/stylesheets/app.css
@@ -1156,6 +1156,7 @@ form .paidPlan label { float: none; font-size: 16px; margin: 0 10px; }
width: 100%;
height: 100%;
padding: 20px 0 40px 0;
+ text-align: center;
}
.templates-list,
.userTemplatesList,
@@ -1186,8 +1187,7 @@ form .paidPlan label { float: none; font-size: 16px; margin: 0 10px; }
}
.templates span {
- display: block;
- float: left;
+ display: inline-block;
margin: 1vw 0;
width:20%;
padding: 2vw;
diff --git a/views/partials/header.ejs b/views/partials/header.ejs
index bb8fc6e..ce9ffae 100644
--- a/views/partials/header.ejs
+++ b/views/partials/header.ejs
@@ -64,7 +64,9 @@
[[ if (profile && String(user._id) == String(profile._id)) { ]]
<a href="/profile" data-role="edit-profile-modal" class="topLink editProfile">Settings</a>
+<!--
<a href="/profile" data-role="edit-subscription-modal" class="topLink editSubscription">Subscription</a>
+ -->
[[ } else if (! profile) { ]]
<a href="/profile" class="topLink profileLink">Profile</a>
[[ } ]]
diff --git a/views/partials/scripts.ejs b/views/partials/scripts.ejs
index bac4120..da3f0ba 100644
--- a/views/partials/scripts.ejs
+++ b/views/partials/scripts.ejs
@@ -86,6 +86,7 @@
<script type="text/javascript" src="/assets/javascripts/rectangles/engine/sculpture/types/image.js"></script>
<script type="text/javascript" src="/assets/javascripts/rectangles/engine/shapes/polyline.js"></script>
+<script type="text/javascript" src="/assets/javascripts/rectangles/engine/shapes/ortho.js"></script>
<script type="text/javascript" src="/assets/javascripts/rectangles/engine/shapes/shapelist.js"></script>
<script type="text/javascript" src="/assets/javascripts/rectangles/engine/shapes/regionlist.js"></script>
diff --git a/views/profile.ejs b/views/profile.ejs
index 63a07f5..d3ae10e 100644
--- a/views/profile.ejs
+++ b/views/profile.ejs
@@ -78,7 +78,9 @@
[[ } ]]
</div>
+<!--
[[ include partials/edit-subscription ]]
+ -->
[[ include partials/edit-profile ]]
[[ include projects/layouts-modal ]]
[[ include projects/edit-project ]]