SetColorCommand.js 1.5 KB

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