1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- import { Command } from '../Command.js';
- /**
- * @param editor Editor
- * @param object THREE.Object3D
- * @param attributeName string
- * @param newValue number, string, boolean or object
- * @constructor
- */
- var SetValueCommand = function ( editor, object, attributeName, newValue ) {
- Command.call( this, 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;
- };
- SetValueCommand.prototype = {
- execute: function () {
- this.object[ this.attributeName ] = this.newValue;
- this.editor.signals.objectChanged.dispatch( this.object );
- // this.editor.signals.sceneGraphChanged.dispatch();
- },
- undo: function () {
- this.object[ this.attributeName ] = this.oldValue;
- this.editor.signals.objectChanged.dispatch( this.object );
- // this.editor.signals.sceneGraphChanged.dispatch();
- },
- update: function ( cmd ) {
- this.newValue = cmd.newValue;
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.attributeName = this.attributeName;
- output.oldValue = this.oldValue;
- output.newValue = this.newValue;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.attributeName = json.attributeName;
- this.oldValue = json.oldValue;
- this.newValue = json.newValue;
- this.object = this.editor.objectByUuid( json.objectUuid );
- }
- };
- export { SetValueCommand };
|