From f68450b1c3ece018009df5542b7e73b2b74852e7 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 3 Apr 2015 20:39:44 -0400 Subject: sculpture on reader --- public/assets/javascripts/ui/reader/ReaderView.js | 1 + 1 file changed, 1 insertion(+) (limited to 'public/assets/javascripts/ui/reader/ReaderView.js') diff --git a/public/assets/javascripts/ui/reader/ReaderView.js b/public/assets/javascripts/ui/reader/ReaderView.js index 617a145..e3e27c3 100644 --- a/public/assets/javascripts/ui/reader/ReaderView.js +++ b/public/assets/javascripts/ui/reader/ReaderView.js @@ -74,6 +74,7 @@ var ReaderView = View.extend({ data.rooms && Rooms.deserialize(data.rooms) data.walls && Walls.deserialize(data.walls) data.media && Scenery.deserialize(data.media) + data.sculpture && Sculpture.deserialize(data.sculpture) data.startPosition && scene.camera.move(data.startPosition) cam.y = window.viewHeight = data.viewHeight || app.defaults.viewHeight -- cgit v1.2.3-70-g09d2 From 7fd34f49fea785f11320eec412a95726cbcf7349 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 20 Apr 2015 17:59:51 -0400 Subject: static build target --- .gitignore | 3 + Gruntfile.js | 130 +++++++++++++- public/assets/javascripts/ui/reader/MediaPlayer.js | 2 +- public/assets/javascripts/ui/reader/ReaderView.js | 12 +- public/assets/javascripts/ui/reader/_router.js | 16 ++ public/assets/test/static.html | 196 +++++++++++++++++++++ server/index.js | 4 + 7 files changed, 354 insertions(+), 9 deletions(-) create mode 100644 public/assets/javascripts/ui/reader/_router.js create mode 100644 public/assets/test/static.html (limited to 'public/assets/javascripts/ui/reader/ReaderView.js') diff --git a/.gitignore b/.gitignore index 50f54f1..14d6d0f 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,6 @@ config.json app.concat.js app.min.js +reader.concat.js +reader.min.js + diff --git a/Gruntfile.js b/Gruntfile.js index 93f13fe..a3ef359 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -147,7 +147,110 @@ module.exports = function(grunt) { "public/assets/javascripts/defaults.js", ], dest: 'public/assets/javascripts/app.concat.js', + }, + + // this builds a static version of the vvalls code, suitable for embedding + // in another website. see assets/test/static.html + 'static': { + src: [ + "public/assets/javascripts/vendor/bower_components/jquery/dist/jquery.min.js", + "public/assets/javascripts/vendor/bower_components/lodash/lodash.min.js", + "public/assets/javascripts/vendor/bower_components/momentjs/min/moment.min.js", + "public/assets/javascripts/vendor/bower_components/fiber/src/fiber.min.js", + "public/assets/javascripts/vendor/bower_components/marked/lib/marked.js", + "public/assets/javascripts/vendor/bower_components/hidpi-canvas/dist/hidpi-canvas.js", + "public/assets/javascripts/vendor/tube.js", + "public/assets/javascripts/vendor/loader.js", + "public/assets/javascripts/vendor/polyfill.js", + "public/assets/javascripts/vendor/froogaloop.js", + "public/assets/javascripts/util.js", + + "public/assets/javascripts/mx/mx.js", + "public/assets/javascripts/mx/extensions/mx.scene.js", + "public/assets/javascripts/mx/extensions/mx.movements.js", + "public/assets/javascripts/mx/extensions/mx.movementsMobile.js", + "public/assets/javascripts/mx/primitives/mx.image.js", + "public/assets/javascripts/mx/primitives/mx.text.js", + "public/assets/javascripts/mx/primitives/mx.video.js", + "public/assets/javascripts/mx/primitives/mx.youtube.js", + "public/assets/javascripts/mx/primitives/mx.vimeo.js", + "public/assets/javascripts/mx/primitives/mx.soundcloud.js", + "public/assets/javascripts/mx/primitives/mx.grid.js", + + "public/assets/javascripts/rectangles/_env.js", + + "public/assets/javascripts/rectangles/util/constants.js", + "public/assets/javascripts/rectangles/util/colors.js", + "public/assets/javascripts/rectangles/util/coords.js", + "public/assets/javascripts/rectangles/util/debug.js", + "public/assets/javascripts/rectangles/util/keys.js", + "public/assets/javascripts/rectangles/util/measurement.js", + "public/assets/javascripts/rectangles/util/minotaur.js", + "public/assets/javascripts/rectangles/util/mouse.js", + "public/assets/javascripts/rectangles/util/permissions.js", + "public/assets/javascripts/rectangles/util/sort.js", + "public/assets/javascripts/rectangles/util/uid.js", + "public/assets/javascripts/rectangles/util/undostack.js", + "public/assets/javascripts/rectangles/util/wheel.js", + + "public/assets/javascripts/rectangles/models/vec2.js", + "public/assets/javascripts/rectangles/models/vec3.js", + "public/assets/javascripts/rectangles/models/rect.js", + "public/assets/javascripts/rectangles/models/surface.js", + "public/assets/javascripts/rectangles/models/tree.js", + "public/assets/javascripts/rectangles/models/room.js", + "public/assets/javascripts/rectangles/models/wall.js", + "public/assets/javascripts/rectangles/models/floor.js", + + "public/assets/javascripts/rectangles/engine/rooms/_rooms.js", + "public/assets/javascripts/rectangles/engine/rooms/_walls.js", + "public/assets/javascripts/rectangles/engine/rooms/builder.js", + "public/assets/javascripts/rectangles/engine/rooms/clipper.js", + "public/assets/javascripts/rectangles/engine/rooms/grouper.js", + "public/assets/javascripts/rectangles/engine/rooms/mover.js", + + "public/assets/javascripts/rectangles/engine/scenery/_scenery.js", + "public/assets/javascripts/rectangles/engine/scenery/move.js", + "public/assets/javascripts/rectangles/engine/scenery/resize.js", + "public/assets/javascripts/rectangles/engine/scenery/randomize.js", + "public/assets/javascripts/rectangles/engine/scenery/sound.js", + "public/assets/javascripts/rectangles/engine/scenery/undo.js", + "public/assets/javascripts/rectangles/engine/scenery/types/_object.js", + "public/assets/javascripts/rectangles/engine/scenery/types/image.js", + "public/assets/javascripts/rectangles/engine/scenery/types/text.js", + "public/assets/javascripts/rectangles/engine/scenery/types/video.js", + "public/assets/javascripts/rectangles/engine/scenery/types/audio.js", + + "public/assets/javascripts/rectangles/engine/sculpture/_sculpture.js", + "public/assets/javascripts/rectangles/engine/sculpture/move.js", + "public/assets/javascripts/rectangles/engine/sculpture/resize.js", + "public/assets/javascripts/rectangles/engine/sculpture/types/_object.js", + "public/assets/javascripts/rectangles/engine/sculpture/types/image.js", + + "public/assets/javascripts/rectangles/engine/map/_map.js", + "public/assets/javascripts/rectangles/engine/map/ui_editor.js", + "public/assets/javascripts/rectangles/engine/map/ui_minimap.js", + "public/assets/javascripts/rectangles/engine/map/draw.js", + + "public/assets/javascripts/ui/lib/View.js", + "public/assets/javascripts/ui/lib/Router.js", + "public/assets/javascripts/ui/lib/ModalView.js", + + "public/assets/javascripts/ui/reader/ReaderView.js", + "public/assets/javascripts/ui/reader/ShareView.js", + "public/assets/javascripts/ui/reader/EmbedView.js", + "public/assets/javascripts/ui/reader/MediaPlayer.js", + "public/assets/javascripts/ui/reader/Tracker.js", + + "public/assets/javascripts/ui/reader/_router.js", + + "public/assets/javascripts/app.js", + "public/assets/javascripts/defaults.js", + ], + dest: 'public/assets/javascripts/reader.concat.js', } + + }, copy: { concat: { @@ -158,7 +261,15 @@ module.exports = function(grunt) { }, ] }, - }, + 'static': { + files: [ + { + src: 'public/assets/javascripts/static.concat.js', + dest: 'public/assets/javascripts/static.min.js', + }, + ] + }, + }, uglify: { options: { banner: '/* vvalls by okfocus 2015 */\n' @@ -166,10 +277,17 @@ module.exports = function(grunt) { js: { src: 'public/assets/javascripts/app.concat.js', dest: 'public/assets/javascripts/app.min.js', + }, + 'static': { + src: 'public/assets/javascripts/static.concat.js', + dest: 'public/assets/javascripts/static.min.js', } }, clean: { - release: ["public/assets/javascripts/app.concat.js"], + release: [ + "public/assets/javascripts/static.concat.js", + "public/assets/javascripts/app.concat.js", + ], } }); @@ -180,8 +298,10 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-clean'); // Default task(s). - grunt.registerTask('js', ['concat:js', 'uglify:js', 'clean:release']); - grunt.registerTask('merge', ['concat:js', 'copy:concat']); - grunt.registerTask('default', ['js']); + grunt.registerTask('js', ['concat:js', 'uglify:js', 'clean:release']); + grunt.registerTask('js-test', ['concat:js', 'copy:concat']); + grunt.registerTask('static', ['concat:static', 'uglify:static', 'clean:release']); + grunt.registerTask('static-test', ['concat:static', 'copy:static']); + grunt.registerTask('default', ['js']); }; diff --git a/public/assets/javascripts/ui/reader/MediaPlayer.js b/public/assets/javascripts/ui/reader/MediaPlayer.js index 8424d9c..8e65976 100644 --- a/public/assets/javascripts/ui/reader/MediaPlayer.js +++ b/public/assets/javascripts/ui/reader/MediaPlayer.js @@ -1,5 +1,5 @@ -var MediaPlayer = FormView.extend({ +var MediaPlayer = View.extend({ el: "#mediaPlayer", events: { diff --git a/public/assets/javascripts/ui/reader/ReaderView.js b/public/assets/javascripts/ui/reader/ReaderView.js index e3e27c3..55d2520 100644 --- a/public/assets/javascripts/ui/reader/ReaderView.js +++ b/public/assets/javascripts/ui/reader/ReaderView.js @@ -31,7 +31,12 @@ var ReaderView = View.extend({ this.tracker = new Tracker ({ mode: mode }) - $.get(this.projectAction + name, this.ready.bind(this)) + if ('vvalls_data' in window) { + this.ready(window.vvalls_data) + } + else { + $.get(this.projectAction + name, this.ready.bind(this)) + } }, getQS: function(){ @@ -85,9 +90,10 @@ var ReaderView = View.extend({ Walls.setColor[mode](colors[mode]) }) - editor.permissions.clear() + window.editor && editor.permissions.clear() - this.listen() + // disable until we start using spinning again + // this.listen() }, listen: function(){ diff --git a/public/assets/javascripts/ui/reader/_router.js b/public/assets/javascripts/ui/reader/_router.js new file mode 100644 index 0000000..a0e346a --- /dev/null +++ b/public/assets/javascripts/ui/reader/_router.js @@ -0,0 +1,16 @@ + +var SiteRouter = Router.extend({ + el: "body", + + initialize: function(){ + app.launch() + if (app.unsupported) return + + this.readerView = app.controller = new ReaderView() + this.readerView.load() + + $("body").removeClass("loading") + } + +}) + diff --git a/public/assets/test/static.html b/public/assets/test/static.html new file mode 100644 index 0000000..90871a5 --- /dev/null +++ b/public/assets/test/static.html @@ -0,0 +1,196 @@ + + + + VValls + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + +
+
+

+ Leaves and such +
+ +
+ + asdf +

+ + + Last modified 4/20/2015 + + + + + Edit Room + +
+ +
+ + + + + + + + + + + + + +
+
+
+ +
+ +
+ X + +
+
+
+

Embed VValls

+ +

+ This code generates an iframe which will embed this room in your website or blog. +

+ + + dimensions: x + + + + test +
+
+
+
+ +
+ +
+ +
+
+ + + + + + + + + + diff --git a/server/index.js b/server/index.js index 7bc3f7f..391385c 100644 --- a/server/index.js +++ b/server/index.js @@ -66,6 +66,10 @@ site.setup = function(){ app.set('env', config.env.production ? "production" : "development") app.get('env') === 'development' && app.use(express.errorHandler()); + if (config.env.production) { + app.set('json spaces', 0) + } + // Essential middleware // app.all('*', middleware.enableCORS); app.all('*', middleware.ensureLocals); -- cgit v1.2.3-70-g09d2 From 94ba321f96638906e41eda7abf371066011c8508 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 29 Apr 2015 18:46:21 -0400 Subject: misc edits --- public/assets/javascripts/mx/extensions/mx.movements.js | 2 +- public/assets/javascripts/mx/primitives/mx.video.js | 3 +++ public/assets/javascripts/mx/primitives/mx.vimeo.js | 16 ++++++++++++---- public/assets/javascripts/mx/primitives/mx.youtube.js | 3 +++ .../javascripts/rectangles/engine/scenery/_scenery.js | 17 +++++++++++++++-- .../javascripts/rectangles/engine/scenery/sound.js | 2 +- .../rectangles/engine/scenery/types/video.js | 7 ++++++- public/assets/javascripts/ui/reader/ReaderView.js | 2 ++ 8 files changed, 43 insertions(+), 9 deletions(-) (limited to 'public/assets/javascripts/ui/reader/ReaderView.js') diff --git a/public/assets/javascripts/mx/extensions/mx.movements.js b/public/assets/javascripts/mx/extensions/mx.movements.js index 931caac..fa59908 100644 --- a/public/assets/javascripts/mx/extensions/mx.movements.js +++ b/public/assets/javascripts/mx/extensions/mx.movements.js @@ -20,7 +20,7 @@ MX.Movements = function (cam) { rotationX_max = PI/6 var v = 12, - vr = Math.PI * 0.012, + vr = Math.PI * 0.018, jumpV = 23, vx = vy = vz = 0, creepFactor = 0.3 diff --git a/public/assets/javascripts/mx/primitives/mx.video.js b/public/assets/javascripts/mx/primitives/mx.video.js index 43c392a..53ccf2e 100644 --- a/public/assets/javascripts/mx/primitives/mx.video.js +++ b/public/assets/javascripts/mx/primitives/mx.video.js @@ -21,6 +21,7 @@ MX.Video = MX.Object3D.extend({ this.el.classList.add("video") this.el.classList.add("mx-scenery") this.paused = !! this.media.autoplay + this.playing = false this.muted = app.muted || !! this.media.mute }, @@ -60,11 +61,13 @@ MX.Video = MX.Object3D.extend({ play: function(){ this.paused = false + this.playing = true this.player.play() }, pause: function(){ this.paused = true + this.playing = false this.player.pause() }, diff --git a/public/assets/javascripts/mx/primitives/mx.vimeo.js b/public/assets/javascripts/mx/primitives/mx.vimeo.js index e1a3b84..af138ae 100644 --- a/public/assets/javascripts/mx/primitives/mx.vimeo.js +++ b/public/assets/javascripts/mx/primitives/mx.vimeo.js @@ -20,6 +20,7 @@ MX.Vimeo = MX.Object3D.extend({ this.backface && this.el.classList.add("backface-visible") this.el.classList.add("video") this.el.classList.add("mx-scenery") + this.playing = false this.paused = !! this.media.autoplay this.muted = app.muted || !! this.media.mute this.started = false @@ -145,19 +146,26 @@ MX.Vimeo = MX.Object3D.extend({ if (this.paused) { this.pause() } + else { + this.playing = true + } }, onPause: function(){ if (! this.paused) { this.play() } + else { + this.playing = false + } }, finished: function(){ -// if (this.media.loop) { -// this.seek(0) -// this.play() -// } + console.log("vimeo finished") + if (this.media.loop) { + this.seek(0) + this.play() + } // else if (this.bound) { if (! this.media.loop && this.bound) { $(".playButton").removeClass('playing') diff --git a/public/assets/javascripts/mx/primitives/mx.youtube.js b/public/assets/javascripts/mx/primitives/mx.youtube.js index e4e73d6..8cd9f59 100644 --- a/public/assets/javascripts/mx/primitives/mx.youtube.js +++ b/public/assets/javascripts/mx/primitives/mx.youtube.js @@ -21,6 +21,7 @@ MX.Youtube = MX.Object3D.extend({ this.el.classList.add("video") this.el.classList.add("mx-scenery") this.paused = !! this.media.autoplay + this.playing = false this.muted = app.muted || !! this.media.mute }, @@ -143,11 +144,13 @@ MX.Youtube = MX.Object3D.extend({ play: function(){ this.paused = false + this.playing = true this.player.playVideo() }, pause: function(){ this.paused = true + this.playing = false this.player.pauseVideo() }, diff --git a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js index e9be663..6203c20 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js +++ b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js @@ -121,7 +121,10 @@ var Scenery = new function(){ } base.playAll = function(){ base.forEach(function(scenery){ - if (scenery.type == "video") scenery.play() + if (scenery.type == "video") { + scenery.unmute() + scenery.play() + } }) } base.pauseAll = function(){ @@ -129,7 +132,17 @@ var Scenery = new function(){ if (scenery.type == "video") scenery.pause() }) } - + base.muteAll = function(){ + base.forEach(function(scenery){ + if (scenery.type == "video") scenery.mx.mute() + }) + } + base.unmuteAll = function(){ + base.forEach(function(scenery){ + if (scenery.type == "video") scenery.mx.unmute() + }) + } + return base } diff --git a/public/assets/javascripts/rectangles/engine/scenery/sound.js b/public/assets/javascripts/rectangles/engine/scenery/sound.js index 37bdee0..d63d8c4 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/sound.js +++ b/public/assets/javascripts/rectangles/engine/scenery/sound.js @@ -5,7 +5,7 @@ Scenery.sound.init = function(){ app.tube.on("move", Scenery.sound.move) } Scenery.sound.move = function(){ - var vals = Scenery.map(function(scenery){ + Scenery.forEach(function(scenery){ if ((scenery.type == "video" || scenery.type == "audio") && ! scenery.muted()) { var distance = dist(cam.x, cam.z, scenery.mx.x, scenery.mx.z) diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/video.js b/public/assets/javascripts/rectangles/engine/scenery/types/video.js index fb1a868..163e19e 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/video.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/video.js @@ -38,7 +38,8 @@ Scenery.types.video = Scenery.types.base.extend(function(base){ backface: false, }) scene.add(this.mx) - this.mx.load() + + this.mx.load() }, play: function(){ @@ -90,6 +91,10 @@ Scenery.types.video = Scenery.types.base.extend(function(base){ } }, + unmute: function(){ + this.mx.unmute() + }, + setVolume: function(n){ this.mx.setVolume(n) }, diff --git a/public/assets/javascripts/ui/reader/ReaderView.js b/public/assets/javascripts/ui/reader/ReaderView.js index 55d2520..1ba97cf 100644 --- a/public/assets/javascripts/ui/reader/ReaderView.js +++ b/public/assets/javascripts/ui/reader/ReaderView.js @@ -94,6 +94,8 @@ var ReaderView = View.extend({ // disable until we start using spinning again // this.listen() + + app.tube("site-ready") }, listen: function(){ -- cgit v1.2.3-70-g09d2 From ee110d4725943bbc2b783323ec5087324531ca33 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 27 Aug 2015 18:17:14 -0400 Subject: get rooms api working with shapes --- .../javascripts/rectangles/engine/map/_map.js | 3 + .../javascripts/rectangles/engine/map/draw.js | 19 +-- .../javascripts/rectangles/engine/shapes/ortho.js | 9 ++ .../rectangles/engine/shapes/polyline.js | 9 ++ .../rectangles/engine/shapes/regionlist.js | 11 ++ .../rectangles/engine/shapes/shapelist.js | 13 +- .../assets/javascripts/ui/editor/EditorSettings.js | 2 +- public/assets/javascripts/ui/reader/ReaderView.js | 7 +- server/lib/api/rooms.js | 139 +++++++++++++++------ 9 files changed, 161 insertions(+), 51 deletions(-) (limited to 'public/assets/javascripts/ui/reader/ReaderView.js') diff --git a/public/assets/javascripts/rectangles/engine/map/_map.js b/public/assets/javascripts/rectangles/engine/map/_map.js index e27346d..6492db6 100644 --- a/public/assets/javascripts/rectangles/engine/map/_map.js +++ b/public/assets/javascripts/rectangles/engine/map/_map.js @@ -50,6 +50,7 @@ var Map = function(opt){ switch (opt.type) { case "ortho": base.draw = new Map.Draw (base, { ortho: true }) + base.draw.grid_size = MAP_GRID_SIZE base.ui = new Map.UI.Ortho (base) base.sides = base.sides_for_center $(window).resize(base.resize) @@ -57,6 +58,7 @@ var Map = function(opt){ case "editor": base.draw = new Map.Draw (base) + base.draw.grid_size = MAP_GRID_SIZE base.ui = new Map.UI.Editor (base) base.sides = base.sides_for_center $(window).resize(base.resize) @@ -64,6 +66,7 @@ var Map = function(opt){ case "minimap": base.draw = new Map.Draw (base, { center: scene.camera, minimap: true }) + base.draw.grid_size = MAP_GRID_SIZE * 10 base.ui = new Map.UI.Minimap (base) base.sides = base.sides_for_camera break diff --git a/public/assets/javascripts/rectangles/engine/map/draw.js b/public/assets/javascripts/rectangles/engine/map/draw.js index fd05f86..4f4759f 100644 --- a/public/assets/javascripts/rectangles/engine/map/draw.js +++ b/public/assets/javascripts/rectangles/engine/map/draw.js @@ -179,8 +179,8 @@ Map.Draw = function(map, opt){ ctx.lineWidth = 1/map.zoom var sides = map.sides() - var quant = sides.clone().quantize(MAP_GRID_SIZE) - for (var x = quant.x.a - MAP_GRID_SIZE; x <= quant.x.b; x += MAP_GRID_SIZE) { + var quant = sides.clone().quantize(draw.grid_size) + for (var x = quant.x.a - draw.grid_size; x <= quant.x.b; x += draw.grid_size) { if (Math.round(x) % 360 == 0) { ctx.strokeStyle = "rgba(0,0,0,0.3)" ctx.lineWidth = 1/map.zoom @@ -191,17 +191,18 @@ Map.Draw = function(map, opt){ } line(x, sides.y.a, x, sides.y.b) } - for (var y = quant.y.a - MAP_GRID_SIZE; y <= quant.y.b; y += MAP_GRID_SIZE) { - if (Math.round(y) % 360 == 0) { + + for (var y = quant.y.a - draw.grid_size; y <= quant.y.b; y += draw.grid_size) { + if (Math.round(y) % 360 == 0) { ctx.strokeStyle = "rgba(0,0,0,0.3)" ctx.lineWidth = 1/map.zoom - } - else { + } + else { ctx.strokeStyle = "rgba(0,0,0,0.05)" ctx.lineWidth = 1/map.zoom - } - line(sides.x.a, y, sides.x.b, y) - } + } + line(sides.x.a, y, sides.x.b, y) + } } // diff --git a/public/assets/javascripts/rectangles/engine/shapes/ortho.js b/public/assets/javascripts/rectangles/engine/shapes/ortho.js index c1acae5..163f646 100644 --- a/public/assets/javascripts/rectangles/engine/shapes/ortho.js +++ b/public/assets/javascripts/rectangles/engine/shapes/ortho.js @@ -1,5 +1,9 @@ // An OrthoPolyline is a Polyline where all angles are 90 degrees. +if (! ('window' in this) ) { + var Polyline = require("./polyline.js") +} + var OrthoPolyline = Polyline.extend(function(base){ var exports = {} exports.type = function(){ @@ -55,3 +59,8 @@ var OrthoPolyline = Polyline.extend(function(base){ } return exports }) + + +if (! ('window' in this) ) { + module.exports = OrthoPolyline +} diff --git a/public/assets/javascripts/rectangles/engine/shapes/polyline.js b/public/assets/javascripts/rectangles/engine/shapes/polyline.js index 579d0ea..b2cd92f 100644 --- a/public/assets/javascripts/rectangles/engine/shapes/polyline.js +++ b/public/assets/javascripts/rectangles/engine/shapes/polyline.js @@ -2,6 +2,11 @@ // Additionally, it manages a set of MX objects which correspond to the walls in 3D. // In this way, it attempts to bridge the 2D (canvas, imperative) and 3D (css, declarative) views. +if (! ('window' in this) ) { + var Fiber = require("../../../vendor/bower_components/fiber/src/fiber.js") + var vec2 = require("../../models/vec2") +} + var Polyline = Fiber.extend(function(base){ var exports = {} exports.init = function(){ @@ -201,3 +206,7 @@ var Polyline = Fiber.extend(function(base){ } return exports }) + +if (! ('window' in this) ) { + module.exports = Polyline +} diff --git a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js index 0dd4a1e..8c9e732 100644 --- a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js +++ b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js @@ -5,6 +5,13 @@ // 1) all angles are orthogonal // 2) all polylines are closed +if (! ('window' in this) ) { + var Fiber = require("../../../vendor/bower_components/fiber/src/fiber.js") + var vec2 = require("../../models/vec2") + var Rect = require("../../models/rect") + var sort = require("../../util/sort") +} + var RegionList = (function(){ var RegionList = {} @@ -223,6 +230,10 @@ var RegionList = (function(){ } return new Rect( segment[0].a, segment[0].b, segment[1].a, segment[1].b ) } + + if (! ('window' in this) ) { + module.exports = RegionList + } return RegionList diff --git a/public/assets/javascripts/rectangles/engine/shapes/shapelist.js b/public/assets/javascripts/rectangles/engine/shapes/shapelist.js index 2d33af2..21beb76 100644 --- a/public/assets/javascripts/rectangles/engine/shapes/shapelist.js +++ b/public/assets/javascripts/rectangles/engine/shapes/shapelist.js @@ -1,5 +1,11 @@ // The ShapeList manages the list of polylines which form a V2 layout. +if (! ('window' in this) ) { + var Fiber = require("../../../vendor/bower_components/fiber/src/fiber.js") + var Polyline = require("./polyline.js") + var OrthoPolyline = require("./ortho.js") +} + var ShapeList = Fiber.extend(function(base){ var exports = {} exports.init = function(){ @@ -110,4 +116,9 @@ var ShapeList = Fiber.extend(function(base){ }) } return exports -}) \ No newline at end of file +}) + +if (! ('window' in this) ) { + shapes = new ShapeList + module.exports = shapes +} diff --git a/public/assets/javascripts/ui/editor/EditorSettings.js b/public/assets/javascripts/ui/editor/EditorSettings.js index 83bc8b7..d8cfca6 100644 --- a/public/assets/javascripts/ui/editor/EditorSettings.js +++ b/public/assets/javascripts/ui/editor/EditorSettings.js @@ -41,7 +41,7 @@ var EditorSettings = FormView.extend({ this.action = data.isNew ? this.createAction : this.updateAction this.parent.data = data - if (data.shapes) { + if (data.shapes.length) { Rooms.deserializeFromShapes(data, data.walls) } else if (data.rooms) { diff --git a/public/assets/javascripts/ui/reader/ReaderView.js b/public/assets/javascripts/ui/reader/ReaderView.js index 1ba97cf..43e81d8 100644 --- a/public/assets/javascripts/ui/reader/ReaderView.js +++ b/public/assets/javascripts/ui/reader/ReaderView.js @@ -76,7 +76,12 @@ var ReaderView = View.extend({ }, build: function(data){ - data.rooms && Rooms.deserialize(data.rooms) + if (data.shapes.length) { + Rooms.deserializeFromShapes(data) + } + else { + Rooms.deserialize(data.rooms) + } data.walls && Walls.deserialize(data.walls) data.media && Scenery.deserialize(data.media) data.sculpture && Sculpture.deserialize(data.sculpture) diff --git a/server/lib/api/rooms.js b/server/lib/api/rooms.js index c044309..2a1d2fe 100644 --- a/server/lib/api/rooms.js +++ b/server/lib/api/rooms.js @@ -6,6 +6,8 @@ var Clipper = require("../../../public/assets/javascripts/rectangles/engine/room var Builder = require("../../../public/assets/javascripts/rectangles/engine/rooms/builder.js") var Grouper = require("../../../public/assets/javascripts/rectangles/engine/rooms/grouper.js") var Walls = require("../../../public/assets/javascripts/rectangles/engine/rooms/_walls.js") +var shapes = require("../../../public/assets/javascripts/rectangles/engine/shapes/shapelist.js") +var RegionList = require("../../../public/assets/javascripts/rectangles/engine/shapes/regionlist.js") /* jshint node: true */ @@ -21,47 +23,106 @@ var rooms = module.exports = { if (! doc) { res.json({ status: 404 }); return } doc = doc.toObject() - doc.rooms.forEach(function(data){ - var rect = new Rect(data.rect.x[0], data.rect.y[0], data.rect.x[1], data.rect.y[1]) - var room = new Room({ - id: data.id, - rect: rect, - height: data.height - }) - Rooms.add(room) - }) - Rooms.clipper.solve_rects() - Rooms.builder.build() - - var walls = [], mx_walls = [], mx_floor = [], mx_ceiling = [] - var collections = Rooms.grouper.collect() - Rooms.grouper.cull(collections) - Rooms.grouper.group(walls, collections, FRONT) - Rooms.grouper.group(walls, collections, BACK) - Rooms.grouper.group(walls, collections, LEFT) - Rooms.grouper.group(walls, collections, RIGHT) - walls.forEach(function(wall){ - wall.mx.forEach(function(mx){ - var data = mx.report() - data.id = wall.id - mx_walls.push(data) - }) - }) - - doc.mx_walls = mx_walls - doc.mx_floor = mx_floor - doc.mx_ceiling = mx_ceiling - - Rooms.forEach(function(room){ - room.mx_floor.forEach(function(mx){ - mx_floor.push( mx.report() ) - }) - room.mx_ceiling.forEach(function(mx){ - mx_ceiling.push( mx.report() ) - }) - }) + if (doc.shapes.length) { + parseMxShapes(doc) + } + else { + parseMxRooms(doc) + } res.json(doc) }) } } + +function parseMxShapes (doc) { + var viewHeight = doc.viewHeight + var wallHeight = doc.wallHeight + + shapes.deserialize( doc.shapes ) + + var walls = [], mx_walls = [], mx_floor = [], mx_ceiling = [] + var regions = RegionList.build() + + regions.forEach(function(region){ + var room = new Room({ + rect: region, + regions: [region], + height: wallHeight, + }) + + room.sides = region.sides + region.id = Rooms.uid("room_") + Rooms.list[ region.id ] = room + Rooms.builder.build_walls(region) + mx_floor.push( Rooms.builder.make_floor(room, region) ) + mx_ceiling.push( Rooms.builder.make_ceiling(room, region) ) + }) + + var collections = Rooms.grouper.collect() + Rooms.grouper.cull(collections) + Rooms.grouper.group(walls, collections, FRONT) + Rooms.grouper.group(walls, collections, BACK) + Rooms.grouper.group(walls, collections, LEFT) + Rooms.grouper.group(walls, collections, RIGHT) + walls.forEach(function(wall){ + wall.mx.forEach(function(mx){ + var data = mx.report() + data.id = wall.id + mx_walls.push(data) + }) + }) + + doc.mx_walls = mx_walls + doc.mx_floor = mx_floor + doc.mx_ceiling = mx_ceiling + + Rooms.forEach(function(room){ + mx_floor.push( room.mx_floor ) + room.mx_ceiling.forEach(function(mx){ + mx_ceiling.push( mx.report() ) + }) + }) +} + +function parseMxRooms (doc) { + doc.rooms.forEach(function(data){ + var rect = new Rect(data.rect.x[0], data.rect.y[0], data.rect.x[1], data.rect.y[1]) + var room = new Room({ + id: data.id, + rect: rect, + height: data.height + }) + Rooms.add(room) + }) + Rooms.clipper.solve_rects() + Rooms.builder.build() + + var walls = [], mx_walls = [], mx_floor = [], mx_ceiling = [] + var collections = Rooms.grouper.collect() + Rooms.grouper.cull(collections) + Rooms.grouper.group(walls, collections, FRONT) + Rooms.grouper.group(walls, collections, BACK) + Rooms.grouper.group(walls, collections, LEFT) + Rooms.grouper.group(walls, collections, RIGHT) + walls.forEach(function(wall){ + wall.mx.forEach(function(mx){ + var data = mx.report() + data.id = wall.id + mx_walls.push(data) + }) + }) + + doc.mx_walls = mx_walls + doc.mx_floor = mx_floor + doc.mx_ceiling = mx_ceiling + + Rooms.forEach(function(room){ + room.mx_floor.forEach(function(mx){ + mx_floor.push( mx.report() ) + }) + room.mx_ceiling.forEach(function(mx){ + mx_ceiling.push( mx.report() ) + }) + }) +} \ No newline at end of file -- cgit v1.2.3-70-g09d2