CmdMultiCmds.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Created by Daniel on 20.07.15.
  3. */
  4. CmdMultiCmds = function ( cmdArray ) {
  5. Cmd.call( this );
  6. this.type = 'CmdMultiCmds';
  7. this.cmdArray = cmdArray !== undefined ? cmdArray : [];
  8. };
  9. CmdMultiCmds.prototype = {
  10. execute: function () {
  11. this.editor.signals.sceneGraphChanged.active = false;
  12. for ( var i = 0; i < this.cmdArray.length; i++ ) {
  13. this.cmdArray[ i ].editor = this.editor;
  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.editor = this.editor;
  42. cmd.fromJSON( cmds[ i ] );
  43. this.cmdArray.push( cmd );
  44. }
  45. }
  46. };