Skip to content

Commit

Permalink
Merge remote-tracking branch 'oveddan/oveddan-improvements'
Browse files Browse the repository at this point in the history
  • Loading branch information
bhouston committed Jul 10, 2023
2 parents 9c8d991 + fce27fb commit e1d4cf7
Show file tree
Hide file tree
Showing 126 changed files with 5,742 additions and 2,424 deletions.
58 changes: 28 additions & 30 deletions apps/exec-graph/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ import process from 'node:process';
import {
DefaultLogger,
Engine,
getCoreNodeDefinitions,
getCoreValueTypes,
Logger,
ManualLifecycleEventEmitter,
parseSafeFloat,
readGraphFromJSON,
registerCoreProfile,
registerLifecycleEventEmitter,
registerLogger,
registerSceneProfile,
Registry,
validateGraph,
validateRegistry,
writeGraphToJSON
validateRegistry
} from '@behave-graph/core';
import { program } from 'commander';
import { createRequire } from 'module';
Expand All @@ -40,28 +36,30 @@ async function execGraph({
jsonPattern: string;
programOptions: ProgramOptions;
}) {
const registry = new Registry();
const manualLifecycleEventEmitter = new ManualLifecycleEventEmitter();
const lifecycleEventEmitter = new ManualLifecycleEventEmitter();
const logger = new DefaultLogger();
registerCoreProfile(registry);
registerSceneProfile(registry);
registerLogger(registry.dependencies, logger);
registerLifecycleEventEmitter(
registry.dependencies,
manualLifecycleEventEmitter
);
const valueTypeMap = getCoreValueTypes();
const nodeDefinitionMap = getCoreNodeDefinitions(valueTypeMap);

const graphJsonPath = jsonPattern;
Logger.verbose(`reading behavior graph: ${graphJsonPath}`);
const textFile = await fs.readFile(graphJsonPath);
const graph = readGraphFromJSON(
JSON.parse(textFile.toString('utf8')),
registry
);
const graph = readGraphFromJSON({
graphJson: JSON.parse(textFile.toString('utf8')),
nodes: nodeDefinitionMap,
values: valueTypeMap,
dependencies: {
logger,
lifecycleEventEmitter
}
});
graph.name = graphJsonPath;

const errorList: string[] = [];
errorList.push(...validateRegistry(registry), ...validateGraph(graph));
errorList.push(
...validateRegistry({ nodes: nodeDefinitionMap, values: valueTypeMap }),
...validateGraph(graph)
);

if (errorList.length > 0) {
Logger.error(`${errorList.length} errors found:`);
Expand All @@ -71,13 +69,13 @@ async function execGraph({
return;
}

if (programOptions.upgrade) {
/* if (programOptions.upgrade) {
const newGraphJson = writeGraphToJSON(graph);
await fs.writeFile(graphJsonPath, JSON.stringify(newGraphJson, null, 2));
}
}*/

Logger.verbose('creating behavior graph');
const engine = new Engine(graph);
const engine = new Engine(graph.nodes);

if (programOptions.trace) {
engine.onNodeExecutionStart.addListener((node) =>
Expand All @@ -93,29 +91,29 @@ async function execGraph({
}

const startTime = Date.now();
if (manualLifecycleEventEmitter.startEvent.listenerCount > 0) {
if (lifecycleEventEmitter.startEvent.listenerCount > 0) {
Logger.verbose('triggering start event');
manualLifecycleEventEmitter.startEvent.emit();
lifecycleEventEmitter.startEvent.emit();

Logger.verbose('executing all (async)');
await engine.executeAllAsync(5);
}

if (manualLifecycleEventEmitter.tickEvent.listenerCount > 0) {
if (lifecycleEventEmitter.tickEvent.listenerCount > 0) {
const iterations = parseSafeFloat(programOptions.iterations, 5);
for (let tick = 0; tick < iterations; tick++) {
Logger.verbose(`triggering tick (${tick} of ${iterations})`);
manualLifecycleEventEmitter.tickEvent.emit();
lifecycleEventEmitter.tickEvent.emit();

Logger.verbose('executing all (async)');
// eslint-disable-next-line no-await-in-loop
await engine.executeAllAsync(5);
}
}

if (manualLifecycleEventEmitter.endEvent.listenerCount > 0) {
if (lifecycleEventEmitter.endEvent.listenerCount > 0) {
Logger.verbose('triggering end event');
manualLifecycleEventEmitter.endEvent.emit();
lifecycleEventEmitter.endEvent.emit();

Logger.verbose('executing all (async)');
await engine.executeAllAsync(5);
Expand Down
1 change: 1 addition & 0 deletions apps/export-node-spec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "export-node-spec",
"version": "0.0.1",
"private": true,
"type": "module",
"bin": "./bin/cli.js",
"types": "./dist/index.d.ts",
Expand Down
27 changes: 19 additions & 8 deletions apps/export-node-spec/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { promises as fs } from 'node:fs';

import {
DefaultLogger,
getCoreNodeDefinitions,
getCoreValueTypes,
Logger,
registerCoreProfile,
registerSceneProfile,
Registry,
ManualLifecycleEventEmitter,
validateNodeRegistry,
writeNodeSpecsToJSON
} from '@behave-graph/core';
Expand Down Expand Up @@ -34,12 +35,15 @@ export const main = async () => {
throw new Error('no path specified');
}

const registry = new Registry();
registerCoreProfile(registry);
registerSceneProfile(registry);
const lifecycleEventEmitter = new ManualLifecycleEventEmitter();
const logger = new DefaultLogger();
const valueTypeMap = getCoreValueTypes();
const nodeDefinitionMap = getCoreNodeDefinitions(valueTypeMap);

const errorList: string[] = [];
errorList.push(...validateNodeRegistry(registry));
errorList.push(
...validateNodeRegistry({ nodes: nodeDefinitionMap, values: valueTypeMap })
);
if (errorList.length > 0) {
Logger.error(`${errorList.length} errors found:`);
errorList.forEach((errorText, errorIndex) => {
Expand All @@ -48,7 +52,14 @@ export const main = async () => {
return;
}

const nodeSpecJson = writeNodeSpecsToJSON(registry);
const nodeSpecJson = writeNodeSpecsToJSON({
nodes: nodeDefinitionMap,
values: valueTypeMap,
dependencies: {
logger,
lifecycleEventEmitter
}
});
nodeSpecJson.sort((a, b) => a.type.localeCompare(b.type));
const jsonOutput = JSON.stringify(nodeSpecJson, null, ' ');
if (programOptions.csv) {
Expand Down
5 changes: 4 additions & 1 deletion apps/graph-editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"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 All @@ -9,7 +10,9 @@
"dependencies": {
"@behave-graph/core": "*",
"@behave-graph/flow": "*",
"three": "^0.145.0"
"@types/three": "0.152.1",
"three": "0.152.2",
"three-stdlib": "^2.22.4"
},
"devDependencies": {
"@vitejs/plugin-react": "^2.2.0",
Expand Down
15 changes: 7 additions & 8 deletions apps/graph-editor/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ import { Examples, Flow } from '@behave-graph/flow';
import React from 'react';
import ReactDOM from 'react-dom/client';

import Branch from '../../../graphs/core/flow/Branch.json';
import HelloWorld from '../../../graphs/core/HelloWorld.json';
import Polynomial from '../../../graphs/core/logic/Polynomial.json';
import Delay from '../../../graphs/core/time/Delay.json';
import SetGet from '../../../graphs/core/variables/SetGet.json';
import rawGraph from './graph.json';

const graph = rawGraph as any as GraphJSON;
const graph = rawGraph as unknown as GraphJSON;

const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);

import HelloWorld from '../../../graphs/core//HelloWorld.json';
import Branch from '../../../graphs/core/flow/Branch.json';
import Polynomial from '../../../graphs/core/logic/Polynomial.json';
import Delay from '../../../graphs/core/time/Delay.json';
import SetGet from '../../../graphs/core/variables/SetGet.json';

// TODO remove when json types fixed in behave-graph
const examples: Examples = {
branch: Branch as unknown as GraphJSON,
Expand All @@ -31,6 +30,6 @@ const examples: Examples = {

root.render(
<React.StrictMode>
<Flow graph={graph} examples={examples} />
<Flow initialGraph={graph} examples={examples} />
</React.StrictMode>
);
1 change: 1 addition & 0 deletions apps/three-viewer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "three-viewer",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "tsc --noEmit && esbuild src/index.ts --target=es2020 --bundle --minify --outfile=public/js/index.js",
Expand Down
Loading

0 comments on commit e1d4cf7

Please sign in to comment.