summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/rectangles')
-rw-r--r--public/assets/javascripts/rectangles/engine/rooms/_walls.js37
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/undo.js75
-rw-r--r--public/assets/javascripts/rectangles/util/minotaur.js2
-rw-r--r--public/assets/javascripts/rectangles/util/undostack.js13
4 files changed, 83 insertions, 44 deletions
diff --git a/public/assets/javascripts/rectangles/engine/rooms/_walls.js b/public/assets/javascripts/rectangles/engine/rooms/_walls.js
index 046961b..f2f395b 100644
--- a/public/assets/javascripts/rectangles/engine/rooms/_walls.js
+++ b/public/assets/javascripts/rectangles/engine/rooms/_walls.js
@@ -86,8 +86,43 @@
var wall = base.lookup[ wall_data.id ]
wall.deserialize( wall_data )
})
+ },
+
+ base.setColor = {
+
+ wall: function(rgb){
+ var rgbaColor = rgba_string(rgb, app.defaults.wallOpacity)
+ Walls.colors.wall = rgb
+ Walls.forEach(function(wall){
+ wall.outline(rgbaColor, null)
+ })
+ },
+
+ outline: function(rgb){
+ var rgbColor = rgb_string(rgb)
+ Walls.colors.outline = rgb
+ Walls.forEach(function(wall){
+ wall.outline(null, rgbColor)
+ })
+ },
+
+ floor: function(rgb){
+ var rgbColor = rgb_string(rgb)
+ Walls.colors.floor = rgb
+ Rooms.forEach(function(room){
+ room.setFloorColor(rgbColor)
+ })
+ },
+
+ ceiling: function(rgb){
+ var rgbColor = rgb_string(rgb)
+ Walls.colors.ceiling = rgb
+ Rooms.forEach(function(room){
+ room.setCeilingColor(rgbColor)
+ })
+ },
+
}
-
}
if ('window' in this) {
diff --git a/public/assets/javascripts/rectangles/engine/scenery/undo.js b/public/assets/javascripts/rectangles/engine/scenery/undo.js
index 1632c5b..ac9fdc0 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/undo.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/undo.js
@@ -1,7 +1,7 @@
(function(){
- UndoStack.register([
- {
- type: "create-scenery",
+ UndoStack.register([
+ {
+ type: "create-scenery",
undo: function(state){
Scenery.remove(state.id)
@@ -14,9 +14,9 @@
// TODO: watch individual scenery object here
Minotaur.watch( app.router.editorView.settings )
},
- },
- {
- type: "update-scenery",
+ },
+ {
+ type: "update-scenery",
undo: function(state){
var scenery = Scenery.find(state.id)
scenery.deserialize(state)
@@ -43,9 +43,9 @@
// TODO: watch individual scenery object here
Minotaur.watch( app.router.editorView.settings )
},
- },
- {
- type: "destroy-scenery",
+ },
+ {
+ type: "destroy-scenery",
undo: function(state){
Scenery.deserialize([ state ])
@@ -58,12 +58,12 @@
// TODO: watch individual scenery object here
Minotaur.watch( app.router.editorView.settings )
},
- },
-
- //
-
- {
- type: "create-room",
+ },
+
+ //
+
+ {
+ type: "create-room",
undo: function(room){
Rooms.remove(room)
Rooms.clipper.update()
@@ -71,52 +71,55 @@
redo: function(room){
Rooms.add(new Room(room))
Rooms.clipper.update()
- app.tube("builder-pick-room", room)
+ app.tube("builder-pick-room", room)
},
- },
- {
- type: "update-room",
+ },
+ {
+ type: "update-room",
undo: function(state){
var room = Rooms.list[state.id]
room.rect.assign( state.rect )
room.height = state.height
Rooms.clipper.update()
- app.tube("builder-pick-room", room)
+ app.tube("builder-pick-room", room)
},
redo: function(state){
var room = Rooms.list[state.id]
room.rect.assign( state.rect )
room.height = state.height
Rooms.clipper.update()
- app.tube("builder-pick-room", room)
+ app.tube("builder-pick-room", room)
},
- },
- {
- type: "destroy-room",
+ },
+ {
+ type: "destroy-room",
undo: function(room){
Rooms.add(new Room(room))
Rooms.clipper.update()
- app.tube("builder-pick-room", room)
+ app.tube("builder-pick-room", room)
},
redo: function(room){
Rooms.remove(room)
Rooms.clipper.update()
},
- },
-
- //
+ },
+
+ //
- {
- type: "update-wallpaper",
+ {
+ type: "update-wallpaper",
undo: function(state){
var wall = Walls.lookup[state.id]
wall.deserialize(state)
},
- redo: function(state){
- var wall = Walls.lookup[state.id]
- wall.deserialize(state)
+ },
+ {
+ type: "update-colors",
+ undo: function(state){
+ Walls.setColor[ state.mode ]( state.rgb )
+ app.router.editorView.lightControl.setSwatchColor( state.mode, state.rgb )
},
- },
-
- ])
+ },
+
+ ])
})()
diff --git a/public/assets/javascripts/rectangles/util/minotaur.js b/public/assets/javascripts/rectangles/util/minotaur.js
index 039a053..e6a37e0 100644
--- a/public/assets/javascripts/rectangles/util/minotaur.js
+++ b/public/assets/javascripts/rectangles/util/minotaur.js
@@ -4,7 +4,7 @@
var base = this
base.$el = $("#minotaur")
base.timeout = null
- base.delay = 500
+ base.delay = 1000
base.objects = {}
base.init = function () {
diff --git a/public/assets/javascripts/rectangles/util/undostack.js b/public/assets/javascripts/rectangles/util/undostack.js
index b93c79e..959e3d1 100644
--- a/public/assets/javascripts/rectangles/util/undostack.js
+++ b/public/assets/javascripts/rectangles/util/undostack.js
@@ -31,16 +31,17 @@
this.types[ action.type ].redo(action.redo)
return this.pointer < this.stack.length-1
}
- UndoStack.prototype.register = function(actionType){
- if (actionType.length) {
- actionType.forEach(this.registerOne.bind(this))
+ UndoStack.prototype.register = function(actions){
+ if (actions.length) {
+ actions.forEach(this.registerOne.bind(this))
}
else {
- this.registerOne(actionType)
+ this.registerOne(actions)
}
}
- UndoStack.prototype.registerOne = function(actionType){
- this.types[ actionType.type ] = actionType
+ UndoStack.prototype.registerOne = function(action){
+ if (! action.redo) { action.redo = action.undo }
+ this.types[ action.type ] = action
}
if ('window' in this) {
window.UndoStack = new UndoStack