diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-08-13 16:12:02 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-08-13 16:21:26 -0400 |
| commit | 90cb5b343f3d56372f9b43faf215ed80dd879fe1 (patch) | |
| tree | dfac1c586b713a70c9bd5ffce01f93a46a256e75 /public/assets/javascripts/rectangles/engine | |
| parent | 14228e82f4836b1bffa3389aa9e8d12959aa3810 (diff) | |
undo for scenery stuff
Diffstat (limited to 'public/assets/javascripts/rectangles/engine')
5 files changed, 66 insertions, 12 deletions
diff --git a/public/assets/javascripts/rectangles/engine/map/ui_editor.js b/public/assets/javascripts/rectangles/engine/map/ui_editor.js index c5c996c..9a557b9 100644 --- a/public/assets/javascripts/rectangles/engine/map/ui_editor.js +++ b/public/assets/javascripts/rectangles/engine/map/ui_editor.js @@ -58,8 +58,8 @@ Map.UI.Editor = function(map){ UndoStack.push({ type: "destroy-room", - prev: room.copy(), - next: { id: room.id }, + undo: room.copy(), + redo: { id: room.id }, }) Rooms.remove(room) @@ -164,8 +164,8 @@ Map.UI.Editor = function(map){ UndoStack.push({ type: "create-room", - prev: { id: room.id }, - next: room.copy() + undo: { id: room.id }, + redo: room.copy() }) app.tube("builder-pick-room", room) @@ -185,8 +185,8 @@ Map.UI.Editor = function(map){ UndoStack.push({ type: "update-room", - prev: oldState, - next: base.dragging.copy() + undo: oldState, + redo: base.dragging.copy() }) } @@ -211,8 +211,8 @@ Map.UI.Editor = function(map){ wheelTimeout = setTimeout(function(){ UndoStack.push({ type: "update-room", - prev: wheelState, - next: intersects[0].copy() + undo: wheelState, + redo: intersects[0].copy() }) Rooms.clipper.update() wheelState = null diff --git a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js index fe5f037..c96885c 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js +++ b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js @@ -30,10 +30,15 @@ var Scenery = new function(){ } base.addNextToWall = function(wall){ - base.add(wall, base.nextMedia) + var media = base.add(wall, base.nextMedia) base.nextMedia = null + return media } - + + base.find = function(id){ + return base.list[id] || null + } + base.remove = function(id){ var media = base.list[id] delete base.list[id] diff --git a/public/assets/javascripts/rectangles/engine/scenery/move.js b/public/assets/javascripts/rectangles/engine/scenery/move.js index 94a4e52..ef9bc32 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/move.js +++ b/public/assets/javascripts/rectangles/engine/scenery/move.js @@ -3,6 +3,7 @@ Scenery.move = function(base){ var x, y, z, bounds var dragging = false + var oldState this.bind = function(){ Scenery.mouse.bind_el(base.mx.el) @@ -23,6 +24,12 @@ Scenery.move = function(base){ function down (e, cursor){ if (e.target != base.mx.el) return; if (editor.permissions.destroy) { + UndoStack.push({ + type: 'destroy-scenery', + undo: base.serialize(), + redo: { id: base.id }, + }) + Scenery.remove(base.id) return } @@ -39,6 +46,7 @@ Scenery.move = function(base){ y = base.mx.y z = base.mx.z bounds = base.bounds + oldState = base.serialize() document.body.classList.add("dragging") } @@ -63,8 +71,20 @@ Scenery.move = function(base){ } function up (e, cursor){ + if (! dragging || ! oldState) return + dragging = false document.body.classList.remove("dragging") + + console.log("pushing", oldState, base.serialize()) + + UndoStack.push({ + type: 'update-scenery', + undo: oldState, + redo: base.serialize(), + }) + + oldState = null } function switch_wall (e, new_wall, cursor){ diff --git a/public/assets/javascripts/rectangles/engine/scenery/resize.js b/public/assets/javascripts/rectangles/engine/scenery/resize.js index df058bb..c5c754a 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/resize.js +++ b/public/assets/javascripts/rectangles/engine/scenery/resize.js @@ -7,6 +7,7 @@ Scenery.resize = new function(){ var x, y, z, bounds var dragging = false var dimensions, position, scale + var oldState var dots = [], dot, selected_dot @@ -54,7 +55,7 @@ Scenery.resize = new function(){ } // move all the dots to the object's current position - base.move_dots = function(){ + base.move_dots = function(){ x = obj.mx.x + sin(rotationY) * dot_distance_from_picture y = obj.mx.y z = obj.mx.z - cos(rotationY) * dot_distance_from_picture @@ -88,7 +89,7 @@ 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 (obj === new_object) return obj = new_object base.add_dots() @@ -151,6 +152,7 @@ Scenery.resize = new function(){ dimensions = obj.dimensions position = new vec3(obj.mx.x, obj.mx.y, obj.mx.z) scale = obj.mx.scale + oldState = obj.serialize() document.body.classList.add("dragging") } @@ -191,6 +193,13 @@ Scenery.resize = new function(){ if (! editor.permissions.resize) { return } obj.scale = obj.mx.ops.scale = obj.mx.scale obj.set_wall() + + UndoStack.push({ + type: 'update-scenery', + undo: oldState, + redo: obj.serialize(), + }) + document.body.classList.remove("dragging") } diff --git a/public/assets/javascripts/rectangles/engine/scenery/undo.js b/public/assets/javascripts/rectangles/engine/scenery/undo.js index 4bdb2c4..7798550 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/undo.js +++ b/public/assets/javascripts/rectangles/engine/scenery/undo.js @@ -3,22 +3,42 @@ { type: "create-scenery", undo: function(state){ + Scenery.remove(state.id) }, redo: function(state){ + Scenery.deserialize([ state ]) }, }, { type: "update-scenery", undo: function(state){ + var scenery = Scenery.find(state.id) + scenery.deserialize(state) + scenery.set_wall(Rooms.walls[ state.wall_id ]) + + if (editor.permissions.resize) { + Scenery.resize.show(scenery) + } }, redo: function(state){ + var scenery = Scenery.find(state.id) + scenery.deserialize(state) + scenery.set_wall(Rooms.walls[ state.wall_id ]) + + if (editor.permissions.resize) { + Scenery.resize.show(scenery) + Scenery.resize.rotate_dots() + Scenery.resize.move_dots() + } }, }, { type: "destroy-scenery", undo: function(state){ + Scenery.deserialize([ state ]) }, redo: function(state){ + Scenery.remove(state.id) }, }, |
