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.
81 lines
1.4 KiB
81 lines
1.4 KiB
2 years ago
|
import { Command } from '../Command.js';
|
||
|
|
||
|
/**
|
||
|
* @param editor Editor
|
||
|
* @param object THREE.Object3D
|
||
|
* @param script javascript object
|
||
|
* @constructor
|
||
|
*/
|
||
|
class RemoveScriptCommand extends Command {
|
||
|
|
||
|
constructor( editor, object, script ) {
|
||
|
|
||
|
super( editor );
|
||
|
|
||
|
this.type = 'RemoveScriptCommand';
|
||
|
this.name = 'Remove Script';
|
||
|
|
||
|
this.object = object;
|
||
|
this.script = script;
|
||
|
if ( this.object && this.script ) {
|
||
|
|
||
|
this.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
execute() {
|
||
|
|
||
|
if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
|
||
|
|
||
|
if ( this.index !== - 1 ) {
|
||
|
|
||
|
this.editor.scripts[ this.object.uuid ].splice( this.index, 1 );
|
||
|
|
||
|
}
|
||
|
|
||
|
this.editor.signals.scriptRemoved.dispatch( this.script );
|
||
|
|
||
|
}
|
||
|
|
||
|
undo() {
|
||
|
|
||
|
if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
|
||
|
|
||
|
this.editor.scripts[ this.object.uuid ] = [];
|
||
|
|
||
|
}
|
||
|
|
||
|
this.editor.scripts[ this.object.uuid ].splice( this.index, 0, this.script );
|
||
|
|
||
|
this.editor.signals.scriptAdded.dispatch( this.script );
|
||
|
|
||
|
}
|
||
|
|
||
|
toJSON() {
|
||
|
|
||
|
const output = super.toJSON( this );
|
||
|
|
||
|
output.objectUuid = this.object.uuid;
|
||
|
output.script = this.script;
|
||
|
output.index = this.index;
|
||
|
|
||
|
return output;
|
||
|
|
||
|
}
|
||
|
|
||
|
fromJSON( json ) {
|
||
|
|
||
|
super.fromJSON( json );
|
||
|
|
||
|
this.script = json.script;
|
||
|
this.index = json.index;
|
||
|
this.object = this.editor.objectByUuid( json.objectUuid );
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
export { RemoveScriptCommand };
|