CmdSetColor.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * @author dforrer / https://github.com/dforrer
  3. */
  4. /**
  5. * @param object THREE.Object3D
  6. * @param attributeName string
  7. * @param newValue integer representing a hex color value
  8. * @constructor
  9. */
  10. CmdSetColor = function ( object, attributeName, newValue ) {
  11. Cmd.call( this );
  12. this.type = 'CmdSetColor';
  13. this.name = 'Set ' + attributeName;
  14. this.updatable = true;
  15. this.object = object;
  16. this.attributeName = attributeName;
  17. this.oldValue = ( object !== undefined ) ? this.object[ this.attributeName ].getHex() : undefined;
  18. this.newValue = newValue;
  19. };
  20. CmdSetColor.prototype = {
  21. execute: function () {
  22. this.object[ this.attributeName ].setHex( this.newValue );
  23. this.editor.signals.objectChanged.dispatch( this.object );
  24. },
  25. undo: function () {
  26. this.object[ this.attributeName ].setHex( this.oldValue );
  27. this.editor.signals.objectChanged.dispatch( this.object );
  28. },
  29. update: function ( cmd ) {
  30. this.newValue = cmd.newValue;
  31. },
  32. toJSON: function () {
  33. var output = Cmd.prototype.toJSON.call( this );
  34. output.objectUuid = this.object.uuid;
  35. output.attributeName = this.attributeName;
  36. output.oldValue = this.oldValue;
  37. output.newValue = this.newValue;
  38. return output;
  39. },
  40. fromJSON: function ( json ) {
  41. Cmd.prototype.fromJSON.call( this, json );
  42. this.object = this.editor.objectByUuid( json.objectUuid );
  43. this.attributeName = json.attributeName;
  44. this.oldValue = json.oldValue;
  45. this.newValue = json.newValue;
  46. }
  47. };