Skip to content

⬅️ Back to Table of Contents

📄 SetValueCommand.js

📊 Analysis Summary

Metric Count
🔧 Functions 5
🧱 Classes 1
📦 Imports 1

📚 Table of Contents

🛠️ File Location:

📂 editor/js/commands/SetValueCommand.js

📦 Imports

Name Source
Command ../Command.js

Functions

SetValueCommand.execute(): void

Returns: void

Calls:

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

        this.object[ this.attributeName ] = this.newValue;
        this.editor.signals.objectChanged.dispatch( this.object );
        // this.editor.signals.sceneGraphChanged.dispatch();

    }

SetValueCommand.undo(): void

Returns: void

Calls:

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

        this.object[ this.attributeName ] = this.oldValue;
        this.editor.signals.objectChanged.dispatch( this.object );
        // this.editor.signals.sceneGraphChanged.dispatch();

    }

SetValueCommand.update(cmd: any): void

Parameters:

  • cmd any

Returns: void

Code
update( cmd ) {

        this.newValue = cmd.newValue;

    }

SetValueCommand.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.objectUuid = this.object.uuid;
        output.attributeName = this.attributeName;
        output.oldValue = this.oldValue;
        output.newValue = this.newValue;

        return output;

    }

SetValueCommand.fromJSON(json: any): void

Parameters:

  • json any

Returns: void

Calls:

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

        super.fromJSON( json );

        this.attributeName = json.attributeName;
        this.oldValue = json.oldValue;
        this.newValue = json.newValue;
        this.object = this.editor.objectByUuid( json.objectUuid );

    }

Classes

SetValueCommand

Class Code
class SetValueCommand extends Command {

    /**
     * @param {Editor} editor
     * @param {THREE.Object3D|null} object
     * @param {string} attributeName
     * @param {number|string|boolean|Object|null} newValue
     * @constructor
     */
    constructor( editor, object = null, attributeName = '', newValue = null ) {

        super( editor );

        this.type = 'SetValueCommand';
        this.name = editor.strings.getKey( 'command/SetValue' ) + ': ' + attributeName;
        this.updatable = true;

        this.object = object;
        this.attributeName = attributeName;
        this.oldValue = ( object !== null ) ? object[ attributeName ] : null;
        this.newValue = newValue;

    }

    execute() {

        this.object[ this.attributeName ] = this.newValue;
        this.editor.signals.objectChanged.dispatch( this.object );
        // this.editor.signals.sceneGraphChanged.dispatch();

    }

    undo() {

        this.object[ this.attributeName ] = this.oldValue;
        this.editor.signals.objectChanged.dispatch( this.object );
        // this.editor.signals.sceneGraphChanged.dispatch();

    }

    update( cmd ) {

        this.newValue = cmd.newValue;

    }

    toJSON() {

        const output = super.toJSON( this );

        output.objectUuid = this.object.uuid;
        output.attributeName = this.attributeName;
        output.oldValue = this.oldValue;
        output.newValue = this.newValue;

        return output;

    }

    fromJSON( json ) {

        super.fromJSON( json );

        this.attributeName = json.attributeName;
        this.oldValue = json.oldValue;
        this.newValue = json.newValue;
        this.object = this.editor.objectByUuid( json.objectUuid );

    }

}

Methods

execute(): void
Code
execute() {

        this.object[ this.attributeName ] = this.newValue;
        this.editor.signals.objectChanged.dispatch( this.object );
        // this.editor.signals.sceneGraphChanged.dispatch();

    }
undo(): void
Code
undo() {

        this.object[ this.attributeName ] = this.oldValue;
        this.editor.signals.objectChanged.dispatch( this.object );
        // this.editor.signals.sceneGraphChanged.dispatch();

    }
update(cmd: any): void
Code
update( cmd ) {

        this.newValue = cmd.newValue;

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

        const output = super.toJSON( this );

        output.objectUuid = this.object.uuid;
        output.attributeName = this.attributeName;
        output.oldValue = this.oldValue;
        output.newValue = this.newValue;

        return output;

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

        super.fromJSON( json );

        this.attributeName = json.attributeName;
        this.oldValue = json.oldValue;
        this.newValue = json.newValue;
        this.object = this.editor.objectByUuid( json.objectUuid );

    }