CmdAddScript.js 1.3 KB

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