diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-11-03 14:54:12 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-11-03 14:54:12 -0500 |
| commit | 0df2cd6c000e593795c1de868a47666862d3ed96 (patch) | |
| tree | 28b032b2a5a7e4f0a6322f805b006add549bf34f | |
| parent | 7e20e81927b4d52de2f54c0923c65869f4c253ee (diff) | |
undo presets
3 files changed, 59 insertions, 13 deletions
diff --git a/public/assets/javascripts/rectangles/engine/rooms/_walls.js b/public/assets/javascripts/rectangles/engine/rooms/_walls.js index 25b1c58..04d0594 100644 --- a/public/assets/javascripts/rectangles/engine/rooms/_walls.js +++ b/public/assets/javascripts/rectangles/engine/rooms/_walls.js @@ -40,12 +40,17 @@ base.colors = {} base.init = function(){ - base.colors = { - wall: app.defaults.colors.wall.slice(), - outline: app.defaults.colors.outline.slice(), - floor: app.defaults.colors.floor.slice(), - ceiling: app.defaults.colors.ceiling.slice(), + base.colors = base.copyColors( app.defaults.colors ) + } + + base.copyColors = function(colors){ + var copy = { + wall: colors.wall.slice(), + outline: colors.outline.slice(), + floor: colors.floor.slice(), + ceiling: colors.ceiling.slice(), } + return copy } base.first = function(){ diff --git a/public/assets/javascripts/rectangles/engine/scenery/undo.js b/public/assets/javascripts/rectangles/engine/scenery/undo.js index ff4f911..52a57d9 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/undo.js +++ b/public/assets/javascripts/rectangles/engine/scenery/undo.js @@ -114,7 +114,32 @@ undo: function(state){ var wall = Walls.lookup[state.id] wall.deserialize(state) - + Minotaur.watch( app.router.editorView.settings ) + }, + }, + { + type: "update-all-wallpaper", + undo: function(state){ + Walls.deserialize(state) + Minotaur.watch( app.router.editorView.settings ) + }, + }, + { + type: "choose-preset", + undo: function(state){ + app.controller.colorControl.load(state.colors) + Walls.deserialize(state.walls) + Minotaur.watch( app.router.editorView.settings ) + }, + redo: function(state){ + app.controller.presets.loadByName(state) + Minotaur.watch( app.router.editorView.settings ) + }, + }, + { + type: "choose-another-preset", + undo: function(state){ + app.controller.presets.loadByName(state) Minotaur.watch( app.router.editorView.settings ) }, }, @@ -123,7 +148,6 @@ undo: function(state){ Walls.setColor[ state.mode ]( state.rgb ) app.router.editorView.colorControl.setSwatchColor( state.mode, state.rgb ) - Minotaur.watch( app.router.editorView.settings ) }, }, diff --git a/public/assets/javascripts/ui/editor/Presets.js b/public/assets/javascripts/ui/editor/Presets.js index ac77d6b..1327e03 100644 --- a/public/assets/javascripts/ui/editor/Presets.js +++ b/public/assets/javascripts/ui/editor/Presets.js @@ -4,7 +4,6 @@ var Presets = View.extend({ events: { "mousedown": "stopPropagation", "click .presets span": "selectPreset", - "click .swatches span": "selectColor", }, presets: { @@ -53,7 +52,9 @@ var Presets = View.extend({ }.bind(this)) }, - modified: false, + modified: true, + lastPreset: "wireframe", + toggle: function(state){ this.$el.toggleClass("active", state) this.parent.cursor.message(state ? "presets" : "start") @@ -75,15 +76,31 @@ var Presets = View.extend({ if (! this.presets[preset]) return this.$(".active").removeClass('active') $(e.currentTarget).addClass('active') + if (this.modified) { + UndoStack.push({ + type: "choose-preset", + undo: { walls: Walls.serialize(), colors: Walls.copyColors(Walls.colors) }, + redo: preset, + }) + Minotaur.watch( app.router.editorView.settings ) + } + else { + UndoStack.push({ + type: "choose-another-preset", + undo: this.lastPreset, + redo: preset, + }) + Minotaur.watch( app.router.editorView.settings ) + } + this.lastPreset = preset this.load(this.presets[preset]) this.modified = false }, - selectColor: function(e){ - var preset = $(e.currentTarget).data('color') - console.log(preset) + loadByName: function(name){ + var preset = this.presets[name] + this.load(preset) }, - load: function(preset){ this.parent.colorControl.modes.forEach(function(mode){ var color |
