CmdSetColor.js 1.5 KB

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