This commit is contained in:
Sam Lavigne 2023-08-24 12:09:55 -04:00
parent 2ab5af0235
commit 648dadaeca
2 changed files with 28 additions and 3 deletions

View File

@ -1,7 +1,7 @@
<script> <script>
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import { nodes, edges } from "./stores.js"; import { nodes, edges } from "./stores.js";
import { Anchor, Node, Svelvet, Minimap, Controls } from "svelvet"; import { Anchor, Node, Svelvet} from "svelvet";
function onConnect(e) { function onConnect(e) {
console.log(e); console.log(e);
@ -25,6 +25,7 @@
} }
function onDisconnect(e) { function onDisconnect(e) {
console.log('dis', e);
const sourceAnchor = e.detail.sourceAnchor.id; const sourceAnchor = e.detail.sourceAnchor.id;
const targetAnchor = e.detail.targetAnchor.id; const targetAnchor = e.detail.targetAnchor.id;
const source = e.detail.sourceNode.id; const source = e.detail.sourceNode.id;
@ -80,7 +81,6 @@
</div> </div>
</Node> </Node>
{/each} {/each}
<Controls />
</Svelvet> </Svelvet>
<style> <style>

View File

@ -6,6 +6,7 @@ import { writable, derived, get } from "svelte/store";
// export const filters = writable([]); // export const filters = writable([]);
export const nodes = writable([]); export const nodes = writable([]);
export const edges = writable([]); export const edges = writable([]);
export const auto = writable(true);
addNode({ name: "punch.mp4" }, "input"); addNode({ name: "punch.mp4" }, "input");
addNode({ name: "out.mp4" }, "output"); addNode({ name: "out.mp4" }, "output");
@ -42,7 +43,6 @@ export const previewCommand = derived([edges, nodes], ([$edges, $nodes]) => {
inputIds[inp.id] = i; inputIds[inp.id] = i;
} }
console.log($edges)
const edgeIds = {}; const edgeIds = {};
for (let i = 0; i < $edges.length; i++) { for (let i = 0; i < $edges.length; i++) {
const e = $edges[i]; const e = $edges[i];
@ -51,6 +51,8 @@ export const previewCommand = derived([edges, nodes], ([$edges, $nodes]) => {
const source = $nodes.find(n => "N-" + n.id === e.source); const source = $nodes.find(n => "N-" + n.id === e.source);
const target = $nodes.find(n => "N-" + n.id === e.target); const target = $nodes.find(n => "N-" + n.id === e.target);
if (!source || !target) continue;
if (source.nodeType === "input") { if (source.nodeType === "input") {
if (e.sourceAnchor.startsWith("A-v")) { if (e.sourceAnchor.startsWith("A-v")) {
edgeIds[e.id] = inputIds[source.id] + ":v"; edgeIds[e.id] = inputIds[source.id] + ":v";
@ -270,6 +272,8 @@ export function addNode(data, type) {
const margin = 10; const margin = 10;
const existing = get(nodes); const existing = get(nodes);
const ouputNode = existing.find(n => n.nodeType === 'output');
const inputNodes = existing.find(n => n.nodeType === "input");
if (type === "input") { if (type === "input") {
const inps = existing.filter((n) => n.nodeType === "input"); const inps = existing.filter((n) => n.nodeType === "input");
@ -284,6 +288,7 @@ export function addNode(data, type) {
data.inputs = ins; data.inputs = ins;
data.outputs = outs; data.outputs = outs;
let node = { let node = {
id: uuidv4(), id: uuidv4(),
type: "ffmpeg", type: "ffmpeg",
@ -297,6 +302,16 @@ export function addNode(data, type) {
return n; return n;
}); });
if (auto) {
const prev = existing[existing.length - 2];
if (prev) {
// set each prev out to new node in
// set new node out to output in
}
}
//autolayout();
// edges.update((_edges) => { // edges.update((_edges) => {
// const target = existing[existing.length - 2]; // const target = existing[existing.length - 2];
// if (!target) return _edges; // if (!target) return _edges;
@ -317,4 +332,14 @@ export function removeNode(id) {
_nodes.splice(index, 1); _nodes.splice(index, 1);
return _nodes; return _nodes;
}); });
edges.update((_edges) => {
for (let i=_edges.length-1; i--; i>=0) {
const e = _edges[i];
if ("N-" + e.source === id || "N-" + e.target === id) {
_edges.splice(i, 1);
}
}
return _edges;
});
} }