You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
1.4 KiB
JavaScript
86 lines
1.4 KiB
JavaScript
import { Command } from '../Command.js';
|
|
|
|
class MultiCmdsCommand extends Command {
|
|
|
|
/**
|
|
* @param {Editor} editor
|
|
* @param {Array<Command>} [cmdArray=[]]
|
|
* @constructor
|
|
*/
|
|
constructor( editor, cmdArray = [] ) {
|
|
|
|
super( editor );
|
|
|
|
this.type = 'MultiCmdsCommand';
|
|
this.name = editor.strings.getKey( 'command/MultiCmds' );
|
|
|
|
this.cmdArray = cmdArray;
|
|
|
|
}
|
|
|
|
execute() {
|
|
|
|
this.editor.signals.sceneGraphChanged.active = false;
|
|
|
|
for ( let i = 0; i < this.cmdArray.length; i ++ ) {
|
|
|
|
this.cmdArray[ i ].execute();
|
|
|
|
}
|
|
|
|
this.editor.signals.sceneGraphChanged.active = true;
|
|
this.editor.signals.sceneGraphChanged.dispatch();
|
|
|
|
}
|
|
|
|
undo() {
|
|
|
|
this.editor.signals.sceneGraphChanged.active = false;
|
|
|
|
for ( let i = this.cmdArray.length - 1; i >= 0; i -- ) {
|
|
|
|
this.cmdArray[ i ].undo();
|
|
|
|
}
|
|
|
|
this.editor.signals.sceneGraphChanged.active = true;
|
|
this.editor.signals.sceneGraphChanged.dispatch();
|
|
|
|
}
|
|
|
|
toJSON() {
|
|
|
|
const output = super.toJSON( this );
|
|
|
|
const cmds = [];
|
|
for ( let i = 0; i < this.cmdArray.length; i ++ ) {
|
|
|
|
cmds.push( this.cmdArray[ i ].toJSON() );
|
|
|
|
}
|
|
|
|
output.cmds = cmds;
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
fromJSON( json ) {
|
|
|
|
super.fromJSON( json );
|
|
|
|
const cmds = json.cmds;
|
|
for ( let i = 0; i < cmds.length; i ++ ) {
|
|
|
|
const cmd = new window[ cmds[ i ].type ](); // creates a new object of type "json.type"
|
|
cmd.fromJSON( cmds[ i ] );
|
|
this.cmdArray.push( cmd );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export { MultiCmdsCommand };
|