SetColorCommand.js 1.7 KB

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