You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.5 KiB
75 lines
1.5 KiB
import { Command } from '../Command.js';
|
|
|
|
/**
|
|
* @param editor Editor
|
|
* @param object THREE.Object3D
|
|
* @param attributeName string
|
|
* @param newValue number, string, boolean or object
|
|
* @constructor
|
|
*/
|
|
class SetValueCommand extends Command {
|
|
|
|
constructor( editor, object, attributeName, newValue ) {
|
|
|
|
super( editor );
|
|
|
|
this.type = 'SetValueCommand';
|
|
this.name = `Set ${attributeName}`;
|
|
this.updatable = true;
|
|
|
|
this.object = object;
|
|
this.attributeName = attributeName;
|
|
this.oldValue = ( object !== undefined ) ? object[ attributeName ] : undefined;
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export { SetValueCommand };
|
|
|