CmdAddScript.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.objectUuid = object !== undefined ? object.uuid : undefined;
  10. this.script = script;
  11. };
  12. CmdAddScript.prototype = {
  13. execute: function () {
  14. if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
  15. this.editor.scripts[ this.object.uuid ] = [];
  16. }
  17. this.editor.scripts[ this.object.uuid ].push( this.script );
  18. this.editor.signals.scriptAdded.dispatch( this.script );
  19. },
  20. undo: function () {
  21. if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
  22. var index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
  23. if ( index !== - 1 ) {
  24. this.editor.scripts[ this.object.uuid ].splice( index, 1 );
  25. }
  26. this.editor.signals.scriptRemoved.dispatch( this.script );
  27. },
  28. toJSON: function () {
  29. var output = Cmd.prototype.toJSON.call( this );
  30. output.objectUuid = this.objectUuid;
  31. output.script = this.script;
  32. return output;
  33. },
  34. fromJSON: function ( json ) {
  35. Cmd.prototype.fromJSON.call( this, json );
  36. this.objectUuid = json.objectUuid;
  37. this.script = json.script;
  38. this.object = this.editor.objectByUuid( json.objectUuid );
  39. }
  40. };