SetScriptValueCommand.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { Command } from '../Command.js';
  2. /**
  3. * @param editor Editor
  4. * @param object THREE.Object3D
  5. * @param script javascript object
  6. * @param attributeName string
  7. * @param newValue string, object
  8. * @constructor
  9. */
  10. function SetScriptValueCommand( editor, object, script, attributeName, newValue ) {
  11. Command.call( this, editor );
  12. this.type = 'SetScriptValueCommand';
  13. this.name = 'Set Script.' + attributeName;
  14. this.updatable = true;
  15. this.object = object;
  16. this.script = script;
  17. this.attributeName = attributeName;
  18. this.oldValue = ( script !== undefined ) ? script[ this.attributeName ] : undefined;
  19. this.newValue = newValue;
  20. }
  21. SetScriptValueCommand.prototype = {
  22. execute: function () {
  23. this.script[ this.attributeName ] = this.newValue;
  24. this.editor.signals.scriptChanged.dispatch();
  25. },
  26. undo: function () {
  27. this.script[ this.attributeName ] = this.oldValue;
  28. this.editor.signals.scriptChanged.dispatch();
  29. },
  30. update: function ( cmd ) {
  31. this.newValue = cmd.newValue;
  32. },
  33. toJSON: function () {
  34. var output = Command.prototype.toJSON.call( this );
  35. output.objectUuid = this.object.uuid;
  36. output.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
  37. output.attributeName = this.attributeName;
  38. output.oldValue = this.oldValue;
  39. output.newValue = this.newValue;
  40. return output;
  41. },
  42. fromJSON: function ( json ) {
  43. Command.prototype.fromJSON.call( this, json );
  44. this.oldValue = json.oldValue;
  45. this.newValue = json.newValue;
  46. this.attributeName = json.attributeName;
  47. this.object = this.editor.objectByUuid( json.objectUuid );
  48. this.script = this.editor.scripts[ json.objectUuid ][ json.index ];
  49. }
  50. };
  51. export { SetScriptValueCommand };