OperatorEditor.js 1.1 KB

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