1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param editor Editor
- * @param object THREE.Object3D
- * @param script javascript object
- * @constructor
- */
- var AddScriptCommand = function ( editor, object, script ) {
- Command.call( this, editor );
- this.type = 'AddScriptCommand';
- this.name = 'Add Script';
- this.object = object;
- this.script = script;
- };
- AddScriptCommand.prototype = {
- execute: function () {
- if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
- this.editor.scripts[ this.object.uuid ] = [];
- }
- this.editor.scripts[ this.object.uuid ].push( this.script );
- this.editor.signals.scriptAdded.dispatch( this.script );
- },
- undo: function () {
- if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
- var index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
- if ( index !== - 1 ) {
- this.editor.scripts[ this.object.uuid ].splice( index, 1 );
- }
- this.editor.signals.scriptRemoved.dispatch( this.script );
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.script = this.script;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.script = json.script;
- this.object = this.editor.objectByUuid( json.objectUuid );
- }
- };
|