123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- import { TempNode } from './TempNode.js';
- class FunctionCallNode extends TempNode {
- constructor( func, inputs ) {
- super();
- this.setFunction( func, inputs );
- }
- setFunction( func, inputs = [] ) {
- this.value = func;
- this.inputs = inputs;
- }
- getFunction() {
- return this.value;
- }
- getType( builder ) {
- return this.value.getType( builder );
- }
- generate( builder, output ) {
- const type = this.getType( builder ),
- func = this.value;
- let code = func.build( builder, output ) + '( ';
- const params = [];
- for ( let i = 0; i < func.inputs.length; i ++ ) {
- const inpt = func.inputs[ i ],
- param = this.inputs[ i ] || this.inputs[ inpt.name ];
- params.push( param.build( builder, builder.getTypeByFormat( inpt.type ) ) );
- }
- code += params.join( ', ' ) + ' )';
- return builder.format( code, type, output );
- }
- copy( source ) {
- super.copy( source );
- for ( const prop in source.inputs ) {
- this.inputs[ prop ] = source.inputs[ prop ];
- }
- this.value = source.value;
- return this;
- }
- toJSON( meta ) {
- let data = this.getJSONNode( meta );
- if ( ! data ) {
- const func = this.value;
- data = this.createJSONNode( meta );
- data.value = this.value.toJSON( meta ).uuid;
- if ( func.inputs.length ) {
- data.inputs = {};
- for ( let i = 0; i < func.inputs.length; i ++ ) {
- const inpt = func.inputs[ i ],
- node = this.inputs[ i ] || this.inputs[ inpt.name ];
- data.inputs[ inpt.name ] = node.toJSON( meta ).uuid;
- }
- }
- }
- return data;
- }
- }
- FunctionCallNode.prototype.nodeType = 'FunctionCall';
- export { FunctionCallNode };
|