Przeglądaj źródła

this.editor is now available in every Cmd...-function

- previously **this.editor** was not available in the constructor of a
Cmd…
Daniel 9 lat temu
rodzic
commit
76fcc4634a

+ 9 - 1
editor/js/Cmd.js

@@ -2,7 +2,7 @@
  * Created by Daniel on 20.07.15.
  */
 
-Cmd = function () {
+Cmd = function ( editorRef ) {
 
 	this.id = -1;
 	this.serialized = false;
@@ -10,6 +10,14 @@ Cmd = function () {
 	this.type = '';
 	this.name = '';
 
+	if ( editorRef !== undefined ) {
+
+		Cmd.editor = editorRef;
+
+	}
+	this.editor = Cmd.editor;
+
+
 };
 
 Cmd.prototype.toJSON = function () {

+ 0 - 2
editor/js/CmdMultiCmds.js

@@ -21,7 +21,6 @@ CmdMultiCmds.prototype = {
 
 		for ( var i = 0; i < this.cmdArray.length; i++ ) {
 
-			this.cmdArray[ i ].editor = this.editor;
 			this.cmdArray[ i ].execute();
 
 		}
@@ -70,7 +69,6 @@ CmdMultiCmds.prototype = {
 		for ( var i = 0; i < cmds.length; i++ ) {
 
 			var cmd = new window[ cmds[ i ].type ]();	// creates a new object of type "json.type"
-			cmd.editor = this.editor;
 			cmd.fromJSON( cmds[ i ] );
 			this.cmdArray.push( cmd );
 

+ 4 - 6
editor/js/CmdSetScene.js

@@ -2,7 +2,7 @@
  * Created by Daniel on 20.07.15.
  */
 
-CmdSetScene = function ( oldScene, newScene ) {
+CmdSetScene = function ( newScene ) {
 
 	Cmd.call( this );
 
@@ -13,9 +13,9 @@ CmdSetScene = function ( oldScene, newScene ) {
 
 	if ( newScene !== undefined ) {
 
-		this.cmdArray.push( new CmdSetUuid( oldScene, newScene.uuid ) );
-		this.cmdArray.push( new CmdSetValue( oldScene, 'name', newScene.name ) );
-		this.cmdArray.push( new CmdSetValue( oldScene, 'userData', JSON.parse( JSON.stringify( newScene.userData ) ) ) );
+		this.cmdArray.push( new CmdSetUuid( this.editor.scene, newScene.uuid ) );
+		this.cmdArray.push( new CmdSetValue( this.editor.scene, 'name', newScene.name ) );
+		this.cmdArray.push( new CmdSetValue( this.editor.scene, 'userData', JSON.parse( JSON.stringify( newScene.userData ) ) ) );
 
 		while ( newScene.children.length > 0 ) {
 
@@ -35,7 +35,6 @@ CmdSetScene.prototype = {
 
 		for ( var i = 0; i < this.cmdArray.length; i ++ ) {
 
-			this.cmdArray[ i ].editor = this.editor;
 			this.cmdArray[ i ].execute();
 
 		}
@@ -84,7 +83,6 @@ CmdSetScene.prototype = {
 		for ( var i = 0; i < cmds.length; i ++ ) {
 
 			var cmd = new window[ cmds[ i ].type ]();	// creates a new object of type "json.type"
-			cmd.editor = this.editor;
 			cmd.fromJSON( cmds[ i ] );
 			this.cmdArray.push( cmd );
 

+ 1 - 1
editor/js/CmdSetScriptValue.js

@@ -18,6 +18,7 @@ CmdSetScriptValue = function ( object, script, attributeName, newValue, cursorPo
 	this.newValue = newValue;
 	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 	this.cursorPosition = cursorPosition; // Format {line: 2, ch: 3}
+	this.index = this.editor.scripts[ this.objectUuid ].indexOf( this.script );
 
 };
 
@@ -25,7 +26,6 @@ CmdSetScriptValue.prototype = {
 
 	execute: function () {
 
-		this.index = this.editor.scripts[ this.objectUuid ].indexOf( this.script );
 		this.script[ this.attributeName ] = this.newValue;
 
 		this.editor.signals.scriptChanged.dispatch();

+ 4 - 3
editor/js/History.js

@@ -13,6 +13,10 @@ History = function ( editor ) {
 
 	this.historyDisabled = false;
 
+	//Set editor-reference in Cmd
+
+	Cmd( editor );
+
 	// signals
 
 	var scope = this;
@@ -63,7 +67,6 @@ History.prototype = {
 			// the command is not updatable and is added as a new part of the history
 
 			this.undos.push( cmd );
-			cmd.editor = this.editor;
 			cmd.id = ++this.idCounter;
 
 		}
@@ -98,7 +101,6 @@ History.prototype = {
 
 				var json = cmd;
 				cmd = new window[ json.type ]();	// creates a new object of type "json.type"
-				cmd.editor = this.editor;
 				cmd.fromJSON( json );
 
 			}
@@ -136,7 +138,6 @@ History.prototype = {
 
 				var json = cmd;
 				cmd = new window[ json.type ]();	// creates a new object of type "json.type"
-				cmd.editor = this.editor;
 				cmd.fromJSON( json );
 
 			}

+ 5 - 5
editor/js/Loader.js

@@ -40,7 +40,7 @@ var Loader = function ( editor ) {
 					var loader = new THREE.AWDLoader();
 					var scene = loader.parse( event.target.result );
 
-					editor.execute( new CmdSetScene( editor.scene, scene ) );
+					editor.execute( new CmdSetScene( scene ) );
 
 				}, false );
 				reader.readAsArrayBuffer( file );
@@ -58,7 +58,7 @@ var Loader = function ( editor ) {
 					var loader = new THREE.BabylonLoader();
 					var scene = loader.parse( json );
 
-					editor.execute( new CmdSetScene( editor.scene, scene ) );
+					editor.execute( new CmdSetScene( scene ) );
 
 				}, false );
 				reader.readAsText( file );
@@ -371,7 +371,7 @@ var Loader = function ( editor ) {
 
 					var result = new THREE.VRMLLoader().parse( contents );
 
-					editor.execute( new CmdSetScene( editor.scene, result ) );
+					editor.execute( new CmdSetScene( result ) );
 
 				}, false );
 				reader.readAsText( file );
@@ -475,7 +475,7 @@ var Loader = function ( editor ) {
 
 			if ( result instanceof THREE.Scene ) {
 
-				editor.execute( new CmdSetScene( editor.scene, result ) );
+				editor.execute( new CmdSetScene( result ) );
 
 			} else {
 
@@ -491,7 +491,7 @@ var Loader = function ( editor ) {
 			var loader = new THREE.SceneLoader();
 			loader.parse( data, function ( result ) {
 
-				editor.execute( new CmdSetScene( editor.scene, result.scene ) );
+				editor.execute( new CmdSetScene( result.scene ) );
 
 			}, '' );
 

+ 1 - 1
test/unit/editor/TestCmdSetScene.js

@@ -24,7 +24,7 @@ test("Test for CmdSetScene (Undo and Redo)", function() {
 	scenes.map( function( scene ) {
 
 		var importedScene = importScene( scene.exportedData );
-		var cmd = new CmdSetScene( editor.scene, importedScene );
+		var cmd = new CmdSetScene( importedScene );
 		cmd.updatable = false;
 		editor.execute( cmd );