feat: extract graph-interface into seperate package

This commit is contained in:
2024-04-10 15:40:01 +02:00
parent 404fcbfe39
commit 2ed1501747
93 changed files with 2193 additions and 1788 deletions

View File

@@ -0,0 +1,42 @@
import type { Graph } from "@nodes/types";
export function grid(width: number, height: number) {
const graph: Graph = {
id: Math.floor(Math.random() * 100000),
edges: [],
nodes: [],
};
const amount = width * height;
for (let i = 0; i < amount; i++) {
const x = i % width;
const y = Math.floor(i / height);
graph.nodes.push({
id: i,
tmp: {
visible: false,
},
position: [x * 30, y * 40],
props: i == 0 ? { value: 0 } : { op_type: 2, a: 2, b: 2 },
type: i == 0 ? "max/plantarium/float" : "max/plantarium/math",
});
graph.edges.push([i, 0, i + 1, i === amount - 1 ? "input" : "a",]);
}
graph.nodes.push({
id: amount,
tmp: {
visible: false,
},
position: [width * 30, (height - 1) * 40],
type: "max/plantarium/output",
props: {},
});
return graph;
}