CmdSetValue.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Created by Daniel on 21.07.15.
  3. */
  4. CmdSetValue = function ( object, attributeName, newValue ) {
  5. Cmd.call( this );
  6. this.type = 'CmdSetValue';
  7. this.updatable = true;
  8. this.object = object;
  9. this.attributeName = attributeName;
  10. this.oldValue = object !== undefined ? object[ attributeName ] : undefined;
  11. this.newValue = newValue;
  12. this.objectUuid = object !== undefined ? object.uuid : undefined;
  13. };
  14. CmdSetValue.prototype = {
  15. execute: function () {
  16. this.object[ this.attributeName ] = this.newValue;
  17. this.editor.signals.objectChanged.dispatch( this.object );
  18. this.editor.signals.sceneGraphChanged.dispatch();
  19. this.editor.signals.updateSidebar.dispatch();
  20. },
  21. undo: function () {
  22. this.object[ this.attributeName ] = this.oldValue;
  23. this.editor.signals.objectChanged.dispatch( this.object );
  24. this.editor.signals.sceneGraphChanged.dispatch();
  25. this.editor.signals.updateSidebar.dispatch();
  26. },
  27. update: function ( cmd ) {
  28. this.newValue = cmd.newValue;
  29. },
  30. toJSON: function () {
  31. var output = Cmd.prototype.toJSON.call( this );
  32. output.objectUuid = this.objectUuid;
  33. output.attributeName = this.attributeName;
  34. output.oldValue = this.oldValue;
  35. output.newValue = this.newValue;
  36. return output;
  37. },
  38. fromJSON: function ( json ) {
  39. Cmd.prototype.fromJSON.call( this, json );
  40. this.objectUuid = json.objectUuid;
  41. this.attributeName = json.attributeName;
  42. this.oldValue = json.oldValue;
  43. this.newValue = json.newValue;
  44. this.object = this.editor.objectByUuid( json.objectUuid );
  45. }
  46. };