diff --git a/editor/docs/Implementing additional commands for undo-redo.md b/editor/docs/Implementing additional commands for undo-redo.md index 4f7fae4f5186a511dabedd982e545095dceb4636..206bcffafaed1962ac233bedec2042ea4eec1c7b 100644 --- a/editor/docs/Implementing additional commands for undo-redo.md +++ b/editor/docs/Implementing additional commands for undo-redo.md @@ -12,7 +12,7 @@ It would also be possible to only store the difference between the old and the n **Before implementing your own command you should look if you can't reuse one of the already existing ones.** -For numbers, strings or booleans the CmdSet...Value-commands can be used. +For numbers, strings or booleans the Set...ValueCommand-commands can be used. Then there are separate commands for: - setting a color property (THREE.Color) - setting maps (THREE.Texture) @@ -26,12 +26,12 @@ Every command needs a constructor. In the constructor ```javascript -CmdXXX = function () { +var DoSomethingCommand = function () { - Cmd.call( this ); // Required: Call default constructor + Command.call( this ); // Required: Call default constructor - this.type = 'CmdXXX'; // Required: has to match the object-name! - this.name = 'Set/Do/Update XXX'; // Required: description of the command, used in Sidebar.History + 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 // restore the old and the new state @@ -46,7 +46,7 @@ And as part of the prototype you need to implement four functions - **fromJSON:** which deserializes the command ```javascript -CmdXXX.prototype = { +DoSomethingCommand.prototype = { execute: function () { @@ -62,21 +62,21 @@ CmdXXX.prototype = { toJSON: function () { - var output = Cmd.prototype.toJSON.call( this ); // Required: Call 'toJSON'-method of prototype 'Cmd' + var output = Command.prototype.toJSON.call( this ); // Required: Call 'toJSON'-method of prototype 'Command' // TODO: serialize all the necessary information as part of 'output' (JSON-format) // so that it can be restored in 'fromJSON' - + return output; }, fromJSON: function ( json ) { - Cmd.prototype.fromJSON.call( this, json ); // Required: Call 'fromJSON'-method of prototype 'Cmd' - + Command.prototype.fromJSON.call( this, json ); // Required: Call 'fromJSON'-method of prototype 'Command' + // TODO: restore command from json - + } }; @@ -89,9 +89,9 @@ To execute a command we need an instance of the main editor-object. The editor-o On **editor** we then call **.execute(...)*** with the new command-object which in turn calls **history.execute(...)** and adds the command to the undo-stack. ```javascript - -editor.execute( new CmdXXX() ); - + +editor.execute( new DoSomethingCommand() ); + ``` ### Updatable commands ### @@ -99,7 +99,7 @@ editor.execute( new CmdXXX() ); Some commands are also **updatable**. By default a command is not updatable. Making a command updatable means that you have to implement a fifth function 'update' as part of the prototype. In it only the 'new' state gets updated while the old one stays the same. -Here as an example is the update-function of **CmdSetColor**: +Here as an example is the update-function of **SetColorCommand**: ```javascript update: function ( cmd ) { @@ -112,15 +112,15 @@ update: function ( cmd ) { #### List of updatable commands -- CmdSetColor -- CmdSetGeometry -- CmdSetMaterialColor -- CmdSetMaterialValue -- CmdSetPosition -- CmdSetRotation -- CmdSetScale -- CmdSetValue -- CmdSetScriptValue +- SetColorCommand +- SetGeometryCommand +- SetMaterialColorCommand +- SetMaterialValueCommand +- SetPositionCommand +- SetRotationCommand +- SetScaleCommand +- SetValueCommand +- SetScriptValueCommand The idea behind 'updatable commands' is that two commands of the same type which occur within a short period of time should be merged into one. diff --git a/editor/docs/Writing unit tests for undo-redo commands.md b/editor/docs/Writing unit tests for undo-redo commands.md index 5fcae29bd58b19eaaaf4f99567aaf91e41477f18..cfd44896778a5e82f2da3c6d576b2bfe1c08285c 100644 --- a/editor/docs/Writing unit tests for undo-redo commands.md +++ b/editor/docs/Writing unit tests for undo-redo commands.md @@ -16,19 +16,19 @@ Each of the listed steps will now be described in detail. ### 1. Create a new unit test file ### -Create a new file in path `test/unit/editor/TestCmdXXX.js`. +Create a new file in path `test/unit/editor/TestDoSomethingCommand.js`. ### 2. Include the new command in the editor test suite ### Navigate to the editor test suite `test/unit/unittests_editor.html` and open it. Within the file, go to the `` and include the new command: -```javascript +```html // //... - - - // add this line + + // add this line + //... ``` @@ -36,12 +36,12 @@ It is recommended to keep the script inclusions in alphabetical order, if possib Next, in the same file, go to `` and include the test file for the new command: -```javascript +```html // //... - - // add this line - + + // add this line + //... ``` @@ -51,12 +51,12 @@ Again, keeping the alphabetical order is recommended. #### Template #### -Open the unit test file `test/unit/editor/TestCmdXXX.js` and paste following code: +Open the unit test file `test/unit/editor/TestDoSomethingCommand.js` and paste following code: ```javascript -module( "CmdXXX" ); +module( "DoSomethingCommand" ); -test("Test CmdXXX (Undo and Redo)", function() { +test("Test DoSomethingCommand (Undo and Redo)", function() { var editor = new Editor(); @@ -68,19 +68,19 @@ test("Test CmdXXX (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 CmdAddObject( box ) ); + editor.execute( new AddObjectCommand( box ) ); // your test begins here... -}); +} ); ``` The predefined code is just meant to ease the development, you do not have to stick with it. However, the test should cover at least one `editor.execute()`, one `editor.undo()` and one `editor.redo()` call. -Best practice is to call `editor.execute( new CmdXXX( {custom parameters} ) )` **twice**. Since you'll have to do one undo (go one step back), it is recommended to have a custom state for comparison. Try to avoid assertions `ok()` against default values. +Best practice is to call `editor.execute( new DoSomethingCommand( {custom parameters} ) )` **twice**. Since you'll have to do one undo (go one step back), it is recommended to have a custom state for comparison. Try to avoid assertions `ok()` against default values. #### Assertions #### After performing `editor.execute()` twice, you can do your first assertion to check whether the executes are done correctly. diff --git a/editor/index.html b/editor/index.html index 53f7907779cd82eb44f5dd4b77a1523a3e862901..37f8bfa5de202c4ad36d8a6486361067bf8bbe48 100644 --- a/editor/index.html +++ b/editor/index.html @@ -124,27 +124,27 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + +