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