SetValueCommand.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * @author dforrer / https://github.com/dforrer
  3. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4. */
  5. import { Command } from '../Command.js';
  6. /**
  7. * @param editor Editor
  8. * @param object THREE.Object3D
  9. * @param attributeName string
  10. * @param newValue number, string, boolean or object
  11. * @constructor
  12. */
  13. var SetValueCommand = function ( editor, object, attributeName, newValue ) {
  14. Command.call( this, editor );
  15. this.type = 'SetValueCommand';
  16. this.name = 'Set ' + attributeName;
  17. this.updatable = true;
  18. this.object = object;
  19. this.attributeName = attributeName;
  20. this.oldValue = ( object !== undefined ) ? object[ attributeName ] : undefined;
  21. this.newValue = newValue;
  22. };
  23. SetValueCommand.prototype = {
  24. execute: function () {
  25. this.object[ this.attributeName ] = this.newValue;
  26. this.editor.signals.objectChanged.dispatch( this.object );
  27. // this.editor.signals.sceneGraphChanged.dispatch();
  28. },
  29. undo: function () {
  30. this.object[ this.attributeName ] = this.oldValue;
  31. this.editor.signals.objectChanged.dispatch( this.object );
  32. // this.editor.signals.sceneGraphChanged.dispatch();
  33. },
  34. update: function ( cmd ) {
  35. this.newValue = cmd.newValue;
  36. },
  37. toJSON: function () {
  38. var output = Command.prototype.toJSON.call( this );
  39. output.objectUuid = this.object.uuid;
  40. output.attributeName = this.attributeName;
  41. output.oldValue = this.oldValue;
  42. output.newValue = this.newValue;
  43. return output;
  44. },
  45. fromJSON: function ( json ) {
  46. Command.prototype.fromJSON.call( this, json );
  47. this.attributeName = json.attributeName;
  48. this.oldValue = json.oldValue;
  49. this.newValue = json.newValue;
  50. this.object = this.editor.objectByUuid( json.objectUuid );
  51. }
  52. };
  53. export { SetValueCommand };