Skip to content

Commit 32f3b87

Browse files
committed
further clean up code; Allow color to be null
1 parent e4d5555 commit 32f3b87

File tree

4 files changed

+42
-26
lines changed

4 files changed

+42
-26
lines changed

playground/BaseNodeEditor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ export class BaseNodeEditor extends Node {
8383

8484
getColor() {
8585

86-
return ( getColorFromNode( this.value ) ) + 'BB';
86+
const color = getColorFromNode( this.value );
87+
88+
return color ? color + 'BB' : null;
8789

8890
}
8991

playground/DataTypeLib.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export function getLengthFromNode( value ) {
4242

4343
}
4444

45-
4645
export const typeToColorLib = {
4746
// gpu
4847
string: '#ff0000',
@@ -63,11 +62,9 @@ export const typeToColorLib = {
6362
node: '#ff00ff'
6463
};
6564

66-
export const defaultColor = '#777777';
67-
6865
export function getColorFromType( type ) {
6966

70-
return typeToColorLib[ type ] || defaultColor;
67+
return typeToColorLib[ type ] || null;
7168

7269
}
7370

@@ -79,7 +76,7 @@ export function getColorFromNode( value ) {
7976

8077
}
8178

82-
export function getTypeFromNode ( value ) {
79+
function getTypeFromNode( value ) {
8380

8481
if ( value ) {
8582

@@ -90,7 +87,7 @@ export function getTypeFromNode ( value ) {
9087

9188
}
9289

93-
export function getTypeFromValue( value ) {
90+
function getTypeFromValue( value ) {
9491

9592
if ( value && value.isScriptableValueNode ) value = value.value;
9693
if ( ! value ) return;
@@ -106,18 +103,17 @@ export function getTypeFromValue( value ) {
106103

107104
}
108105

109-
export function getColorFromValue( value ) {
106+
export function setInputAestheticsFromType( element, type ) {
110107

111-
const type = getTypeFromValue( value );
108+
element.setInput( getLengthFromType( type ) );
112109

113-
return getColorFromType( type );
110+
const color = getColorFromType( type );
114111

115-
}
112+
if ( color ) {
116113

117-
export function setInputAestheticsFromType( element, type ) {
114+
element.setInputColor( color );
118115

119-
element.setInput( getLengthFromType( type ) );
120-
element.setInputColor( getColorFromType( type ) );
116+
}
121117

122118
return element;
123119

@@ -133,7 +129,11 @@ export function setOutputAestheticsFromNode( element, node ) {
133129

134130
}
135131

136-
let type = getTypeFromNode( node );
132+
return setOutputAestheticsFromType( element, getTypeFromNode( node ) );
133+
134+
}
135+
136+
export function setOutputAestheticsFromType( element, type ) {
137137

138138
if ( ! type ) {
139139

@@ -143,8 +143,23 @@ export function setOutputAestheticsFromNode( element, node ) {
143143

144144
}
145145

146+
if ( type == 'void' ) {
147+
148+
element.setOutput( 0 );
149+
150+
return element;
151+
152+
}
153+
146154
element.setOutput( getLengthFromType( type ) );
147-
element.setOutputColor( getColorFromType( type ) );
155+
156+
const color = getColorFromType( type );
157+
158+
if ( color ) {
159+
160+
element.setOutputColor( color );
161+
162+
}
148163

149164
return element;
150165

playground/NodeEditorUtils.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { StringInput, NumberInput, ColorInput, Element, LabelElement } from 'flow';
22
import { string, float, vec2, vec3, vec4, color } from 'three/nodes';
3-
import { getColorFromType } from './DataTypeLib.js';
3+
import { setInputAestheticsFromType, setOutputAestheticsFromType } from './DataTypeLib.js';
44

55
export function exportJSON( object, name ) {
66

@@ -265,19 +265,17 @@ export function createElementFromJSON( json ) {
265265

266266
if ( inputType && json.inputConnection !== false ) {
267267

268-
element.setInputColor( getColorFromType( inputType ) );
268+
setInputAestheticsFromType( element, inputType );
269269
//element.setInputStyle( 'dotted' ); // 'border-style: dotted;'
270-
element.setInput( 1 );
271270

272271
element.onValid( onValidType( inputType ) );
273272

274273
}
275274

276275
if ( outputType ) {
277276

278-
element.setInputColor( getColorFromType( outputType ) );
277+
setOutputAestheticsFromType( element, outputType );
279278
//element.setInputStyle( 'dotted' ); // 'border-style: dotted;'
280-
element.setOutput( 1 );
281279

282280
}
283281

playground/editors/ScriptableEditor.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BaseNodeEditor } from '../BaseNodeEditor.js';
22
import { CodeEditorElement } from '../elements/CodeEditorElement.js';
33
import { disposeScene, createElementFromJSON, isGPUNode, onValidType } from '../NodeEditorUtils.js';
44
import { global, scriptable, js, scriptableValue } from 'three/nodes';
5-
import { getColorFromType } from '../DataTypeLib.js';
5+
import { getColorFromType, setInputAestheticsFromType, setOutputAestheticsFromType } from '../DataTypeLib.js';
66

77
const defaultTitle = 'Scriptable';
88
const defaultWidth = 500;
@@ -70,7 +70,9 @@ export class ScriptableEditor extends BaseNodeEditor {
7070

7171
getColor() {
7272

73-
return getColorFromType( this.layout ? this.layout.outputType : null ) + 'BB';
73+
const color = getColorFromType( this.layout ? this.layout.outputType : null );
74+
75+
return color ? color + 'BB' : null;
7476

7577
}
7678

@@ -171,8 +173,7 @@ export class ScriptableEditor extends BaseNodeEditor {
171173

172174
const outputType = layout.outputType;
173175

174-
this.title.setOutputColor( getColorFromType( outputType ) );
175-
this.title.setOutput( outputType && outputType !== 'void' ? this.outputLength : 0 );
176+
setOutputAestheticsFromType( this.title, outputType );
176177

177178
} else {
178179

@@ -407,7 +408,7 @@ export class ScriptableEditor extends BaseNodeEditor {
407408

408409
_initExternalConnection() {
409410

410-
this.title.setInputColor( getColorFromType( 'CodeNode' ) ).setInput( 1 ).onValid( onValidType( 'CodeNode' ) ).onConnect( () => {
411+
setInputAestheticsFromType(this.title, 'CodeNode' ).onValid( onValidType( 'CodeNode' ) ).onConnect( () => {
411412

412413
this.hasExternalEditor ? this._toExternal() : this._toInternal();
413414

0 commit comments

Comments
 (0)