CmdRemoveScript.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * @author dforrer / https://github.com/dforrer
  3. */
  4. /**
  5. * @param object THREE.Object3D
  6. * @param script javascript object
  7. * @constructor
  8. */
  9. CmdRemoveScript = function ( object, script ) {
  10. Cmd.call( this );
  11. this.type = 'CmdRemoveScript';
  12. this.name = 'Remove Script';
  13. this.object = object;
  14. this.script = script;
  15. if ( this.object && this.script ) {
  16. this.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
  17. }
  18. };
  19. CmdRemoveScript.prototype = {
  20. execute: function () {
  21. if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
  22. if ( this.index !== - 1 ) {
  23. this.editor.scripts[ this.object.uuid ].splice( this.index, 1 );
  24. }
  25. this.editor.signals.scriptRemoved.dispatch( this.script );
  26. },
  27. undo: function () {
  28. if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
  29. this.editor.scripts[ this.object.uuid ] = [];
  30. }
  31. this.editor.scripts[ this.object.uuid ].splice( this.index, 0, this.script );
  32. this.editor.signals.scriptAdded.dispatch( this.script );
  33. },
  34. toJSON: function () {
  35. var output = Cmd.prototype.toJSON.call( this );
  36. output.objectUuid = this.object.uuid;
  37. output.script = this.script;
  38. output.index = this.index;
  39. return output;
  40. },
  41. fromJSON: function ( json ) {
  42. Cmd.prototype.fromJSON.call( this, json );
  43. this.script = json.script;
  44. this.index = json.index;
  45. this.object = this.editor.objectByUuid( json.objectUuid );
  46. }
  47. };