123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- /**
- * Created by Daniel on 20.07.15.
- */
- CmdMoveObject = function ( object, newParent, newBefore ) {
- Cmd.call( this );
- this.type = 'CmdMoveObject';
- this.name = 'Move Object';
- this.object = object;
- this.oldParent = ( object !== undefined ) ? object.parent : undefined;
- this.oldIndex = ( this.oldParent !== undefined ) ? this.oldParent.children.indexOf( this.object ) : undefined;
- this.newParent = newParent;
- if ( newBefore !== undefined ) {
- this.newIndex = ( newParent !== undefined ) ? newParent.children.indexOf( newBefore ) : undefined;
- } else {
- this.newIndex = ( newParent !== undefined ) ? newParent.children.length : undefined;
- }
- if ( this.oldParent === this.newParent && this.newIndex > this.oldIndex ) {
- this.newIndex --;
- }
- this.newBefore = newBefore;
- };
- CmdMoveObject.prototype = {
- execute: function () {
- this.oldParent.remove( this.object );
- var children = this.newParent.children;
- children.splice( this.newIndex, 0, this.object );
- this.object.parent = this.newParent;
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- undo: function () {
- this.newParent.remove( this.object );
- var children = this.oldParent.children;
- children.splice( this.oldIndex, 0, this.object );
- this.object.parent = this.oldParent;
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- toJSON: function () {
- var output = Cmd.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.newParentUuid = this.newParent.uuid;
- output.oldParentUuid = this.oldParent.uuid;
- output.newIndex = this.newIndex;
- output.oldIndex = this.oldIndex;
- return output;
- },
- fromJSON: function ( json ) {
- Cmd.prototype.fromJSON.call( this, json );
- this.object = this.editor.objectByUuid( json.objectUuid );
- this.oldParent = this.editor.objectByUuid( json.oldParentUuid );
- if ( this.oldParent === undefined ) {
- this.oldParent = this.editor.scene;
- }
- this.newParent = this.editor.objectByUuid( json.newParentUuid );
- if ( this.newParent === undefined ) {
- this.newParent = this.editor.scene;
- }
- this.newIndex = json.newIndex;
- this.oldIndex = json.oldIndex;
- }
- };
|