summaryrefslogtreecommitdiff
path: root/public/assets/javascripts
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-08-27 18:00:57 -0400
committerJules Laplace <jules@okfoc.us>2015-08-27 18:00:57 -0400
commitebb9226fd5d37e8033e87e41b8ac0355d68f954c (patch)
tree8da5f8c450ab57379804a06000a24a875420f896 /public/assets/javascripts
parentf2b0b712d4a73bfaeb1ed21674b0843f0d6fa28a (diff)
staff area for blueprints
Diffstat (limited to 'public/assets/javascripts')
-rw-r--r--public/assets/javascripts/rectangles/engine/shapes/regionlist.js64
-rw-r--r--public/assets/javascripts/rectangles/engine/shapes/shapelist.js3
-rw-r--r--public/assets/javascripts/ui/blueprint/BlueprintEditor.js8
-rw-r--r--public/assets/javascripts/ui/blueprint/BlueprintInfo.js23
4 files changed, 75 insertions, 23 deletions
diff --git a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js
index 86269a6..0dd4a1e 100644
--- a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js
+++ b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js
@@ -10,10 +10,25 @@ var RegionList = (function(){
var RegionList = {}
var regions = RegionList.regions
+ // Build a list of regions from the existing shapes.
+ // Operates on all the shapes at once.
RegionList.build = function(){
-
- // first, get the segments sorted right to left & top to bottom
var segments = RegionList.getSortedSegments()
+ return RegionList.buildRoomsFromSegments(segments)
+ }
+
+ // Build a list of regions from the individual shapes.
+ // Same, but operates on the shapes individually
+ RegionList.buildByShape = function(){
+ var shapes = RegionList.getSortedSegmentsByShape()
+ var region_lists = shapes.map(function(shape){
+ return RegionList.buildRoomsFromSegments(shape.segments)
+ })
+ var regions = []
+ return regions.concat.apply(regions, region_lists);
+ }
+
+ RegionList.buildRoomsFromSegments = function(segments){
var rooms = []
var seen_rooms = {}
@@ -172,31 +187,42 @@ var RegionList = (function(){
return rooms
}
-
// Gets a list of polylines from the ShapeList and sorts the segments.
RegionList.getSortedSegments = function(){
// get a list of all segments from these polylines
var segments = shapes.getAllSegments()
- // re-orient them so they're either facing up or right and make them into rects
- segments = segments.map(function(segment){
- // vertical
- if (segment[0].a == segment[1].a) {
- if (segment[0].b > segment[1].b) {
- segment.push(segment.shift())
- }
- }
- // horizontal
- else if (segment[0].b == segment[1].b) {
- if (segment[0].a > segment[1].a) {
- segment.push(segment.shift())
- }
- }
- return new Rect( segment[0].a, segment[0].b, segment[1].a, segment[1].b )
- })
+ segments = segments.map(RegionList.segmentsToRects)
return sort.rects_by_position(segments)
}
+
+ RegionList.getSortedSegmentsByShape = function(){
+ return shapes.getAllShapeSegments().map(function(shape){
+ var segments = shape.map(RegionList.segmentsToRects)
+ return {
+ shape: shape,
+ segments: sort.rects_by_position(segments)
+ }
+ })
+ }
+
+ // re-orient a segment so it's either facing up or right and make it into a rect
+ RegionList.segmentsToRects = function(segment){
+ // vertical
+ if (segment[0].a == segment[1].a) {
+ if (segment[0].b > segment[1].b) {
+ segment.push(segment.shift())
+ }
+ }
+ // horizontal
+ else if (segment[0].b == segment[1].b) {
+ if (segment[0].a > segment[1].a) {
+ segment.push(segment.shift())
+ }
+ }
+ return new Rect( segment[0].a, segment[0].b, segment[1].a, segment[1].b )
+ }
return RegionList
diff --git a/public/assets/javascripts/rectangles/engine/shapes/shapelist.js b/public/assets/javascripts/rectangles/engine/shapes/shapelist.js
index e5a70fb..2d33af2 100644
--- a/public/assets/javascripts/rectangles/engine/shapes/shapelist.js
+++ b/public/assets/javascripts/rectangles/engine/shapes/shapelist.js
@@ -69,6 +69,9 @@ var ShapeList = Fiber.extend(function(base){
exports.forEach = function(fn){
this.shapes.forEach(fn)
}
+ exports.getAllShapeSegments = function(){
+ return this.shapes.map(function(shape){ return shape.getSegments() })
+ }
exports.getAllSegments = function(){
var segments = []
this.shapes.forEach(function(shape){
diff --git a/public/assets/javascripts/ui/blueprint/BlueprintEditor.js b/public/assets/javascripts/ui/blueprint/BlueprintEditor.js
index 7a1c064..7704689 100644
--- a/public/assets/javascripts/ui/blueprint/BlueprintEditor.js
+++ b/public/assets/javascripts/ui/blueprint/BlueprintEditor.js
@@ -82,7 +82,7 @@ var BlueprintEditor = View.extend(AnimatedView.prototype).extend({
scale: media.scale,
})
this.startAnimating()
- this.regions = RegionList.build()
+ this.regions = RegionList.buildByShape()
},
animate: function(t, dt){
@@ -114,9 +114,9 @@ var BlueprintEditor = View.extend(AnimatedView.prototype).extend({
map.draw.camera(scene.camera)
// var colors = ["rgba(0,0,0,0.1)"]
-// var colors = ["rgba(255,255,255,1)"]
-//
-// map.draw.regions(this.regions, colors, "#000")
+// var colors = ["rgba(255,255,255,1)"]
+
+// map.draw.regions(this.regions, colors, "#000")
// this.regions.forEach(function(room,i){
// map.draw.ctx.fillStyle = colors[i % colors.length]
diff --git a/public/assets/javascripts/ui/blueprint/BlueprintInfo.js b/public/assets/javascripts/ui/blueprint/BlueprintInfo.js
index 6dd6a7d..51b310e 100644
--- a/public/assets/javascripts/ui/blueprint/BlueprintInfo.js
+++ b/public/assets/javascripts/ui/blueprint/BlueprintInfo.js
@@ -10,6 +10,7 @@ var BlueprintInfo = View.extend({
"change [name=units]": 'changeUnits',
"keydown [name=viewHeight]": 'enterViewHeight',
"change [name=viewHeight]": 'changeViewHeight',
+ "click .openScaler": 'openScaler',
},
initialize: function(opt){
@@ -18,13 +19,30 @@ var BlueprintInfo = View.extend({
this.$units = this.$("[name=units]")
this.$viewHeight = this.$("[name=viewHeight]")
this.$unitName = this.$(".unitName")
+ this.$blueprintScaleDisplay = this.$("#blueprintScaleDisplay")
},
load: function(data){
this.$viewHeight.unitVal( window.viewHeight = data.viewHeight || app.defaults.viewHeight )
this.$height.unitVal( window.wallHeight = data.wallHeight || app.defaults.wallHeight )
this.$units.val( data.units )
+ this.$('span.units').html( data.units )
this.$unitName.html( data.units )
+
+ var resolution
+ switch (data.units) {
+ case 'ft':
+ resolution = app.defaults.footResolution
+ break
+ case 'm':
+ resolution = app.defaults.meterResolution
+ break
+ case 'px':
+ default:
+ resolution = 1
+ break
+ }
+ this.$blueprintScaleDisplay.html( ((1/data.scale) * resolution).toFixed(1) )
this.show()
},
@@ -33,6 +51,11 @@ var BlueprintInfo = View.extend({
this.$viewHeight.unitVal( window.viewHeight )
},
+ openScaler: function(){
+ this.parent.scaler.pick( this.parent.data, true )
+ this.parent.scaler.show()
+ },
+
show: function(){
this.toggle(true)
},