You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
1.4 KiB
97 lines
1.4 KiB
2 years ago
|
import { ObjectNode } from '../../libs/flow.module.js';
|
||
|
|
||
|
export const onNodeValidElement = ( inputElement, outputElement ) => {
|
||
|
|
||
|
const outputObject = outputElement.getObject();
|
||
|
|
||
|
if ( ! outputObject || ! outputObject.isNode ) {
|
||
|
|
||
|
return false;
|
||
|
|
||
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
export class BaseNode extends ObjectNode {
|
||
|
|
||
|
constructor( name, inputLength, value = null, width = 300 ) {
|
||
|
|
||
|
const getObjectCallback = ( /*output = null*/ ) => {
|
||
|
|
||
|
return this.value;
|
||
|
|
||
|
};
|
||
|
|
||
|
super( name, inputLength, getObjectCallback, width );
|
||
|
|
||
|
this.setOutputColor( this.getColorValueFromValue( value ) );
|
||
|
|
||
|
this.editor = null;
|
||
|
|
||
|
this.value = value;
|
||
|
|
||
|
this.onValidElement = onNodeValidElement;
|
||
|
|
||
|
}
|
||
|
|
||
|
getColor() {
|
||
|
|
||
|
return ( this.getColorValueFromValue( this.value ) || '#777777' ) + 'BB';
|
||
|
|
||
|
}
|
||
|
|
||
|
serialize( data ) {
|
||
|
|
||
|
super.serialize( data );
|
||
|
|
||
|
delete data.width;
|
||
|
|
||
|
}
|
||
|
|
||
|
deserialize( data ) {
|
||
|
|
||
|
delete data.width;
|
||
|
|
||
|
super.deserialize( data );
|
||
|
|
||
|
}
|
||
|
|
||
|
setEditor( value ) {
|
||
|
|
||
|
this.editor = value;
|
||
|
|
||
|
return this;
|
||
|
|
||
|
}
|
||
|
|
||
|
getColorValueFromValue( value ) {
|
||
|
|
||
|
if ( ! value ) return;
|
||
|
|
||
|
if ( value.isMaterial === true ) {
|
||
|
|
||
|
//return 'forestgreen';
|
||
|
return '#228b22';
|
||
|
|
||
|
} else if ( value.isObject3D === true ) {
|
||
|
|
||
|
return '#ffa500';
|
||
|
|
||
|
} else if ( value.isDataFile === true ) {
|
||
|
|
||
|
return '#00ffff';
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
add( element ) {
|
||
|
|
||
|
element.onValid( ( source, target ) => this.onValidElement( source, target ) );
|
||
|
|
||
|
return super.add( element );
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|