summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-11-03 16:59:45 -0500
committerJules Laplace <jules@okfoc.us>2014-11-03 16:59:45 -0500
commita49023a991c62595fc5c449729be4cc313ff66a7 (patch)
tree2e4d3bd4ce9f19fae1c3c6ce73133f24ef81fa8f
parent16e4733522018477062abd8d60837c2bd69a93cb (diff)
fix undo scenery create/destroy
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/move.js31
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/resize.js2
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/undo.js6
-rw-r--r--public/assets/javascripts/rectangles/util/undostack.js1
-rw-r--r--public/assets/javascripts/ui/editor/MediaEditor.js14
5 files changed, 37 insertions, 17 deletions
diff --git a/public/assets/javascripts/rectangles/engine/scenery/move.js b/public/assets/javascripts/rectangles/engine/scenery/move.js
index 7d148cf..3ae4993 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/move.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/move.js
@@ -2,7 +2,7 @@
Scenery.move = function(base){
var x, y, z, position, dimension, bounds
- var dragging = false
+ var dragging = false, moved = false
var oldState
this.bind = function(){
@@ -45,6 +45,7 @@ Scenery.move = function(base){
return
}
dragging = true
+ moved = false
x = base.mx.x
y = base.mx.y
z = base.mx.z
@@ -59,6 +60,8 @@ Scenery.move = function(base){
function drag (e, cursor){
if (! dragging) return
+
+ moved = true
var flipX = base.wall.side & (FRONT | RIGHT)
@@ -89,21 +92,23 @@ Scenery.move = function(base){
function up (e, cursor){
if (! dragging || ! oldState) return
-
- dragging = false
- document.body.classList.remove("dragging")
+
+ if (moved) {
+ UndoStack.push({
+ type: 'update-scenery',
+ undo: oldState,
+ redo: base.serialize(),
+ })
- UndoStack.push({
- type: 'update-scenery',
- undo: oldState,
- redo: base.serialize(),
- })
+ // TODO: watch individual scenery object here
+ Minotaur.watch( app.router.editorView.settings )
+ }
- // TODO: watch individual scenery object here
- Minotaur.watch( app.router.editorView.settings )
-
+ dragging = moved = false
oldState = null
- }
+ document.body.classList.remove("dragging")
+
+ }
function switch_wall (e, target, cursor){
if (! dragging) return
diff --git a/public/assets/javascripts/rectangles/engine/scenery/resize.js b/public/assets/javascripts/rectangles/engine/scenery/resize.js
index 0ce976e..e424829 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/resize.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/resize.js
@@ -88,8 +88,8 @@ Scenery.resize = new function(){
// pick a new object to focus on and show the dots
base.show = function(new_object) {
// if (obj === new_object) return
+ if (! new_object) return
obj = new_object
-
base.add_dots()
base.rotate_dots()
base.move_dots()
diff --git a/public/assets/javascripts/rectangles/engine/scenery/undo.js b/public/assets/javascripts/rectangles/engine/scenery/undo.js
index 3deb764..998f7c6 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/undo.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/undo.js
@@ -4,12 +4,13 @@
type: "create-scenery",
undo: function(state){
Scenery.remove(state.id)
+ Scenery.resize.hide()
// TODO: watch individual scenery object here
Minotaur.watch( app.router.editorView.settings )
},
redo: function(state){
- Scenery.deserialize([ state ])
+ var scenery = Scenery.deserialize([ state ])
Scenery.resize.show( scenery )
// TODO: watch individual scenery object here
@@ -49,13 +50,14 @@
{
type: "destroy-scenery",
undo: function(state){
- Scenery.deserialize([ state ])
+ var scenery = Scenery.deserialize([ state ])
Scenery.resize.show( scenery )
// TODO: watch individual scenery object here
Minotaur.watch( app.router.editorView.settings )
},
redo: function(state){
+ Scenery.resize.hide()
Scenery.remove(state.id)
// TODO: watch individual scenery object here
diff --git a/public/assets/javascripts/rectangles/util/undostack.js b/public/assets/javascripts/rectangles/util/undostack.js
index 959e3d1..040a4eb 100644
--- a/public/assets/javascripts/rectangles/util/undostack.js
+++ b/public/assets/javascripts/rectangles/util/undostack.js
@@ -10,6 +10,7 @@
this.pointer++
this.stack[this.pointer] = action
this.purge()
+ this.debug && console.log("push", action.type)
}
UndoStack.prototype.purge = function(){
if (this.stack.length-1 == this.pointer) return
diff --git a/public/assets/javascripts/ui/editor/MediaEditor.js b/public/assets/javascripts/ui/editor/MediaEditor.js
index 9b81db1..9a3c355 100644
--- a/public/assets/javascripts/ui/editor/MediaEditor.js
+++ b/public/assets/javascripts/ui/editor/MediaEditor.js
@@ -161,7 +161,7 @@ var MediaEditor = FormView.extend({
unbind: function(){
if (this.scenery) {
- if (this.tainted) {
+ if (this.tainted && this.scenery.media) {
this.scenery.media.title = this.$name.val()
this.scenery.media.description = this.$description.val()
Minotaur.watch( app.router.editorView.settings )
@@ -178,8 +178,20 @@ var MediaEditor = FormView.extend({
destroy: function(){
var scenery = this.scenery
this.hide()
+
+ UndoStack.push({
+ type: 'destroy-scenery',
+ undo: scenery.serialize(),
+ redo: { id: scenery.id },
+ })
+
+ // TODO: watch individual scenery object here
+ Minotaur.watch( app.router.editorView.settings )
+
Scenery.remove(scenery.id)
Scenery.resize.hide()
+ this.tainted = false
+ this.scenery = null
},
})