CmdSetUuid.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Created by Daniel on 21.07.15.
  3. */
  4. CmdSetUuid = function ( object, newUuid ) {
  5. Cmd.call( this );
  6. this.type = 'CmdSetUuid';
  7. this.name = 'Update UUID';
  8. this.object = object;
  9. this.oldUuid = ( object !== undefined ) ? object.uuid : undefined;
  10. this.newUuid = newUuid;
  11. };
  12. CmdSetUuid.prototype = {
  13. execute: function () {
  14. this.object.uuid = this.newUuid;
  15. this.editor.signals.objectChanged.dispatch( this.object );
  16. this.editor.signals.sceneGraphChanged.dispatch();
  17. },
  18. undo: function () {
  19. this.object.uuid = this.oldUuid;
  20. this.editor.signals.objectChanged.dispatch( this.object );
  21. this.editor.signals.sceneGraphChanged.dispatch();
  22. },
  23. toJSON: function () {
  24. var output = Cmd.prototype.toJSON.call( this );
  25. output.oldUuid = this.oldUuid;
  26. output.newUuid = this.newUuid;
  27. return output;
  28. },
  29. fromJSON: function ( json ) {
  30. Cmd.prototype.fromJSON.call( this, json );
  31. this.oldUuid = json.oldUuid;
  32. this.newUuid = json.newUuid;
  33. this.object = this.editor.objectByUuid( json.oldUuid );
  34. if ( this.object === undefined ) {
  35. this.object = this.editor.objectByUuid( json.newUuid );
  36. }
  37. }
  38. };