polygonjs-engine
Version:
node-based webgl 3D engine https://polygonjs.com
104 lines (96 loc) • 3.11 kB
text/typescript
import {NodeContext, NodeContextUnion} from '../../../../poly/NodeContext';
import {
BaseGlConnectionPoint,
GlConnectionPointType,
GlConnectionPoint,
GLParamTypeToConnectionPointTypeMap,
} from './Gl';
import {
BaseJsConnectionPoint,
JsConnectionPointType,
JsConnectionPoint,
JsParamTypeToConnectionPointTypeMap,
} from './Js';
import {BaseEventConnectionPoint, EventConnectionPoint, EventConnectionPointType} from './Event';
type ConnectionPointTypeMapGeneric = {
[]: BaseEventConnectionPoint | BaseGlConnectionPoint | BaseJsConnectionPoint | undefined;
};
export interface ConnectionPointTypeMap extends ConnectionPointTypeMapGeneric {
[]: undefined;
[]: undefined;
[]: BaseEventConnectionPoint;
[]: BaseGlConnectionPoint;
[]: BaseJsConnectionPoint;
[]: undefined;
[]: undefined;
[]: undefined;
[]: undefined;
[]: undefined;
[]: undefined;
}
type ConnectionPointEnumMapGeneric = {
[]: EventConnectionPointType | GlConnectionPointType | JsConnectionPointType | undefined;
};
export interface ConnectionPointEnumMap extends ConnectionPointEnumMapGeneric {
[]: undefined;
[]: undefined;
[]: EventConnectionPointType;
[]: GlConnectionPointType;
[]: JsConnectionPointType;
[]: undefined;
[]: undefined;
[]: undefined;
[]: undefined;
[]: undefined;
[]: undefined;
}
type IConnectionPointEnumMap = {[key in NodeContextUnion]: ConnectionPointEnumMap[key]};
export const DEFAULT_CONNECTION_POINT_ENUM_MAP: IConnectionPointEnumMap = {
[]: undefined,
[]: undefined,
[]: EventConnectionPointType.BASE,
[]: GlConnectionPointType.FLOAT,
[]: JsConnectionPointType.FLOAT,
[]: undefined,
[]: undefined,
[]: undefined,
[]: undefined,
[]: undefined,
[]: undefined,
};
export function create_connection_point<NC extends NodeContext>(
context: NC,
name: string,
type: ConnectionPointEnumMap[NC]
) {
switch (context) {
case NodeContext.EVENT: {
return new EventConnectionPoint(name, type as EventConnectionPointType);
}
case NodeContext.GL: {
return new GlConnectionPoint(name, type as GlConnectionPointType);
}
case NodeContext.JS: {
return new JsConnectionPoint(name, type as JsConnectionPointType);
}
default: {
return undefined;
}
}
}
export function param_type_to_connection_point_type_map<NC extends NodeContext>(context: NC) {
switch (context) {
case NodeContext.EVENT: {
return undefined;
}
case NodeContext.GL: {
return GLParamTypeToConnectionPointTypeMap;
}
case NodeContext.JS: {
return JsParamTypeToConnectionPointTypeMap;
}
default: {
return undefined;
}
}
}