Permalink
Browse files

Added selection support to undo/redo, and some ground work for full r…

…eplay functionality.
  • Loading branch information...
1 parent 1569c81 commit 173cc684b6111cc95afb6e2b3b851effeab83bc2 @TylerJones TylerJones committed Apr 28, 2012
Showing with 29 additions and 2 deletions.
  1. +29 −2 web/js/board.js
View
@@ -32,6 +32,9 @@ var Board = Class.extend({
self.elements = [];
self.undoLog = [];
self.curUndo = -1;
+ self.replayLog = [];
+ self.record = false;
+ self.action = "Initial State";
self.drag = 0;
self.drag_target = null;
@@ -263,7 +266,8 @@ var Board = Class.extend({
return {'x': x, 'y': y};
},
- undoAdd: function(self) {
+ undoAdd: function(self, action) {
+ self.action = action;
var text = self.serialize(false);
self.curUndo++;
console.log(self.curUndo);
@@ -272,8 +276,17 @@ var Board = Class.extend({
self.undoLog.pop();
}
self.undoLog.push(text);
+ self.replayAdd(action);
},
+ undoOveride: function(self, action) {
+ self.action = action;
+ var text = self.serialize(false);
+ console.log(self.curUndo);
+ self.undoLog[self.curUndo] = text;
+ self.replayAdd(action);
+ },
+
undo: function(self) {
self.curUndo--;
console.log(self.curUndo);
@@ -282,6 +295,7 @@ var Board = Class.extend({
self.curUndo = 0;
}
self.deserialize(self.undoLog[self.curUndo], false);
+ self.replayAdd("Undoing");
},
redo: function(self) {
@@ -292,8 +306,18 @@ var Board = Class.extend({
self.curUndo = self.undoLog.length-1;
}
self.deserialize(self.undoLog[self.curUndo], false);
+ self.replayAdd("Redoing");
},
+ replayAdd: function(self, action) {
+ if (self.record == false){
+ return;
+ }
+ self.action = action;
+ var text = self.serialize(false);
+ self.replayLog.push(text);
+ },
+
serialize: function(self, full) {
for (var i=0; i<self.nodes.length; i++) {
self.nodes[i].id = i;
@@ -302,7 +326,7 @@ var Board = Class.extend({
self.elements[i].n1_id = self.elements[i].n1.id;
self.elements[i].n2_id = self.elements[i].n2.id;
}
- var keys = ["id", "nodes", "elements", "type", "x", "y", "n1_id", "n2_id", "resistance", "notes"];
+ var keys = ["id", "nodes", "elements", "type", "x", "y", "n1_id", "n2_id", "resistance", "notes", "selected", "action"];
if (full == true) {
keys = keys.concat(['undoLog', 'curUndo']);
}
@@ -326,6 +350,7 @@ var Board = Class.extend({
for (var i=0; i<boardData.nodes.length; i++) {
new Node(self, boardData.nodes[i].x, boardData.nodes[i].y);
self.nodes[i].notes = boardData.nodes[i].notes;
+ self.nodes[i].selected = boardData.nodes[i].selected;
}
for (var i=0; i<boardData.elements.length; i++) {
var n1 = self.nodes[boardData.elements[i].n1_id];
@@ -338,6 +363,7 @@ var Board = Class.extend({
new Resistor(self, n1, n2, r);
}
self.elements[i].notes = boardData.elements[i].notes;
+ self.elements[i].selected = boardData.elements[i].selected;
}
if (full == true) {
self.undoLog = []
@@ -346,6 +372,7 @@ var Board = Class.extend({
}
self.curUndo = boardData.curUndo;
}
+ self.action = boardData.action;
},
get_color: function(self) {

0 comments on commit 173cc68

Please sign in to comment.