CmdAddScript.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * Created by Daniel on 20.07.15.
  3. */
  4. CmdAddScript = function ( object, script ) {
  5. Cmd.call( this );
  6. this.type = 'CmdAddScript';
  7. this.name = 'Add Script';
  8. this.object = object;
  9. this.script = script;
  10. };
  11. CmdAddScript.prototype = {
  12. execute: function () {
  13. if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
  14. this.editor.scripts[ this.object.uuid ] = [];
  15. }
  16. this.editor.scripts[ this.object.uuid ].push( this.script );
  17. this.editor.signals.scriptAdded.dispatch( this.script );
  18. },
  19. undo: function () {
  20. if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
  21. var index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
  22. if ( index !== - 1 ) {
  23. this.editor.scripts[ this.object.uuid ].splice( index, 1 );
  24. }
  25. this.editor.signals.scriptRemoved.dispatch( this.script );
  26. },
  27. toJSON: function () {
  28. var output = Cmd.prototype.toJSON.call( this );
  29. output.objectUuid = this.object.uuid;
  30. output.script = this.script;
  31. return output;
  32. },
  33. fromJSON: function ( json ) {
  34. Cmd.prototype.fromJSON.call( this, json );
  35. this.script = json.script;
  36. this.object = this.editor.objectByUuid( json.objectUuid );
  37. }
  38. };