CmdSetValue.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.name = 'Set ' + attributeName;
  8. this.updatable = true;
  9. this.object = object;
  10. this.attributeName = attributeName;
  11. this.oldValue = object !== undefined ? object[ attributeName ] : undefined;
  12. this.newValue = newValue;
  13. this.objectUuid = object !== undefined ? object.uuid : undefined;
  14. };
  15. CmdSetValue.prototype = {
  16. execute: function () {
  17. this.object[ this.attributeName ] = this.newValue;
  18. this.editor.signals.objectChanged.dispatch( this.object );
  19. this.editor.signals.sceneGraphChanged.dispatch();
  20. this.editor.signals.updateSidebar.dispatch();
  21. },
  22. undo: function () {
  23. this.object[ this.attributeName ] = this.oldValue;
  24. this.editor.signals.objectChanged.dispatch( this.object );
  25. this.editor.signals.sceneGraphChanged.dispatch();
  26. this.editor.signals.updateSidebar.dispatch();
  27. },
  28. update: function ( cmd ) {
  29. this.newValue = cmd.newValue;
  30. },
  31. toJSON: function () {
  32. var output = Cmd.prototype.toJSON.call( this );
  33. output.objectUuid = this.objectUuid;
  34. output.attributeName = this.attributeName;
  35. output.oldValue = this.oldValue;
  36. output.newValue = this.newValue;
  37. return output;
  38. },
  39. fromJSON: function ( json ) {
  40. Cmd.prototype.fromJSON.call( this, json );
  41. this.objectUuid = json.objectUuid;
  42. this.attributeName = json.attributeName;
  43. this.oldValue = json.oldValue;
  44. this.newValue = json.newValue;
  45. this.object = this.editor.objectByUuid( json.objectUuid );
  46. }
  47. };