2024-03-06 14:01:07 +01:00
|
|
|
<script lang="ts">
|
2024-04-10 14:27:23 +02:00
|
|
|
import Grid from "$lib/grid";
|
2024-04-15 22:13:43 +02:00
|
|
|
import GraphInterface from "$lib/graph-interface";
|
2024-04-25 01:53:20 +02:00
|
|
|
import { WorkerRuntimeExecutor } from "$lib/worker-runtime-executor";
|
2024-04-20 02:41:18 +02:00
|
|
|
import { RemoteNodeRegistry } from "$lib/node-registry-client";
|
2024-04-10 15:40:01 +02:00
|
|
|
import * as templates from "$lib/graph-templates";
|
2024-04-23 19:14:27 +02:00
|
|
|
import type { Graph, Node } from "@nodes/types";
|
2024-04-20 02:41:18 +02:00
|
|
|
import Viewer from "$lib/result-viewer/Viewer.svelte";
|
2024-04-18 18:39:24 +02:00
|
|
|
import Settings from "$lib/settings/Settings.svelte";
|
2024-04-25 01:53:20 +02:00
|
|
|
import { AppSettingTypes, AppSettings } from "$lib/settings/app-settings";
|
|
|
|
import { writable, type Writable } from "svelte/store";
|
2024-04-24 19:11:00 +02:00
|
|
|
import Keymap from "$lib/settings/panels/Keymap.svelte";
|
2024-04-19 22:00:43 +02:00
|
|
|
import type { createKeyMap } from "$lib/helpers/createKeyMap";
|
2024-04-20 02:41:18 +02:00
|
|
|
import NodeStore from "$lib/node-store/NodeStore.svelte";
|
|
|
|
import type { GraphManager } from "$lib/graph-interface/graph-manager";
|
|
|
|
import { setContext } from "svelte";
|
2024-04-24 01:40:04 +02:00
|
|
|
import {
|
|
|
|
decodeFloat,
|
|
|
|
decodeNestedArray,
|
|
|
|
encodeNestedArray,
|
|
|
|
} from "@nodes/utils";
|
2024-04-25 01:53:20 +02:00
|
|
|
import ActiveNodeSettings from "$lib/settings/panels/ActiveNodeSettings.svelte";
|
2024-04-25 00:02:02 +02:00
|
|
|
import PerformanceViewer from "$lib/performance/PerformanceViewer.svelte";
|
2024-04-25 01:53:20 +02:00
|
|
|
import Panel from "$lib/settings/Panel.svelte";
|
|
|
|
import GraphSettings from "$lib/settings/panels/GraphSettings.svelte";
|
|
|
|
import NestedSettings from "$lib/settings/panels/NestedSettings.svelte";
|
2024-04-25 03:37:52 +02:00
|
|
|
import { createPerformanceStore } from "$lib/performance";
|
|
|
|
import { type PerformanceData } from "$lib/performance/store";
|
2024-04-25 00:02:02 +02:00
|
|
|
|
2024-04-20 02:41:18 +02:00
|
|
|
const nodeRegistry = new RemoteNodeRegistry("");
|
2024-04-25 01:53:20 +02:00
|
|
|
const workerRuntime = new WorkerRuntimeExecutor();
|
|
|
|
|
|
|
|
let performanceData: PerformanceData;
|
2024-04-25 03:37:52 +02:00
|
|
|
let viewerPerformance = createPerformanceStore();
|
2024-03-19 16:41:15 +01:00
|
|
|
|
2024-04-22 16:52:52 +02:00
|
|
|
globalThis.decode = decodeNestedArray;
|
2024-04-23 03:41:28 +02:00
|
|
|
globalThis.encode = encodeNestedArray;
|
2024-04-24 01:40:04 +02:00
|
|
|
globalThis.decodeFloat = decodeFloat;
|
2024-04-22 16:52:52 +02:00
|
|
|
|
2024-04-16 15:32:23 +02:00
|
|
|
let res: Int32Array;
|
2024-04-23 19:14:27 +02:00
|
|
|
let activeNode: Node | undefined;
|
2024-03-19 16:56:42 +01:00
|
|
|
|
2024-04-10 15:40:01 +02:00
|
|
|
let graph = localStorage.getItem("graph")
|
|
|
|
? JSON.parse(localStorage.getItem("graph")!)
|
|
|
|
: templates.grid(3, 3);
|
2024-03-19 16:56:42 +01:00
|
|
|
|
2024-04-20 02:41:18 +02:00
|
|
|
let manager: GraphManager;
|
2024-04-19 02:36:11 +02:00
|
|
|
let managerStatus: Writable<"loading" | "error" | "idle">;
|
2024-04-20 02:41:18 +02:00
|
|
|
$: if (manager) {
|
|
|
|
setContext("graphManager", manager);
|
|
|
|
}
|
2024-04-19 02:36:11 +02:00
|
|
|
|
2024-04-19 22:00:43 +02:00
|
|
|
let keymap: ReturnType<typeof createKeyMap>;
|
2024-04-25 01:53:20 +02:00
|
|
|
let graphSettings = writable<Record<string, any>>({});
|
|
|
|
let graphSettingTypes = {};
|
2024-04-19 22:00:43 +02:00
|
|
|
|
2024-04-25 03:37:52 +02:00
|
|
|
let isWorking = false;
|
|
|
|
|
|
|
|
let unfinished:
|
|
|
|
| {
|
|
|
|
graph: Graph;
|
|
|
|
settings: Record<string, any>;
|
|
|
|
}
|
|
|
|
| undefined;
|
|
|
|
|
|
|
|
async function handleResult(_graph: Graph, _settings: Record<string, any>) {
|
|
|
|
if (!_settings) return;
|
|
|
|
if (isWorking) {
|
|
|
|
unfinished = {
|
|
|
|
graph: _graph,
|
|
|
|
settings: _settings,
|
|
|
|
};
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isWorking = true;
|
2024-04-24 22:16:15 +02:00
|
|
|
try {
|
2024-04-25 03:37:52 +02:00
|
|
|
res = await workerRuntime.execute(_graph, _settings);
|
2024-04-25 01:53:20 +02:00
|
|
|
performanceData = await workerRuntime.getPerformanceData();
|
2024-04-25 03:37:52 +02:00
|
|
|
isWorking = false;
|
2024-04-24 22:16:15 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.log("errors", error);
|
|
|
|
}
|
2024-04-25 03:37:52 +02:00
|
|
|
|
|
|
|
if (unfinished) {
|
|
|
|
let d = unfinished;
|
|
|
|
unfinished = undefined;
|
|
|
|
handleResult(d.graph, d.settings);
|
|
|
|
}
|
2024-04-10 15:40:01 +02:00
|
|
|
}
|
2024-04-18 18:39:24 +02:00
|
|
|
|
2024-04-25 01:53:20 +02:00
|
|
|
$: if (AppSettings) {
|
|
|
|
//@ts-ignore
|
|
|
|
AppSettingTypes.debug.stressTest.loadGrid.callback = () => {
|
|
|
|
graph = templates.grid($AppSettings.amount, $AppSettings.amount);
|
2024-04-19 22:00:43 +02:00
|
|
|
};
|
2024-04-25 01:53:20 +02:00
|
|
|
//@ts-ignore
|
|
|
|
AppSettingTypes.debug.stressTest.loadTree.callback = () => {
|
2024-04-25 03:37:52 +02:00
|
|
|
graph = templates.tree($AppSettings.amount);
|
2024-04-20 02:41:18 +02:00
|
|
|
};
|
2024-04-23 19:14:27 +02:00
|
|
|
}
|
|
|
|
|
2024-04-25 01:53:20 +02:00
|
|
|
function handleSave(event: CustomEvent<Graph>) {
|
|
|
|
localStorage.setItem("graph", JSON.stringify(event.detail));
|
2024-04-18 18:39:24 +02:00
|
|
|
}
|
2024-03-06 14:01:07 +01:00
|
|
|
</script>
|
|
|
|
|
2024-04-19 02:36:11 +02:00
|
|
|
<div class="wrapper manager-{$managerStatus}">
|
|
|
|
<header></header>
|
2024-04-10 14:27:23 +02:00
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Cell>
|
2024-04-25 03:37:52 +02:00
|
|
|
<Viewer
|
|
|
|
centerCamera={$AppSettings.centerCamera}
|
|
|
|
result={res}
|
|
|
|
perf={viewerPerformance}
|
|
|
|
/>
|
2024-04-10 15:40:01 +02:00
|
|
|
</Grid.Cell>
|
|
|
|
<Grid.Cell>
|
|
|
|
{#key graph}
|
2024-04-10 21:57:03 +02:00
|
|
|
<GraphInterface
|
2024-04-25 01:53:20 +02:00
|
|
|
{graph}
|
|
|
|
registry={nodeRegistry}
|
2024-04-20 02:41:18 +02:00
|
|
|
bind:manager
|
2024-04-23 19:14:27 +02:00
|
|
|
bind:activeNode
|
2024-04-19 22:00:43 +02:00
|
|
|
bind:keymap
|
2024-04-22 16:52:52 +02:00
|
|
|
showGrid={$AppSettings?.showNodeGrid}
|
|
|
|
snapToGrid={$AppSettings?.snapToGrid}
|
2024-04-25 01:53:20 +02:00
|
|
|
bind:settings={graphSettings}
|
|
|
|
bind:settingTypes={graphSettingTypes}
|
2024-04-25 03:37:52 +02:00
|
|
|
on:result={(ev) => handleResult(ev.detail, $graphSettings)}
|
2024-04-10 15:40:01 +02:00
|
|
|
on:save={handleSave}
|
|
|
|
/>
|
2024-04-25 01:53:20 +02:00
|
|
|
<Settings>
|
|
|
|
<Panel id="general" title="General" icon="i-tabler-settings">
|
|
|
|
<NestedSettings
|
|
|
|
id="general"
|
|
|
|
store={AppSettings}
|
|
|
|
settings={AppSettingTypes}
|
|
|
|
/>
|
|
|
|
</Panel>
|
|
|
|
<Panel id="node-store" title="Node Store" icon="i-tabler-database">
|
|
|
|
<NodeStore registry={nodeRegistry} />
|
|
|
|
</Panel>
|
|
|
|
<Panel
|
|
|
|
id="performance"
|
|
|
|
title="Performance"
|
|
|
|
icon="i-tabler-brand-speedtest"
|
|
|
|
>
|
|
|
|
{#if performanceData}
|
2024-04-25 03:37:52 +02:00
|
|
|
<PerformanceViewer
|
|
|
|
data={performanceData}
|
|
|
|
viewer={$viewerPerformance}
|
|
|
|
/>
|
2024-04-25 01:53:20 +02:00
|
|
|
{/if}
|
|
|
|
</Panel>
|
|
|
|
<Panel
|
|
|
|
id="shortcuts"
|
|
|
|
title="Keyboard Shortcuts"
|
|
|
|
icon="i-tabler-keyboard"
|
|
|
|
>
|
|
|
|
{#if keymap}
|
|
|
|
<Keymap {keymap} />
|
|
|
|
{/if}
|
|
|
|
</Panel>
|
|
|
|
<Panel
|
|
|
|
id="graph-settings"
|
|
|
|
title="Graph Settings"
|
|
|
|
icon="i-tabler-brand-git"
|
|
|
|
>
|
|
|
|
{#if Object.keys(graphSettingTypes).length > 0}
|
|
|
|
<GraphSettings type={graphSettingTypes} store={graphSettings} />
|
|
|
|
{/if}
|
|
|
|
</Panel>
|
|
|
|
<Panel
|
|
|
|
id="active-node"
|
|
|
|
title="Node Settings"
|
|
|
|
icon="i-tabler-adjustments"
|
|
|
|
>
|
|
|
|
<ActiveNodeSettings {manager} node={activeNode} />
|
|
|
|
</Panel>
|
|
|
|
</Settings>
|
2024-04-10 15:40:01 +02:00
|
|
|
{/key}
|
2024-04-10 14:27:23 +02:00
|
|
|
</Grid.Cell>
|
|
|
|
</Grid.Row>
|
2024-03-06 14:01:07 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
2024-04-10 14:27:23 +02:00
|
|
|
header {
|
2024-04-22 22:27:21 +02:00
|
|
|
/* border-bottom: solid thin var(--outline); */
|
2024-04-19 01:27:11 +02:00
|
|
|
background-color: var(--layer-1);
|
2024-03-06 14:01:07 +01:00
|
|
|
}
|
|
|
|
|
2024-03-20 02:17:58 +01:00
|
|
|
.wrapper {
|
2024-04-10 14:27:23 +02:00
|
|
|
height: 100vh;
|
|
|
|
width: 100vw;
|
|
|
|
color: white;
|
|
|
|
display: grid;
|
2024-04-22 22:27:21 +02:00
|
|
|
grid-template-rows: 0px 1fr;
|
2024-04-10 14:27:23 +02:00
|
|
|
}
|
|
|
|
|
2024-04-19 02:36:11 +02:00
|
|
|
.wrapper :global(canvas) {
|
|
|
|
transition: opacity 0.3s ease;
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
.manager-loading :global(.graph-wrapper),
|
|
|
|
.manager-loading :global(canvas) {
|
|
|
|
opacity: 0.2;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
2024-03-06 14:01:07 +01:00
|
|
|
:global(html) {
|
|
|
|
background: rgb(13, 19, 32);
|
|
|
|
background: linear-gradient(
|
|
|
|
180deg,
|
|
|
|
rgba(13, 19, 32, 1) 0%,
|
|
|
|
rgba(8, 12, 21, 1) 100%
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
:global(body) {
|
|
|
|
margin: 0;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
</style>
|