CmdRemoveScript.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Created by Daniel on 20.07.15.
  3. */
  4. CmdRemoveScript = function ( object, script ) {
  5. Cmd.call( this );
  6. this.type = 'CmdRemoveScript';
  7. this.name = 'Remove Script';
  8. this.object = object;
  9. this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
  10. this.script = script;
  11. };
  12. CmdRemoveScript.prototype = {
  13. execute: function () {
  14. if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
  15. this.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
  16. if ( this.index !== - 1 ) {
  17. this.editor.scripts[ this.object.uuid ].splice( this.index, 1 );
  18. }
  19. this.editor.signals.scriptRemoved.dispatch( this.script );
  20. },
  21. undo: function () {
  22. if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
  23. this.editor.scripts[ this.object.uuid ] = [];
  24. }
  25. this.editor.scripts[ this.object.uuid ].splice( this.index, 0, this.script );
  26. this.editor.signals.scriptAdded.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. output.index = this.index;
  33. return output;
  34. },
  35. fromJSON: function ( json ) {
  36. Cmd.prototype.fromJSON.call( this, json );
  37. this.objectUuid = json.objectUuid;
  38. this.script = json.script;
  39. this.index = json.index;
  40. this.object = this.editor.objectByUuid( json.objectUuid );
  41. }
  42. };