diff --git a/src/LGraph.ts b/src/LGraph.ts index d21cc309a..5c8aafb97 100644 --- a/src/LGraph.ts +++ b/src/LGraph.ts @@ -118,7 +118,7 @@ export class LGraph implements LinkNetwork, Serialisable { nodes_executing: boolean[] = [] nodes_actioning: (string | boolean)[] = [] nodes_executedAction: string[] = [] - extra: Record = {} + extra: Record = {} inputs: Dictionary = {} outputs: Dictionary = {} @@ -1471,14 +1471,14 @@ export class LGraph implements LinkNetwork, Serialisable { const linkArray = [...this._links.values()] const links = linkArray.map(x => x.serialize()) - if (reroutes.length) { + if (reroutes?.length) { // Link parent IDs cannot go in 0.4 schema arrays extra.linkExtensions = linkArray .filter(x => x.parentId !== undefined) .map(x => ({ id: x.id, parentId: x.parentId })) } - extra.reroutes = reroutes.length ? reroutes : undefined + extra.reroutes = reroutes?.length ? reroutes : undefined return { last_node_id: state.lastNodeId, last_link_id: state.lastLinkId, @@ -1499,7 +1499,7 @@ export class LGraph implements LinkNetwork, Serialisable { * Mutating the properties of the return object may result in changes to your graph. * It is intended for use with {@link structuredClone} or {@link JSON.stringify}. */ - asSerialisable(options?: { sortNodes: boolean }): Required { + asSerialisable(options?: { sortNodes: boolean }): SerialisableGraph & Required> { const { config, state, extra } = this const nodeList = !LiteGraph.use_uuids && options?.sortNodes @@ -1510,10 +1510,10 @@ export class LGraph implements LinkNetwork, Serialisable { const nodes = nodeList.map(node => node.serialize()) const groups = this._groups.map(x => x.serialize()) - const links = [...this._links.values()].map(x => x.asSerialisable()) - const reroutes = [...this.reroutes.values()].map(x => x.asSerialisable()) + const links = this._links.size ? [...this._links.values()].map(x => x.asSerialisable()) : undefined + const reroutes = this.reroutes.size ? [...this.reroutes.values()].map(x => x.asSerialisable()) : undefined - const data: Required = { + const data: ReturnType = { version: LGraph.serialisedSchemaVersion, config, state, @@ -1542,11 +1542,11 @@ export class LGraph implements LinkNetwork, Serialisable { if (!data) return if (!keep_old) this.clear() - const { extra } = data let reroutes: SerialisableReroute[] | undefined // TODO: Determine whether this should this fall back to 0.4. if (data.version === 0.4) { + const { extra } = data // Deprecated - old schema version, links are arrays if (Array.isArray(data.links)) { for (const linkData of data.links) { diff --git a/src/LGraphNode.ts b/src/LGraphNode.ts index 331ac6bb1..4f69499e4 100644 --- a/src/LGraphNode.ts +++ b/src/LGraphNode.ts @@ -2578,7 +2578,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { input.link = null // remove the link from the links pool - graph._links.delete(link_id) + link_info.disconnect(graph) graph._version++ // link_info hasn't been modified so its ok @@ -2625,7 +2625,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { ) } // remove the link from the links pool - graph._links.delete(link_id) + link_info.disconnect(graph) this.onConnectionsChange?.( NodeSlotType.OUTPUT, diff --git a/src/Reroute.ts b/src/Reroute.ts index 2e561ff90..3b355938c 100644 --- a/src/Reroute.ts +++ b/src/Reroute.ts @@ -67,9 +67,6 @@ export class Reroute implements Positionable, LinkSegment, Serialisable - /** The averaged angle of every link through this reroute. */ - otherAngle: number = 0 - /** Cached cos */ cos: number = 0 sin: number = 0 @@ -95,7 +92,6 @@ export class Reroute implements Positionable, LinkSegment, Serialisable + readonly reroutes: ReadonlyMap + getNodeById(id: NodeId): LGraphNode | null +} + /** * Contains a list of links, reroutes, and nodes. */ -export interface LinkNetwork { +export interface LinkNetwork extends ReadonlyLinkNetwork { readonly links: Map readonly reroutes: Map getNodeById(id: NodeId): LGraphNode | null diff --git a/src/types/serialisation.ts b/src/types/serialisation.ts index a46033136..699a2afdf 100644 --- a/src/types/serialisation.ts +++ b/src/types/serialisation.ts @@ -37,7 +37,7 @@ export interface SerialisableGraph { nodes?: ISerialisedNode[] links?: SerialisableLLink[] reroutes?: SerialisableReroute[] - extra?: Record + extra?: Dictionary } export type ISerialisableNodeInput = Omit & { @@ -86,7 +86,9 @@ export interface ISerialisedGraph { groups: ISerialisedGroup[] config: LGraphConfig version: typeof LiteGraph.VERSION - extra?: Record + extra?: Dictionary & { + reroutes?: SerialisableReroute[] + } } /** Serialised LGraphGroup */