SetValueCommand.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { Command } from '../Command.js';
  2. /**
  3. * @param editor Editor
  4. * @param object THREE.Object3D
  5. * @param attributeName string
  6. * @param newValue number, string, boolean or object
  7. * @constructor
  8. */
  9. function SetValueCommand( editor, object, attributeName, newValue ) {
  10. Command.call( this, editor );
  11. this.type = 'SetValueCommand';
  12. this.name = 'Set ' + attributeName;
  13. this.updatable = true;
  14. this.object = object;
  15. this.attributeName = attributeName;
  16. this.oldValue = ( object !== undefined ) ? object[ attributeName ] : undefined;
  17. this.newValue = newValue;
  18. }
  19. SetValueCommand.prototype = {
  20. execute: function () {
  21. this.object[ this.attributeName ] = this.newValue;
  22. this.editor.signals.objectChanged.dispatch( this.object );
  23. // this.editor.signals.sceneGraphChanged.dispatch();
  24. },
  25. undo: function () {
  26. this.object[ this.attributeName ] = this.oldValue;
  27. this.editor.signals.objectChanged.dispatch( this.object );
  28. // this.editor.signals.sceneGraphChanged.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.attributeName = this.attributeName;
  37. output.oldValue = this.oldValue;
  38. output.newValue = this.newValue;
  39. return output;
  40. },
  41. fromJSON: function ( json ) {
  42. Command.prototype.fromJSON.call( this, json );
  43. this.attributeName = json.attributeName;
  44. this.oldValue = json.oldValue;
  45. this.newValue = json.newValue;
  46. this.object = this.editor.objectByUuid( json.objectUuid );
  47. }
  48. };
  49. export { SetValueCommand };