feat: some shut

This commit is contained in:
2024-04-20 04:08:30 +02:00
parent 78c88e4d66
commit 4c7c4cac2c
21 changed files with 172 additions and 171 deletions

View File

@ -8,6 +8,8 @@ import type { NodeInput } from "@nodes/types";
const logger = createLogger("graph-manager");
logger.mute();
function areSocketsCompatible(output: string | undefined, inputs: string | string[] | undefined) {
if (Array.isArray(inputs) && output) {
return inputs.includes(output);
@ -225,6 +227,32 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any, "
return this.registry.getNode(id);
}
async loadNode(id: string) {
await this.registry.load([id]);
const nodeType = this.registry.getNode(id);
if (!nodeType) return;
const settingTypes = this.settingTypes;
const settingValues = this.settings;
if (nodeType.inputs) {
for (const key in nodeType.inputs) {
let settingId = nodeType.inputs[key].setting;
if (settingId) {
settingTypes[settingId] = nodeType.inputs[key];
if (settingValues[settingId] === undefined && "value" in type.inputs[key]) {
settingValues[settingId] = nodeType.inputs[key].value;
}
}
}
}
this.settings = settingValues;
this.settingTypes = settingTypes;
this.emit("settings", { types: settingTypes, values: settingValues });
}
getChildrenOfNode(node: Node) {
const children = [];
const stack = node.tmp?.children?.slice(0);
@ -349,6 +377,8 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any, "
return;
}
const node: Node = { id: this.createNodeId(), type, position, tmp: { type: nodeType }, props };
this.nodes.update((nodes) => {

View File

@ -773,14 +773,13 @@
}
const pos = projectScreenToWorld(mx, my);
graph.registry.load([nodeId]).then(() => {
graph.loadNode(nodeId).then(() => {
graph.createNode({
type: nodeId,
props: {},
position: pos,
});
});
console.log({ nodeId });
}
function handlerDragOver(e: DragEvent) {