CmdRemoveScript.js 1.3 KB

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