From 19234bdac1830c52ff0ac695b8620270093e5693 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Thu, 14 Mar 2024 16:55:11 +0100 Subject: [PATCH] feat: add initial input prototypes --- frontend/src/lib/components/NodeInput.svelte | 28 +++++++++++++++++++ .../src/lib/components/NodeParameter.svelte | 23 +++++++++++---- .../src/lib/components/graph/GraphView.svelte | 1 - frontend/src/lib/elements/Checkbox.svelte | 4 +-- frontend/src/lib/elements/Float.story.svelte | 17 +++++++++++ frontend/src/lib/elements/Float.svelte | 19 +++++++++++++ .../src/lib/elements/Integer.story.svelte | 17 +++++++++++ frontend/src/lib/elements/Integer.svelte | 9 ++++++ frontend/src/lib/elements/Select.story.svelte | 17 +++++++++++ frontend/src/lib/elements/Select.svelte | 21 ++++++++++++++ frontend/src/lib/graph-manager.ts | 13 +++++++-- frontend/src/lib/types/inputs.ts | 8 +++++- frontend/src/routes/app.css | 6 ++-- 13 files changed, 168 insertions(+), 15 deletions(-) create mode 100644 frontend/src/lib/components/NodeInput.svelte create mode 100644 frontend/src/lib/elements/Float.story.svelte create mode 100644 frontend/src/lib/elements/Integer.story.svelte create mode 100644 frontend/src/lib/elements/Select.story.svelte diff --git a/frontend/src/lib/components/NodeInput.svelte b/frontend/src/lib/components/NodeInput.svelte new file mode 100644 index 0000000..60f6642 --- /dev/null +++ b/frontend/src/lib/components/NodeInput.svelte @@ -0,0 +1,28 @@ + + +{#if input.type === "float"} + +{:else if input.type === "integer"} + +{:else if input.type === "boolean"} + +{:else if input.type === "select"} + + diff --git a/frontend/src/lib/elements/Float.svelte b/frontend/src/lib/elements/Float.svelte index e69de29..8324334 100644 --- a/frontend/src/lib/elements/Float.svelte +++ b/frontend/src/lib/elements/Float.svelte @@ -0,0 +1,19 @@ + + + + + diff --git a/frontend/src/lib/elements/Integer.story.svelte b/frontend/src/lib/elements/Integer.story.svelte new file mode 100644 index 0000000..7128efb --- /dev/null +++ b/frontend/src/lib/elements/Integer.story.svelte @@ -0,0 +1,17 @@ + + + +
+ +
+
+ + diff --git a/frontend/src/lib/elements/Integer.svelte b/frontend/src/lib/elements/Integer.svelte index e69de29..da759b6 100644 --- a/frontend/src/lib/elements/Integer.svelte +++ b/frontend/src/lib/elements/Integer.svelte @@ -0,0 +1,9 @@ + + + + diff --git a/frontend/src/lib/elements/Select.story.svelte b/frontend/src/lib/elements/Select.story.svelte new file mode 100644 index 0000000..32c9f50 --- /dev/null +++ b/frontend/src/lib/elements/Select.story.svelte @@ -0,0 +1,17 @@ + + + +
+ + {#each options as option} + + {/each} + + + diff --git a/frontend/src/lib/graph-manager.ts b/frontend/src/lib/graph-manager.ts index 3dc844c..1fa5ed8 100644 --- a/frontend/src/lib/graph-manager.ts +++ b/frontend/src/lib/graph-manager.ts @@ -6,7 +6,7 @@ const nodeTypes: NodeType[] = [ { id: "input/float", inputs: { - "value": { type: "float" }, + "value": { type: "float", value: 0.1 }, }, outputs: ["float"], }, @@ -14,8 +14,8 @@ const nodeTypes: NodeType[] = [ id: "math", inputs: { "type": { type: "select", options: ["add", "subtract", "multiply", "divide"], internal: true }, - "a": { type: "float" }, - "b": { type: "float" }, + "a": { type: "float", value: 0.2 }, + "b": { type: "float", value: 0.2 }, }, outputs: ["float"], }, @@ -44,6 +44,8 @@ export class GraphManager { private _edges: Edge[] = []; edges: Writable = writable([]); + inputSockets: Writable> = writable(new Set()); + history: HistoryManager = new HistoryManager(this); private constructor(private graph: Graph, private nodeRegistry: NodeRegistry = new NodeRegistry()) { @@ -52,6 +54,11 @@ export class GraphManager { }); this.edges.subscribe((edges) => { this._edges = edges; + const s = new Set(); + for (const edge of edges) { + s.add(`${edge[2].id}-${edge[3]}`); + } + this.inputSockets.set(s); }); } diff --git a/frontend/src/lib/types/inputs.ts b/frontend/src/lib/types/inputs.ts index 31465ab..c1d80be 100644 --- a/frontend/src/lib/types/inputs.ts +++ b/frontend/src/lib/types/inputs.ts @@ -3,6 +3,7 @@ type NodeInputFloat = { value?: number; min?: number; max?: number; + step?: number; } type NodeInputInteger = { @@ -12,6 +13,11 @@ type NodeInputInteger = { max?: number; } +type NodeInputBoolean = { + type: "boolean"; + value?: boolean; +} + type NodeInputSelect = { type: "select"; value?: string; @@ -22,4 +28,4 @@ type DefaultOptions = { internal?: boolean; } -export type NodeInput = (NodeInputFloat | NodeInputInteger | NodeInputSelect) & DefaultOptions; +export type NodeInput = (NodeInputBoolean | NodeInputFloat | NodeInputInteger | NodeInputSelect) & DefaultOptions; diff --git a/frontend/src/routes/app.css b/frontend/src/routes/app.css index d1123ae..e46dfb4 100644 --- a/frontend/src/routes/app.css +++ b/frontend/src/routes/app.css @@ -21,8 +21,8 @@ } :root { - font-family: 'Fira Code', monospace; - + --font-family: 'Fira Code', monospace; + font-family: var(--font-family); /* Spacing */ --spacing-xs: 4px; @@ -48,6 +48,8 @@ body { --background-color: #151515; --background-color-darker: #101010; --text-color: #aeaeae; + + background-color: var(--background-color-darker); } body.theme-catppuccin {