summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/_scenery.js3
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/randomize.js18
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/undo.js30
-rw-r--r--public/assets/javascripts/ui/editor/EditorSettings.js15
-rw-r--r--public/assets/javascripts/ui/editor/WallpaperPicker.js29
-rwxr-xr-xpublic/assets/stylesheets/app.css32
-rw-r--r--server/lib/util.js10
-rw-r--r--views/controls/editor/settings.ejs6
8 files changed, 127 insertions, 16 deletions
diff --git a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js
index d03e0e1..d52fe21 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js
@@ -99,6 +99,7 @@ var Scenery = new function(){
}
base.deserialize = function(scenery_data){
+ var added = []
scenery_data.forEach(function(data){
var wall = Walls.lookup[data.wall_id] || Walls.first()
var scene_media = base.add({
@@ -107,7 +108,9 @@ var Scenery = new function(){
media: data.media,
id: data.id
})
+ added.push(scene_media)
})
+ return added
}
return base
diff --git a/public/assets/javascripts/rectangles/engine/scenery/randomize.js b/public/assets/javascripts/rectangles/engine/scenery/randomize.js
index 1c2eb56..6581f38 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/randomize.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/randomize.js
@@ -33,7 +33,7 @@ Scenery.randomize.get_dimensions = function (media_objs){
// Returns a lookup of walls to use, keyed by wall ID.
Scenery.randomize.get_empty_walls = function(wall_list){
// get a list of all walls
- var walls = {};
+ var walls = {}, removed = [];
(wall_list || Walls.list).forEach(function(wall){
walls[wall.id] = wall
@@ -44,6 +44,7 @@ Scenery.randomize.get_empty_walls = function(wall_list){
Scenery.forEach(function(scenery){
if (scenery.was_randomly_placed) {
// remove it and reuse this wall?
+ removed.push( scenery.serialize() )
Scenery.remove( scenery.id )
}
else {
@@ -52,7 +53,7 @@ Scenery.randomize.get_empty_walls = function(wall_list){
})
}
- return walls
+ return { walls: walls, removed: removed }
}
// Randomly place a set of media objects on empty walls.
@@ -60,7 +61,10 @@ Scenery.randomize.get_empty_walls = function(wall_list){
// Optionally takes a list of walls to use.
Scenery.randomize.add = function (media_objs, wall_list) {
var media_list = Scenery.randomize.get_dimensions(media_objs)
- var walls = Scenery.randomize.get_empty_walls(wall_list)
+ var empty_data = Scenery.randomize.get_empty_walls(wall_list)
+ var walls = empty_data.walls
+ var removed = empty_data.removed
+ var added = []
var wall_ids = _.keys(walls)
if (! wall_ids.length) { return }
@@ -93,6 +97,7 @@ Scenery.randomize.add = function (media_objs, wall_list) {
index: 0,
})
scenery.was_randomly_placed = true
+ added.push(scenery.serialize())
}
else {
// artwork won't fit anywhere??
@@ -100,4 +105,11 @@ Scenery.randomize.add = function (media_objs, wall_list) {
return false
})
+
+ UndoStack.push({
+ type: "randomize-scenery",
+ undo: { added: added, removed: removed },
+ redo: { added: added, removed: removed },
+ })
+
} \ No newline at end of file
diff --git a/public/assets/javascripts/rectangles/engine/scenery/undo.js b/public/assets/javascripts/rectangles/engine/scenery/undo.js
index 8b85d02..1232780 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/undo.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/undo.js
@@ -121,7 +121,7 @@
})
},
},
-
+
//
{
@@ -166,6 +166,34 @@
Minotaur.watch( app.router.editorView.settings )
},
},
+ {
+ type: "randomize-scenery",
+ undo: function(state){
+ state.added.forEach(function(_scenery){
+ Scenery.remove(_scenery.id)
+ })
+ var scenery_list = Scenery.deserialize(state.removed)
+ scenery_list.forEach(function(scenery){
+ scenery.was_randomly_placed = true
+ })
+ Scenery.resize.hide()
+
+ // TODO: watch individual scenery object here
+ Minotaur.watch( app.router.editorView.settings )
+ },
+ redo: function(state){
+ state.removed.forEach(function(_scenery){
+ Scenery.remove(_scenery.id)
+ })
+ var scenery_list = Scenery.deserialize(state.added)
+ scenery_list.forEach(function(scenery){
+ scenery.was_randomly_placed = true
+ })
+
+ // TODO: watch individual scenery object here
+ Minotaur.watch( app.router.editorView.settings )
+ },
+ },
])
})()
diff --git a/public/assets/javascripts/ui/editor/EditorSettings.js b/public/assets/javascripts/ui/editor/EditorSettings.js
index 026607a..b319404 100644
--- a/public/assets/javascripts/ui/editor/EditorSettings.js
+++ b/public/assets/javascripts/ui/editor/EditorSettings.js
@@ -18,6 +18,7 @@ var EditorSettings = FormView.extend({
"click [data-role='clear-project']": 'clear',
"click [data-role='destroy-project']": 'destroy',
"click [data-role='toggle-map']": 'toggleMap',
+ "click [data-role='view-project']": 'viewProject',
"click #startText": "setStartPosition",
"click #moveText": "confirmStartPosition",
"click #confirmText": "setStartPosition",
@@ -217,11 +218,25 @@ var EditorSettings = FormView.extend({
this.isVisible = true
},
+ viewAfterSave: false,
+ viewProject: function(e){
+ e.preventDefault()
+ Minotaur.unwatch(this)
+ Minotaur.hide()
+ this.viewAfterSave = true
+ this.save()
+ },
+
success: function(data){
this.$id.val(data._id)
this.$name.val(data.name)
this.action = this.updateAction
+ if (this.viewAfterSave) {
+ window.location.pathname = "/project/" + data.slug
+ return
+ }
+
Minotaur.unwatch(this)
Minotaur.hide()
diff --git a/public/assets/javascripts/ui/editor/WallpaperPicker.js b/public/assets/javascripts/ui/editor/WallpaperPicker.js
index e2aaeb7..3640d6d 100644
--- a/public/assets/javascripts/ui/editor/WallpaperPicker.js
+++ b/public/assets/javascripts/ui/editor/WallpaperPicker.js
@@ -5,6 +5,7 @@ var WallpaperPicker = UploadView.extend({
mediaTag: "wallpaper",
createAction: "/api/media/new",
uploadAction: "/api/media/upload",
+ destroyAction: "/api/media/destroy",
events: {
"contextmenu": 'contextmenu',
@@ -51,8 +52,6 @@ var WallpaperPicker = UploadView.extend({
this.load()
}
}
- // toggle the class that makes the cursor a paintbucket
- // $("body").removeClass("pastePaper")
},
load: function(){
@@ -78,6 +77,7 @@ var WallpaperPicker = UploadView.extend({
var swatch = document.createElement("div")
swatch.className = "swatch"
swatch.style.backgroundImage = "url(" + media.url + ")"
+ swatch.setAttribute("data-id", media._id)
this.$swatches.append(swatch)
this.$swatches.show()
this.$(".txt").hide()
@@ -104,23 +104,41 @@ var WallpaperPicker = UploadView.extend({
},
pick: function(e){
- app.tube('cancel-wallpaper')
var $swatch = $(e.currentTarget)
- this.follow( e, $swatch.css('background-image') )
- this.parent.presets.modified = true
+ if (Scenery.nextWallpaper == "none") {
+ var _id = $swatch[0].getAttribute("data-id")
+ $swatch.remove()
+ this.destroy(_id, function(){})
+ }
+ else {
+ app.tube('cancel-wallpaper')
+ this.follow( e, $swatch.css('background-image') )
+ this.parent.presets.modified = true
+ }
},
remove: function(e){
if (Scenery.nextWallpaper) {
+ // remove red class to the wallpaper
Scenery.nextWallpaper = null
app.tube('cancel-wallpaper')
}
else {
+ // add red class to the wallpaper
this.follow( e, "none" )
$(".floatingSwatch").addClass("scissors")
+ this.$el.addClass("deleteArmed")
}
},
+ destroy: function(_id, cb){
+ $.ajax({
+ type: "delete",
+ url: this.destroyAction,
+ data: { _id: _id, _csrf: $("[name=_csrf]").val() }
+ }).complete(cb || function(){})
+ },
+
contextmenu: function(e){
if (Scenery.nextWallpaper) {
e.preventDefault()
@@ -159,6 +177,7 @@ var WallpaperPicker = UploadView.extend({
app.off('cancel-wallpaper', _hideCursor)
$floatingSwatch.removeClass("scissors").hide()
$(".floodMessage").hide()
+ base.$el.removeClass("deleteArmed")
}
function _floodRoom (e) {
if (e.keyCode == 13) {
diff --git a/public/assets/stylesheets/app.css b/public/assets/stylesheets/app.css
index 98d97ac..5d69d75 100755
--- a/public/assets/stylesheets/app.css
+++ b/public/assets/stylesheets/app.css
@@ -1690,6 +1690,38 @@ border-left: 1px solid black;
padding-bottom: 6px;
}
+.wallpaper.deleteArmed.active .swatches .swatch {
+ border: 1px solid #FF3B30;
+}
+.desktop .wallpaper.deleteArmed .swatch:hover {
+ background-color: #FF3B30;
+}
+
+.wallpaper.deleteArmed .swatch:before {
+ content: "\f1eb";
+ font-family: 'ionicons';
+ speak: none;
+ font-style: normal;
+ font-weight: normal;
+ font-variant: normal;
+ text-transform: none;
+ -webkit-font-smoothing: antialiased;
+ font-size: 16px;
+ position: absolute;
+ background: #FF3B30;
+ border-radius: 50%;
+ margin-top: -8px;
+ margin-left: -8px;
+ color: white;
+ width: 20px;
+ height: 20px;
+ line-height: 16px;
+ text-align: center;
+ padding-top: 2px;
+}
+
+
+
.vvbox .colors {
max-width: 155px;
margin-bottom: 5px;
diff --git a/server/lib/util.js b/server/lib/util.js
index 273d7d1..e3fd1ed 100644
--- a/server/lib/util.js
+++ b/server/lib/util.js
@@ -10,8 +10,9 @@ var entities = new RegExp("[<>&]", 'g')
var util = {}
-util.trim = function (s){ return (s || "").replace(whitespaceHead,"").replace(whitespaceTail,"") }
-
+util.trim = function (s){
+ return (s || "").replace(whitespaceHead,"").replace(whitespaceTail,"")
+}
util.slugify = function (s){
return (s || "").toLowerCase().replace(whitespace,"-").replace(nonAlphanumerics, '-').replace(consecutiveDashes,"-")
}
@@ -33,7 +34,6 @@ util.escapeRegExp = function (s) {
util.htmlize = function(s) {
return s.replace(/\n/g,"<br>")
}
-
util.cleanQuery = function (query) {
var update = _.extend({}, query);
delete update._id;
@@ -43,14 +43,10 @@ util.cleanQuery = function (query) {
delete update.created_by;
return update;
}
-
util.ip2num = function(dot) {
- console.log(dot);
-
var d = (dot || "127.0.0.1").split('.');
return ((((((+d[0])*256)+(+d[1]))*256)+(+d[2]))*256)+(+d[3]);
}
-
util.num2ip = function(num) {
if (! num) return ""
var d = num % 256;
diff --git a/views/controls/editor/settings.ejs b/views/controls/editor/settings.ejs
index cd17382..cd915c5 100644
--- a/views/controls/editor/settings.ejs
+++ b/views/controls/editor/settings.ejs
@@ -27,6 +27,12 @@
<span class="ion-map"></span>
Edit map
</a>
+
+ <a href="#" class="modalLink" data-role='view-project' style="margin-left: 40px;">
+ <span class="ion-ios7-search-strong"></span>
+ View project
+ </a>
+
</div>
<div class="setting">