From 5421349c791739557fafd0403db736aa3648e22c Mon Sep 17 00:00:00 2001 From: Max Richter Date: Fri, 8 Nov 2024 02:38:19 +0100 Subject: [PATCH] feat: migrate some more stuff to svelte-5, mainly app settings --- app/package.json | 1 - app/src/lib/graph-interface/graph-manager.ts | 19 +-- .../lib/graph-interface/graph/Graph.svelte | 7 +- .../lib/graph-interface/graph/Wrapper.svelte | 10 +- app/src/lib/graph-interface/graph/colors.ts | 1 - .../lib/graph-interface/graph/state.svelte.ts | 9 +- .../lib/graph-interface/node/NodeHTML.svelte | 1 - .../graph-interface/node/NodeHeader.svelte | 4 +- .../graph-interface/node/NodeParameter.svelte | 8 +- app/src/lib/helpers/deepMerge.ts | 24 +++ app/src/lib/helpers/localState.svelte.ts | 11 ++ app/src/lib/node-store/DraggableNode.svelte | 1 + app/src/lib/node-store/NodeStore.svelte | 5 +- .../performance/SmallPerformanceViewer.svelte | 63 ++++---- app/src/lib/result-viewer/Scene.svelte | 32 ++-- .../src => app/src/lib/runtime}/index.ts | 1 + .../lib/runtime}/remote-runtime-executor.ts | 0 .../lib/runtime}/runtime-executor-cache.ts | 0 .../src/lib/runtime}/runtime-executor.ts | 0 .../worker-runtime-executor-backend.ts | 0 .../lib/runtime}/worker-runtime-executor.ts | 5 +- app/src/lib/settings/Settings.svelte | 1 + app/src/lib/settings/app-settings.svelte.ts | 153 ++++++++++++++++++ .../settings/panels/ActiveNodeSettings.svelte | 2 +- .../lib/settings/panels/ExportSettings.svelte | 3 + .../lib/settings/panels/NestedSettings.svelte | 128 +++++++++------ app/src/routes/+page.svelte | 11 +- nodes/max/plantarium/gravity/src/input.json | 2 + nodes/max/plantarium/vec3/src/input.json | 3 + packages/runtime/package.json | 21 --- packages/types/src/settings.ts | 7 + packages/ui/src/lib/app.css | 3 - packages/ui/src/lib/elements/Checkbox.svelte | 3 +- packages/ui/src/lib/elements/Select.svelte | 1 - 34 files changed, 375 insertions(+), 165 deletions(-) create mode 100644 app/src/lib/helpers/deepMerge.ts create mode 100644 app/src/lib/helpers/localState.svelte.ts rename {packages/runtime/src => app/src/lib/runtime}/index.ts (99%) rename {packages/runtime/src => app/src/lib/runtime}/remote-runtime-executor.ts (100%) rename {packages/runtime/src => app/src/lib/runtime}/runtime-executor-cache.ts (100%) rename {packages/runtime/src => app/src/lib/runtime}/runtime-executor.ts (100%) rename {packages/runtime/src => app/src/lib/runtime}/worker-runtime-executor-backend.ts (100%) rename {packages/runtime/src => app/src/lib/runtime}/worker-runtime-executor.ts (84%) create mode 100644 app/src/lib/settings/app-settings.svelte.ts delete mode 100644 packages/runtime/package.json create mode 100644 packages/types/src/settings.ts diff --git a/app/package.json b/app/package.json index f6eeaeb..f27c68c 100644 --- a/app/package.json +++ b/app/package.json @@ -11,7 +11,6 @@ }, "dependencies": { "@nodes/registry": "link:../packages/registry", - "@nodes/runtime": "link:../packages/runtime", "@nodes/ui": "link:../packages/ui", "@nodes/utils": "link:../packages/utils", "@sveltejs/kit": "^2.7.4", diff --git a/app/src/lib/graph-interface/graph-manager.ts b/app/src/lib/graph-interface/graph-manager.ts index 3e8c5db..c962126 100644 --- a/app/src/lib/graph-interface/graph-manager.ts +++ b/app/src/lib/graph-interface/graph-manager.ts @@ -29,16 +29,22 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any, " private _nodes: Map = new Map(); nodes: Writable> = writable(new Map()); - settingTypes: Record = {}; - settings: Record = {}; + private _edges: Edge[] = []; edges: Writable = writable([]); + settingTypes: Record = {}; + settings: Record = {}; + currentUndoGroup: number | null = null; inputSockets: Writable> = writable(new Set()); history: HistoryManager = new HistoryManager(); + execute = throttle(() => { + if (this.loaded === false) return; + this.emit("result", this.serialize()); + }, 10); constructor(public registry: NodeRegistry) { super(); @@ -53,7 +59,6 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any, " } this.inputSockets.set(s); }); - this.execute = throttle(() => this._execute(), 10); } serialize(): Graph { @@ -67,7 +72,6 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any, " const edges = this._edges.map(edge => [edge[0].id, edge[1], edge[2].id, edge[3]]) as Graph["edges"]; const serialized = { id: this.graph.id, settings: this.settings, nodes, edges }; logger.groupEnd(); - console.log({ serialized }); return clone(serialized); } @@ -86,11 +90,6 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any, " } - execute() { } - _execute() { - if (this.loaded === false) return; - this.emit("result", this.serialize()); - } getNodeDefinitions() { return this.registry.getAllNodes(); @@ -111,9 +110,7 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any, " return [...nodes.values()]; } - getEdgesBetweenNodes(nodes: Node[]): [number, number, number, string][] { - const edges = []; for (const node of nodes) { const children = node.tmp?.children || []; diff --git a/app/src/lib/graph-interface/graph/Graph.svelte b/app/src/lib/graph-interface/graph/Graph.svelte index b06cfbd..b51f7fc 100644 --- a/app/src/lib/graph-interface/graph/Graph.svelte +++ b/app/src/lib/graph-interface/graph/Graph.svelte @@ -21,11 +21,10 @@ import HelpView from "../HelpView.svelte"; import FileSaver from "file-saver"; import { Canvas } from "@threlte/core"; + import { getGraphManager } from "./context.js"; const state = getGraphState(); - export let manager: GraphManager; - export let snapToGrid = true; export let showGrid = true; export let showHelp = false; @@ -33,7 +32,8 @@ let keymap = getContext>("keymap") || createKeyMap([]); - setContext("graphManager", manager); + const manager = getGraphManager(); + const status = manager.status; const nodes = manager.nodes; const edges = manager.edges; @@ -965,6 +965,7 @@ - diff --git a/packages/ui/src/lib/elements/Select.svelte b/packages/ui/src/lib/elements/Select.svelte index c657512..39fc11f 100644 --- a/packages/ui/src/lib/elements/Select.svelte +++ b/packages/ui/src/lib/elements/Select.svelte @@ -25,4 +25,3 @@ border: none; } -