CmdSetValue.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. };
  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.object.uuid;
  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.attributeName = json.attributeName;
  41. this.oldValue = json.oldValue;
  42. this.newValue = json.newValue;
  43. this.object = this.editor.objectByUuid( json.objectUuid );
  44. }
  45. };