Skip to content

Commit

Permalink
scene, flow and graph-editor compile and run, but are not complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhouston committed Jul 10, 2023
1 parent e1d4cf7 commit 4b531b6
Show file tree
Hide file tree
Showing 14 changed files with 2,386 additions and 35 deletions.
1 change: 0 additions & 1 deletion apps/graph-editor/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "graph-editor",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "tsc --noEmit && esbuild src/index.tsx --target=es2020 --bundle --minify --outfile=public/js/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Graphs/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { INode } from '../Nodes/NodeInstance.js';
import { NodeDefinitionsMap } from '../Nodes/Registry/NodeDefinitionsMap.js';
import { Socket } from '../Sockets/Socket.js';
import { ValueTypeMap } from '../Values/ValueTypeMap.js';
import { Variable } from '../Variables/Variable.js';
import { Variable } from '../Values/Variables/Variable.js';

// Purpose:
// - stores the node graph
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Graphs/IO/readGraphFromJSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { INode } from '../../Nodes/NodeInstance.js';
import { NodeDefinitionsMap } from '../../Nodes/Registry/NodeDefinitionsMap.js';
import { Socket } from '../../Sockets/Socket.js';
import { ValueTypeMap } from '../../Values/ValueTypeMap.js';
import { Variable } from '../../Variables/Variable.js';
import { Variable } from '../../Values/Variables/Variable.js';
import {
createNode,
GraphCustomEvents,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Profiles/Core/Variables/VariableGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
NodeCategory,
SocketsList
} from '../../../Nodes/NodeDefinitions.js';
import { Variable } from '../../../Variables/Variable.js';
import { Variable } from '../../../Values/Variables/Variable.js';

export const VariableGet = makeFunctionNodeDefinition({
typeName: 'variable/get',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Profiles/Core/Variables/VariableSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
NodeCategory,
SocketsList
} from '../../../Nodes/NodeDefinitions.js';
import { Variable } from '../../../Variables/Variable.js';
import { Variable } from '../../../Values/Variables/Variable.js';

export const VariableSet = makeFlowNodeDefinition({
typeName: 'variable/set',
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/Registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ export interface IRegistry {
readonly values: ValueTypeMap;
readonly nodes: NodeDefinitionsMap;
}

export interface IQueryableRegistry<T> {
get: (id: string) => T | undefined;
getAll: () => T[];
getAllNames: () => string[];
contains: (id: string) => boolean;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventEmitter } from '../Events/EventEmitter.js';
import { Metadata } from '../Metadata.js';
import { EventEmitter } from '../../Events/EventEmitter.js';
import { Metadata } from '../../Metadata.js';

export class Variable {
private value: any;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export * from './Values/ValueType.js';
export * from './Sockets/Socket.js';
export * from './Events/CustomEvent.js';
export * from './Events/EventEmitter.js';
export * from './Variables/Variable.js';
export * from './Values/Variables/Variable.js';

// loading & execution
export * from './Execution/Engine.js';
Expand Down
8 changes: 7 additions & 1 deletion packages/flow/src/components/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ const getPairs = <T, U>(arr1: T[], arr2: U[]) => {
return pairs;
};

export const Node = ({ id, data, spec, selected, allSpecs }: NodeProps) => {
export const Node: React.FC<NodeProps> = ({
id,
data,
spec,
selected,
allSpecs
}: NodeProps) => {
const edges = useEdges();
const handleChange = useChangeNodeData(id);
const pairs = getPairs(spec.inputs, spec.outputs);
Expand Down
12 changes: 6 additions & 6 deletions packages/flow/src/hooks/useQueriableDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { IQueriableRegistry } from 'packages/core/src';
import { IQueryableRegistry } from '@behave-graph/core';
import { useMemo } from 'react';

export const toQueriableDefinitions = <T>(definitionsMap: {
export const toQueryableDefinitions = <T>(definitionsMap: {
[id: string]: T;
}): IQueriableRegistry<T> => ({
}): IQueryableRegistry<T> => ({
get: (id: string) => definitionsMap[id],
getAll: () => Object.values(definitionsMap),
getAllNames: () => Object.keys(definitionsMap),
contains: (id: string) => definitionsMap[id] !== undefined
});

export const useQueriableDefinitions = <T>(definitionsMap: {
export const useQueryableDefinitions = <T>(definitionsMap: {
[id: string]: T;
}): IQueriableRegistry<T> => {
}): IQueryableRegistry<T> => {
const queriableDefinitions = useMemo(
() => toQueriableDefinitions(definitionsMap),
() => toQueryableDefinitions(definitionsMap),
[definitionsMap]
);

Expand Down
27 changes: 15 additions & 12 deletions packages/flow/src/hooks/useRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import { DefaultLogger, ManualLifecycleEventEmitter } from '@behave-graph/core';
import {
DefaultLogger,
getCoreNodeDefinitions,
getCoreValueTypes,
IRegistry,
ManualLifecycleEventEmitter
} from '@behave-graph/core';
import { useState } from 'react';

const createRegistry = () => {
const registry = new Registry();
const logger = new DefaultLogger();
const manualLifecycleEventEmitter = new ManualLifecycleEventEmitter();
registerCoreProfile(registry);
registerSceneProfile(registry);
registerLogger(registry.dependencies, logger);
registerLifecycleEventEmitter(
registry.dependencies,
manualLifecycleEventEmitter
);
const logger = new DefaultLogger();
const valueTypeMap = getCoreValueTypes();
const nodeDefinitionMap = getCoreNodeDefinitions(valueTypeMap);

return {
registry,
registry: {
nodes: nodeDefinitionMap,
values: valueTypeMap
},
logger,
manualLifecycleEventEmitter
};
};

export const useRegistry = () => {
const [registry] = useState<{
registry: Registry;
registry: IRegistry;
logger: DefaultLogger;
manualLifecycleEventEmitter: ManualLifecycleEventEmitter;
}>(() => createRegistry());
Expand Down
2 changes: 1 addition & 1 deletion packages/flow/src/util/customNodeTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { getNodeSpecJSON } from './getNodeSpecJSON.js';
const spec = getNodeSpecJSON();

export const customNodeTypes = spec.reduce((nodes, node) => {
nodes[node.type] = (props) => <Node spec={node} {...props} />;
nodes[node.type] = (props) => <Node spec={node} allSpecs={spec} {...props} />;
return nodes;
}, {} as NodeTypes);
23 changes: 16 additions & 7 deletions packages/flow/src/util/getNodeSpecJSON.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import {
DefaultLogger,
getCoreNodeDefinitions,
getCoreValueTypes,
ManualLifecycleEventEmitter,
NodeSpecJSON,
registerCoreProfile,
registerSceneProfile,
Registry,
writeNodeSpecsToJSON
} from '@behave-graph/core';

let nodeSpecJSON: NodeSpecJSON[] | undefined = undefined;

export const getNodeSpecJSON = (): NodeSpecJSON[] => {
if (nodeSpecJSON === undefined) {
const registry = new Registry();
registerCoreProfile(registry);
registerSceneProfile(registry);
nodeSpecJSON = writeNodeSpecsToJSON(registry);
const lifecycleEventEmitter = new ManualLifecycleEventEmitter();
const logger = new DefaultLogger();
const valueTypeMap = getCoreValueTypes();
const nodeDefinitionMap = getCoreNodeDefinitions(valueTypeMap);
nodeSpecJSON = writeNodeSpecsToJSON({
nodes: nodeDefinitionMap,
values: valueTypeMap,
dependencies: {
logger,
lifecycleEventEmitter
}
});
}
return nodeSpecJSON;
};
Loading

0 comments on commit 4b531b6

Please sign in to comment.