OperatorEditor.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { ObjectNode } from '../core/ObjectNode.js';
  2. import { SelectInput, LabelElement } from '../../libs/flow.module.js';
  3. import { OperatorNode, FloatNode } from '../../renderers/nodes/Nodes.js';
  4. const NULL_VALUE = new FloatNode();
  5. export class OperatorEditor extends ObjectNode {
  6. constructor() {
  7. const node = new OperatorNode( '+', NULL_VALUE, NULL_VALUE );
  8. super( 'Float', 1, node );
  9. this.title.setStyle( 'green' );
  10. const opInput = new SelectInput( [
  11. { name: '+ Addition', value: '+' },
  12. { name: '- Subtraction', value: '-' },
  13. { name: '* Multiplication', value: '*' },
  14. { name: '/ Division', value: '/' }
  15. ] );
  16. opInput.onChange( ( data ) => {
  17. node.op = data.getValue();
  18. this.invalidate();
  19. } );
  20. const aElement = new LabelElement( 'A' ).setInput( 3 );
  21. const bElement = new LabelElement( 'B' ).setInput( 3 );
  22. aElement.onConnect( () => {
  23. node.aNode = aElement.linkedExtra || NULL_VALUE;
  24. } );
  25. bElement.onConnect( () => {
  26. node.bNode = bElement.linkedExtra || NULL_VALUE;
  27. } );
  28. this.add( new LabelElement( 'Operator' ).add( opInput ) )
  29. .add( aElement )
  30. .add( bElement );
  31. }
  32. }