CmdMultiCmds.js 1.4 KB

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