CmdSetUuid.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. this.editor.signals.updateSidebar.dispatch();
  18. },
  19. undo: function () {
  20. this.object.uuid = this.oldUuid;
  21. this.editor.signals.objectChanged.dispatch( this.object );
  22. this.editor.signals.sceneGraphChanged.dispatch();
  23. this.editor.signals.updateSidebar.dispatch();
  24. },
  25. toJSON: function () {
  26. var output = Cmd.prototype.toJSON.call( this );
  27. output.oldUuid = this.oldUuid;
  28. output.newUuid = this.newUuid;
  29. return output;
  30. },
  31. fromJSON: function ( json ) {
  32. Cmd.prototype.fromJSON.call( this, json );
  33. this.oldUuid = json.oldUuid;
  34. this.newUuid = json.newUuid;
  35. this.object = this.editor.objectByUuid( json.oldUuid );
  36. if ( this.object === undefined ) {
  37. this.object = this.editor.objectByUuid( json.newUuid );
  38. }
  39. }
  40. };