CmdMultiCmds.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Created by Daniel on 20.07.15.
  3. */
  4. CmdMultiCmds = function ( cmdArray ) {
  5. Cmd.call( this );
  6. this.type = 'CmdMultiCmds';
  7. this.name = 'Multiple Changes';
  8. this.cmdArray = ( cmdArray !== undefined ) ? cmdArray : [];
  9. };
  10. CmdMultiCmds.prototype = {
  11. execute: function () {
  12. this.editor.signals.sceneGraphChanged.active = false;
  13. for ( var i = 0; i < this.cmdArray.length; i++ ) {
  14. this.cmdArray[ i ].execute();
  15. }
  16. this.editor.signals.sceneGraphChanged.active = true;
  17. this.editor.signals.sceneGraphChanged.dispatch();
  18. },
  19. undo: function () {
  20. this.editor.signals.sceneGraphChanged.active = false;
  21. for ( var i = this.cmdArray.length - 1; i >= 0; i-- ) {
  22. this.cmdArray[ i ].undo();
  23. }
  24. this.editor.signals.sceneGraphChanged.active = true;
  25. this.editor.signals.sceneGraphChanged.dispatch();
  26. },
  27. toJSON: function () {
  28. var output = Cmd.prototype.toJSON.call( this );
  29. var cmds = [];
  30. for ( var i = 0; i < this.cmdArray.length; i++ ) {
  31. cmds.push( this.cmdArray[ i ].toJSON() );
  32. }
  33. output.cmds = cmds;
  34. return output;
  35. },
  36. fromJSON: function ( json ) {
  37. Cmd.prototype.fromJSON.call( this, json );
  38. var cmds = json.cmds;
  39. for ( var i = 0; i < cmds.length; i++ ) {
  40. var cmd = new window[ cmds[ i ].type ](); // creates a new object of type "json.type"
  41. cmd.fromJSON( cmds[ i ] );
  42. this.cmdArray.push( cmd );
  43. }
  44. }
  45. };