Skip to content

⬅️ Back to Table of Contents

📄 SetUuidCommand.js

📊 Analysis Summary

Metric Count
🔧 Functions 4
🧱 Classes 1
📦 Imports 1

📚 Table of Contents

🛠️ File Location:

📂 editor/js/commands/SetUuidCommand.js

📦 Imports

Name Source
Command ../Command.js

Functions

SetUuidCommand.execute(): void

Returns: void

Calls:

  • this.editor.signals.objectChanged.dispatch
  • this.editor.signals.sceneGraphChanged.dispatch
Code
execute() {

        this.object.uuid = this.newUuid;
        this.editor.signals.objectChanged.dispatch( this.object );
        this.editor.signals.sceneGraphChanged.dispatch();

    }

SetUuidCommand.undo(): void

Returns: void

Calls:

  • this.editor.signals.objectChanged.dispatch
  • this.editor.signals.sceneGraphChanged.dispatch
Code
undo() {

        this.object.uuid = this.oldUuid;
        this.editor.signals.objectChanged.dispatch( this.object );
        this.editor.signals.sceneGraphChanged.dispatch();

    }

SetUuidCommand.toJSON(): { type: string; id: number; name: string; }

Returns: { type: string; id: number; name: string; }

Calls:

  • super.toJSON
Code
toJSON() {

        const output = super.toJSON( this );

        output.oldUuid = this.oldUuid;
        output.newUuid = this.newUuid;

        return output;

    }

SetUuidCommand.fromJSON(json: any): void

Parameters:

  • json any

Returns: void

Calls:

  • super.fromJSON
  • this.editor.objectByUuid
Code
fromJSON( json ) {

        super.fromJSON( json );

        this.oldUuid = json.oldUuid;
        this.newUuid = json.newUuid;
        this.object = this.editor.objectByUuid( json.oldUuid );

        if ( this.object === undefined ) {

            this.object = this.editor.objectByUuid( json.newUuid );

        }

    }

Classes

SetUuidCommand

Class Code
class SetUuidCommand extends Command {

    /**
     * @param {Editor} editor
     * @param {THREE.Object3D|null} object
     * @param {string|null} newUuid
     * @constructor
     */
    constructor( editor, object = null, newUuid = null ) {

        super( editor );

        this.type = 'SetUuidCommand';
        this.name = editor.strings.getKey( 'command/SetUuid' );

        this.object = object;

        this.oldUuid = ( object !== null ) ? object.uuid : null;
        this.newUuid = newUuid;

    }

    execute() {

        this.object.uuid = this.newUuid;
        this.editor.signals.objectChanged.dispatch( this.object );
        this.editor.signals.sceneGraphChanged.dispatch();

    }

    undo() {

        this.object.uuid = this.oldUuid;
        this.editor.signals.objectChanged.dispatch( this.object );
        this.editor.signals.sceneGraphChanged.dispatch();

    }

    toJSON() {

        const output = super.toJSON( this );

        output.oldUuid = this.oldUuid;
        output.newUuid = this.newUuid;

        return output;

    }

    fromJSON( json ) {

        super.fromJSON( json );

        this.oldUuid = json.oldUuid;
        this.newUuid = json.newUuid;
        this.object = this.editor.objectByUuid( json.oldUuid );

        if ( this.object === undefined ) {

            this.object = this.editor.objectByUuid( json.newUuid );

        }

    }

}

Methods

execute(): void
Code
execute() {

        this.object.uuid = this.newUuid;
        this.editor.signals.objectChanged.dispatch( this.object );
        this.editor.signals.sceneGraphChanged.dispatch();

    }
undo(): void
Code
undo() {

        this.object.uuid = this.oldUuid;
        this.editor.signals.objectChanged.dispatch( this.object );
        this.editor.signals.sceneGraphChanged.dispatch();

    }
toJSON(): { type: string; id: number; name: string; }
Code
toJSON() {

        const output = super.toJSON( this );

        output.oldUuid = this.oldUuid;
        output.newUuid = this.newUuid;

        return output;

    }
fromJSON(json: any): void
Code
fromJSON( json ) {

        super.fromJSON( json );

        this.oldUuid = json.oldUuid;
        this.newUuid = json.newUuid;
        this.object = this.editor.objectByUuid( json.oldUuid );

        if ( this.object === undefined ) {

            this.object = this.editor.objectByUuid( json.newUuid );

        }

    }