2
0

SetScriptValueCommand.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { Command } from '../Command.js';
  2. /**
  3. * @param editor Editor
  4. * @param object THREE.Object3D
  5. * @param script javascript object
  6. * @param attributeName string
  7. * @param newValue string, object
  8. * @constructor
  9. */
  10. class SetScriptValueCommand extends Command {
  11. constructor( editor, object, script, attributeName, newValue ) {
  12. super( editor );
  13. this.type = 'SetScriptValueCommand';
  14. this.name = `Set Script.${attributeName}`;
  15. this.updatable = true;
  16. this.object = object;
  17. this.script = script;
  18. this.attributeName = attributeName;
  19. this.oldValue = ( script !== undefined ) ? script[ this.attributeName ] : undefined;
  20. this.newValue = newValue;
  21. }
  22. execute() {
  23. this.script[ this.attributeName ] = this.newValue;
  24. this.editor.signals.scriptChanged.dispatch();
  25. }
  26. undo() {
  27. this.script[ this.attributeName ] = this.oldValue;
  28. this.editor.signals.scriptChanged.dispatch();
  29. }
  30. update( cmd ) {
  31. this.newValue = cmd.newValue;
  32. }
  33. toJSON() {
  34. const output = super.toJSON( this );
  35. output.objectUuid = this.object.uuid;
  36. output.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
  37. output.attributeName = this.attributeName;
  38. output.oldValue = this.oldValue;
  39. output.newValue = this.newValue;
  40. return output;
  41. }
  42. fromJSON( json ) {
  43. super.fromJSON( json );
  44. this.oldValue = json.oldValue;
  45. this.newValue = json.newValue;
  46. this.attributeName = json.attributeName;
  47. this.object = this.editor.objectByUuid( json.objectUuid );
  48. this.script = this.editor.scripts[ json.objectUuid ][ json.index ];
  49. }
  50. }
  51. export { SetScriptValueCommand };