SetValueCommand.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /**
  6. * @param editor Editor
  7. * @param object THREE.Object3D
  8. * @param attributeName string
  9. * @param newValue number, string, boolean or object
  10. * @constructor
  11. */
  12. var SetValueCommand = function ( editor, object, attributeName, newValue ) {
  13. Command.call( this, editor );
  14. this.type = 'SetValueCommand';
  15. this.name = 'Set ' + attributeName;
  16. this.updatable = true;
  17. this.object = object;
  18. this.attributeName = attributeName;
  19. this.oldValue = ( object !== undefined ) ? object[ attributeName ] : undefined;
  20. this.newValue = newValue;
  21. };
  22. SetValueCommand.prototype = {
  23. execute: function () {
  24. this.object[ this.attributeName ] = this.newValue;
  25. this.editor.signals.objectChanged.dispatch( this.object );
  26. // this.editor.signals.sceneGraphChanged.dispatch();
  27. },
  28. undo: function () {
  29. this.object[ this.attributeName ] = this.oldValue;
  30. this.editor.signals.objectChanged.dispatch( this.object );
  31. // this.editor.signals.sceneGraphChanged.dispatch();
  32. },
  33. update: function ( cmd ) {
  34. this.newValue = cmd.newValue;
  35. },
  36. toJSON: function () {
  37. var output = Command.prototype.toJSON.call( this );
  38. output.objectUuid = this.object.uuid;
  39. output.attributeName = this.attributeName;
  40. output.oldValue = this.oldValue;
  41. output.newValue = this.newValue;
  42. return output;
  43. },
  44. fromJSON: function ( json ) {
  45. Command.prototype.fromJSON.call( this, json );
  46. this.attributeName = json.attributeName;
  47. this.oldValue = json.oldValue;
  48. this.newValue = json.newValue;
  49. this.object = this.editor.objectByUuid( json.objectUuid );
  50. }
  51. };