2
0

SetScriptValueCommand.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * @author dforrer / https://github.com/dforrer
  3. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4. */
  5. /**
  6. * @param editor Editor
  7. * @param object THREE.Object3D
  8. * @param script javascript object
  9. * @param attributeName string
  10. * @param newValue string, object
  11. * @constructor
  12. */
  13. var SetScriptValueCommand = function ( editor, object, script, attributeName, newValue ) {
  14. Command.call( this, editor );
  15. this.type = 'SetScriptValueCommand';
  16. this.name = 'Set Script.' + attributeName;
  17. this.updatable = true;
  18. this.object = object;
  19. this.script = script;
  20. this.attributeName = attributeName;
  21. this.oldValue = ( script !== undefined ) ? script[ this.attributeName ] : undefined;
  22. this.newValue = newValue;
  23. };
  24. SetScriptValueCommand.prototype = {
  25. execute: function () {
  26. this.script[ this.attributeName ] = this.newValue;
  27. this.editor.signals.scriptChanged.dispatch();
  28. },
  29. undo: function () {
  30. this.script[ this.attributeName ] = this.oldValue;
  31. this.editor.signals.scriptChanged.dispatch();
  32. },
  33. update: function ( cmd ) {
  34. this.newValue = cmd.newValue;
  35. },
  36. toJSON: function () {
  37. var output = Command.prototype.toJSON.call( this );
  38. output.objectUuid = this.object.uuid;
  39. output.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
  40. output.attributeName = this.attributeName;
  41. output.oldValue = this.oldValue;
  42. output.newValue = this.newValue;
  43. return output;
  44. },
  45. fromJSON: function ( json ) {
  46. Command.prototype.fromJSON.call( this, json );
  47. this.oldValue = json.oldValue;
  48. this.newValue = json.newValue;
  49. this.attributeName = json.attributeName;
  50. this.object = this.editor.objectByUuid( json.objectUuid );
  51. this.script = this.editor.scripts[ json.objectUuid ][ json.index ];
  52. }
  53. };