summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/engine
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-08-12 18:49:01 -0400
committerJules Laplace <jules@okfoc.us>2014-08-12 18:49:01 -0400
commitb8b208d219cf782c39d054ad741724c6995a0b62 (patch)
tree7f77e4c10c3d86d7a80d6cf1c8ff20f9c1e393c3 /public/assets/javascripts/rectangles/engine
parent838ccfe6c2125e464d3c95c6e222e7e762dc8fd2 (diff)
undo stuff working on rooms editor
Diffstat (limited to 'public/assets/javascripts/rectangles/engine')
-rw-r--r--public/assets/javascripts/rectangles/engine/map/ui_editor.js43
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/undo.js6
2 files changed, 37 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 4b5f784..c5c996c 100644
--- a/public/assets/javascripts/rectangles/engine/map/ui_editor.js
+++ b/public/assets/javascripts/rectangles/engine/map/ui_editor.js
@@ -58,7 +58,7 @@ Map.UI.Editor = function(map){
UndoStack.push({
type: "destroy-room",
- prev: room.clone(),
+ prev: room.copy(),
next: { id: room.id },
})
@@ -165,23 +165,36 @@ Map.UI.Editor = function(map){
UndoStack.push({
type: "create-room",
prev: { id: room.id },
- next: room.clone()
+ next: room.copy()
})
app.tube("builder-pick-room", room)
}
}
- if (base.resizing) {
- base.dragging.rect.resize()
- }
- else if (base.dragging) {
- base.dragging.rect.translate()
- }
+ if (base.resizing || base.dragging) {
+ var oldState = base.dragging.copy()
+
+ if (base.resizing) {
+ base.dragging.rect.resize()
+ }
+ else if (base.dragging) {
+ base.dragging.rect.translate()
+ }
+
+ UndoStack.push({
+ type: "update-room",
+ prev: oldState,
+ next: base.dragging.copy()
+ })
+ }
+
base.creating = base.dragging = base.resizing = false
}
+ var wheelState, wheelTimeout
+
function mousewheel (e, val, delta){
var cursor = base.mouse.cursor
@@ -190,8 +203,20 @@ Map.UI.Editor = function(map){
})
if (intersects.length) {
+ wheelState = wheelState || intersects[0].copy()
+
intersects[0].height = clamp( ~~(intersects[0].height - delta), height_min, height_max )
- Rooms.clipper.update()
+
+ clearTimeout(wheelTimeout)
+ wheelTimeout = setTimeout(function(){
+ UndoStack.push({
+ type: "update-room",
+ prev: wheelState,
+ next: intersects[0].copy()
+ })
+ Rooms.clipper.update()
+ wheelState = null
+ }, 500)
}
else {
map.set_zoom(map.zoom_exponent - delta/20)
diff --git a/public/assets/javascripts/rectangles/engine/scenery/undo.js b/public/assets/javascripts/rectangles/engine/scenery/undo.js
index b10a101..4bdb2c4 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/undo.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/undo.js
@@ -31,7 +31,7 @@
Rooms.clipper.update()
},
redo: function(room){
- Rooms.add(room)
+ Rooms.add(new Room(room))
Rooms.clipper.update()
app.tube("builder-pick-room", room)
},
@@ -56,7 +56,7 @@
{
type: "destroy-room",
undo: function(room){
- Rooms.add(room)
+ Rooms.add(new Room(room))
Rooms.clipper.update()
app.tube("builder-pick-room", room)
},
@@ -77,4 +77,4 @@
},
])
-})() \ No newline at end of file
+})()