SetColorCommand.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /**
  6. * @param editor Editor
  7. * @param object THREE.Object3D
  8. * @param attributeName string
  9. * @param newValue integer representing a hex color value
  10. * @constructor
  11. */
  12. var SetColorCommand = function ( editor, object, attributeName, newValue ) {
  13. Command.call( this, editor );
  14. this.type = 'SetColorCommand';
  15. this.name = 'Set ' + attributeName;
  16. this.updatable = true;
  17. this.object = object;
  18. this.attributeName = attributeName;
  19. this.oldValue = ( object !== undefined ) ? this.object[ this.attributeName ].getHex() : undefined;
  20. this.newValue = newValue;
  21. };
  22. SetColorCommand.prototype = {
  23. execute: function () {
  24. this.object[ this.attributeName ].setHex( this.newValue );
  25. this.editor.signals.objectChanged.dispatch( this.object );
  26. },
  27. undo: function () {
  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 = Command.prototype.toJSON.call( this );
  36. output.objectUuid = this.object.uuid;
  37. output.attributeName = this.attributeName;
  38. output.oldValue = this.oldValue;
  39. output.newValue = this.newValue;
  40. return output;
  41. },
  42. fromJSON: function ( json ) {
  43. Command.prototype.fromJSON.call( this, json );
  44. this.object = this.editor.objectByUuid( json.objectUuid );
  45. this.attributeName = json.attributeName;
  46. this.oldValue = json.oldValue;
  47. this.newValue = json.newValue;
  48. }
  49. };