SetValueCommand.js 1.5 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. class SetValueCommand extends Command {
  10. constructor( editor, object, attributeName, newValue ) {
  11. super( editor );
  12. this.type = 'SetValueCommand';
  13. this.name = `Set ${attributeName}`;
  14. this.updatable = true;
  15. this.object = object;
  16. this.attributeName = attributeName;
  17. this.oldValue = ( object !== undefined ) ? object[ attributeName ] : undefined;
  18. this.newValue = newValue;
  19. }
  20. execute() {
  21. this.object[ this.attributeName ] = this.newValue;
  22. this.editor.signals.objectChanged.dispatch( this.object );
  23. // this.editor.signals.sceneGraphChanged.dispatch();
  24. }
  25. undo() {
  26. this.object[ this.attributeName ] = this.oldValue;
  27. this.editor.signals.objectChanged.dispatch( this.object );
  28. // this.editor.signals.sceneGraphChanged.dispatch();
  29. }
  30. update( cmd ) {
  31. this.newValue = cmd.newValue;
  32. }
  33. toJSON() {
  34. const output = super.toJSON( 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( json ) {
  42. super.fromJSON( 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 };