Skip to content

Commit

Permalink
Editor: Make editor parameter of Command class mandatory.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Jun 23, 2019
1 parent 8e45e2b commit a8a6686
Show file tree
Hide file tree
Showing 50 changed files with 236 additions and 228 deletions.
12 changes: 6 additions & 6 deletions editor/docs/Implementing additional commands for undo-redo.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ Then there are separate commands for:
Every command needs a constructor. In the constructor

```javascript

var DoSomethingCommand = function () {

Command.call( this ); // Required: Call default constructor
var DoSomethingCommand = function ( editor ) {

Command.call( this, editor ); // Required: Call default constructor

this.type = 'DoSomethingCommand'; // Required: has to match the object-name!
this.name = 'Set/Do/Update Something'; // Required: description of the command, used in Sidebar.History

// TODO: store all the relevant information needed to
// TODO: store all the relevant information needed to
// restore the old and the new state

};
Expand All @@ -50,13 +50,13 @@ DoSomethingCommand.prototype = {

execute: function () {

// TODO: apply changes to 'object' to reach the new state
// TODO: apply changes to 'object' to reach the new state

},

undo: function () {

// TODO: restore 'object' to old state
// TODO: restore 'object' to old state

},

Expand Down
4 changes: 2 additions & 2 deletions editor/docs/Writing unit tests for undo-redo commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test("Test DoSomethingCommand (Undo and Redo)", function() {
// var perspectiveCamera = aPerspectiveCamera( 'Name your perspectiveCamera' );

// in most cases you'll need to add the object to work with
editor.execute( new AddObjectCommand( box ) );
editor.execute( new AddObjectCommand( editor, box ) );


// your test begins here...
Expand All @@ -91,4 +91,4 @@ Finally, perform `editor.redo()` and verify if the values are as expected.

### 4. Execute the test ###

Open the editor's unit test suite `test/unit/unittests_editor.html` in your browser and check the results from the test framework.
Open the editor's unit test suite `test/unit/unittests_editor.html` in your browser and check the results from the test framework.
13 changes: 3 additions & 10 deletions editor/js/Command.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,19 @@
*/

/**
* @param editorRef pointer to main editor object used to initialize
* @param editor pointer to main editor object used to initialize
* each command object with a reference to the editor
* @constructor
*/

var Command = function ( editorRef ) {
var Command = function ( editor ) {

this.id = - 1;
this.inMemory = false;
this.updatable = false;
this.type = '';
this.name = '';

if ( editorRef !== undefined ) {

Command.editor = editorRef;

}
this.editor = Command.editor;

this.editor = editor;

};

Expand Down
4 changes: 0 additions & 4 deletions editor/js/History.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ History = function ( editor ) {
this.historyDisabled = false;
this.config = editor.config;

//Set editor-reference in Command

Command( editor );

// signals

var scope = this;
Expand Down
50 changes: 25 additions & 25 deletions editor/js/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var Loader = function ( editor ) {
var loader = new THREE.TDSLoader();
var object = loader.parse( event.target.result );

editor.execute( new AddObjectCommand( object ) );
editor.execute( new AddObjectCommand( editor, object ) );

}, false );
reader.readAsArrayBuffer( file );
Expand All @@ -80,7 +80,7 @@ var Loader = function ( editor ) {
var loader = new THREE.AMFLoader();
var amfobject = loader.parse( event.target.result );

editor.execute( new AddObjectCommand( amfobject ) );
editor.execute( new AddObjectCommand( editor, amfobject ) );

}, false );
reader.readAsArrayBuffer( file );
Expand All @@ -94,7 +94,7 @@ var Loader = function ( editor ) {
var loader = new THREE.AWDLoader();
var scene = loader.parse( event.target.result );

editor.execute( new SetSceneCommand( scene ) );
editor.execute( new SetSceneCommand( editor, scene ) );

}, false );
reader.readAsArrayBuffer( file );
Expand All @@ -111,7 +111,7 @@ var Loader = function ( editor ) {
var loader = new THREE.BabylonLoader();
var scene = loader.parse( json );

editor.execute( new SetSceneCommand( scene ) );
editor.execute( new SetSceneCommand( editor, scene ) );

}, false );
reader.readAsText( file );
Expand All @@ -133,7 +133,7 @@ var Loader = function ( editor ) {
var mesh = new THREE.Mesh( geometry, material );
mesh.name = filename;

editor.execute( new AddObjectCommand( mesh ) );
editor.execute( new AddObjectCommand( editor, mesh ) );

}, false );
reader.readAsText( file );
Expand All @@ -160,7 +160,7 @@ var Loader = function ( editor ) {
var mesh = new THREE.Mesh( geometry, material );
mesh.name = filename;

editor.execute( new AddObjectCommand( mesh ) );
editor.execute( new AddObjectCommand( editor, mesh ) );

} );

Expand All @@ -181,7 +181,7 @@ var Loader = function ( editor ) {
collada.scene.name = filename;

editor.addAnimation( collada.scene, collada.animations );
editor.execute( new AddObjectCommand( collada.scene ) );
editor.execute( new AddObjectCommand( editor, collada.scene ) );

}, false );
reader.readAsText( file );
Expand All @@ -198,7 +198,7 @@ var Loader = function ( editor ) {
var object = loader.parse( contents );

editor.addAnimation( object, object.animations );
editor.execute( new AddObjectCommand( object ) );
editor.execute( new AddObjectCommand( editor, object ) );

}, false );
reader.readAsArrayBuffer( file );
Expand All @@ -221,7 +221,7 @@ var Loader = function ( editor ) {
scene.name = filename;

editor.addAnimation( scene, result.animations );
editor.execute( new AddObjectCommand( scene ) );
editor.execute( new AddObjectCommand( editor, scene ) );

} );

Expand Down Expand Up @@ -254,7 +254,7 @@ var Loader = function ( editor ) {
scene.name = filename;

editor.addAnimation( scene, result.animations );
editor.execute( new AddObjectCommand( scene ) );
editor.execute( new AddObjectCommand( editor, scene ) );

} );

Expand Down Expand Up @@ -329,7 +329,7 @@ var Loader = function ( editor ) {

collada.scene.name = filename;

editor.execute( new AddObjectCommand( collada.scene ) );
editor.execute( new AddObjectCommand( editor, collada.scene ) );

}, false );
reader.readAsArrayBuffer( file );
Expand All @@ -353,7 +353,7 @@ var Loader = function ( editor ) {
mesh.name = filename;

editor.addAnimation( mesh, geometry.animations );
editor.execute( new AddObjectCommand( mesh ) );
editor.execute( new AddObjectCommand( editor, mesh ) );

}, false );
reader.readAsArrayBuffer( file );
Expand All @@ -369,7 +369,7 @@ var Loader = function ( editor ) {
var object = new THREE.OBJLoader().parse( contents );
object.name = filename;

editor.execute( new AddObjectCommand( object ) );
editor.execute( new AddObjectCommand( editor, object ) );

}, false );
reader.readAsText( file );
Expand All @@ -386,7 +386,7 @@ var Loader = function ( editor ) {
var loader = new THREE.PlayCanvasLoader();
var object = loader.parse( json );

editor.execute( new AddObjectCommand( object ) );
editor.execute( new AddObjectCommand( editor, object ) );

}, false );
reader.readAsText( file );
Expand All @@ -408,7 +408,7 @@ var Loader = function ( editor ) {
var mesh = new THREE.Mesh( geometry, material );
mesh.name = filename;

editor.execute( new AddObjectCommand( mesh ) );
editor.execute( new AddObjectCommand( editor, mesh ) );

}, false );
reader.readAsArrayBuffer( file );
Expand All @@ -430,7 +430,7 @@ var Loader = function ( editor ) {
var mesh = new THREE.Mesh( geometry, material );
mesh.name = filename;

editor.execute( new AddObjectCommand( mesh ) );
editor.execute( new AddObjectCommand( editor, mesh ) );

}, false );

Expand Down Expand Up @@ -485,7 +485,7 @@ var Loader = function ( editor ) {

}

editor.execute( new AddObjectCommand( group ) );
editor.execute( new AddObjectCommand( editor, group ) );

}, false );
reader.readAsText( file );
Expand All @@ -507,7 +507,7 @@ var Loader = function ( editor ) {
var mesh = new THREE.Mesh( geometry, material );
mesh.name = filename;

editor.execute( new AddObjectCommand( mesh ) );
editor.execute( new AddObjectCommand( editor, mesh ) );

}, false );
reader.readAsText( file );
Expand All @@ -522,7 +522,7 @@ var Loader = function ( editor ) {

var result = new THREE.VRMLLoader().parse( contents );

editor.execute( new SetSceneCommand( result ) );
editor.execute( new SetSceneCommand( editor, result ) );

}, false );
reader.readAsText( file );
Expand Down Expand Up @@ -579,7 +579,7 @@ var Loader = function ( editor ) {

var mesh = new THREE.Mesh( result );

editor.execute( new AddObjectCommand( mesh ) );
editor.execute( new AddObjectCommand( editor, mesh ) );

break;

Expand All @@ -598,11 +598,11 @@ var Loader = function ( editor ) {

if ( result.isScene ) {

editor.execute( new SetSceneCommand( result ) );
editor.execute( new SetSceneCommand( editor, result ) );

} else {

editor.execute( new AddObjectCommand( result ) );
editor.execute( new AddObjectCommand( editor, result ) );

}

Expand Down Expand Up @@ -643,7 +643,7 @@ var Loader = function ( editor ) {

var materials = new THREE.MTLLoader().parse( zip.file( 'materials.mtl' ).asText() );
var object = new THREE.OBJLoader().setMaterials( materials ).parse( zip.file( 'model.obj' ).asText() );
editor.execute( new AddObjectCommand( object ) );
editor.execute( new AddObjectCommand( editor, object ) );

}

Expand Down Expand Up @@ -678,7 +678,7 @@ var Loader = function ( editor ) {
var loader = new THREE.FBXLoader( manager );
var object = loader.parse( file.asArrayBuffer() );

editor.execute( new AddObjectCommand( object ) );
editor.execute( new AddObjectCommand( editor, object ) );

break;

Expand All @@ -690,7 +690,7 @@ var Loader = function ( editor ) {
var scene = result.scene;

editor.addAnimation( scene, result.animations );
editor.execute( new AddObjectCommand( scene ) );
editor.execute( new AddObjectCommand( editor, scene ) );

} );

Expand Down
Loading

0 comments on commit a8a6686

Please sign in to comment.