From 802156e5a018d1efdfd58e085fcec16e87365c62 Mon Sep 17 00:00:00 2001 From: ilya Date: Mon, 13 Jul 2020 19:54:24 +0300 Subject: [PATCH 1/2] TypeDef updates and fix of method declaration --- src/litegraph.d.ts | 5 +++++ src/litegraph.js | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/litegraph.d.ts b/src/litegraph.d.ts index b524fd0d2..4f2a875d4 100644 --- a/src/litegraph.d.ts +++ b/src/litegraph.d.ts @@ -16,6 +16,7 @@ export type SlotShape = | typeof LiteGraph.CIRCLE_SHAPE | typeof LiteGraph.ARROW_SHAPE | typeof LiteGraph.SQUARE_SHAPE + | number; // For custom shapes /** https://github.com/jagenjo/litegraph.js/tree/master/guides#node-slots */ export interface INodeSlot { @@ -238,6 +239,8 @@ export const LiteGraph: { registerNodeType(type: string, base: { new (): LGraphNode }): void; /** removes a node type from the system */ unregisterNodeType(type: string): void; + /** Removes all previously registered node's types. */ + clearRegisteredTypes(): void; /** * Create a new node type by passing a function, it wraps it with a proper class and generates inputs according to the parameters of the function. * Useful to wrap simple methods that do not require properties, and that only process some input to generate an output. @@ -1308,6 +1311,8 @@ export declare class LGraphCanvas { drawBackCanvas(): void; /** draws the given node inside the canvas */ drawNode(node: LGraphNode, ctx: CanvasRenderingContext2D): void; + /** draws graphic for node's slot */ + drawSlotGraphic(ctx: CanvasRenderingContext2D, pos: number[], shape: SlotShape, horizontal: boolean): void; /** draws the shape of the given node in the canvas */ drawNodeShape( node: LGraphNode, diff --git a/src/litegraph.js b/src/litegraph.js index b3aed4324..0b5b3792c 100755 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -6978,7 +6978,7 @@ LGraphNode.prototype.executeAction = function(action) var temp_vec2 = new Float32Array(2); - function drawSlotGraphic(ctx, pos, shape, horizontal) { + LGraphCanvas.prototype.drawSlotGraphic = function(ctx, pos, shape, horizontal) { ctx.beginPath(); switch (shape) { @@ -7173,7 +7173,7 @@ LGraphNode.prototype.executeAction = function(action) var shape = slot.shape || (slot.type === LiteGraph.EVENT && LiteGraph.BOX_SHAPE) || (low_quality && LiteGraph.SQUARE_SHAPE) || LiteGraph.CIRCLE_SHAPE; - drawSlotGraphic(ctx, pos, shape, horizontal); + this.drawSlotGraphic(ctx, pos, shape, horizontal); //render name if (render_text) { @@ -7217,7 +7217,7 @@ LGraphNode.prototype.executeAction = function(action) var shape = slot.shape || (slot.type === LiteGraph.EVENT && LiteGraph.BOX_SHAPE) || (low_quality && LiteGraph.SQUARE_SHAPE) || LiteGraph.CIRCLE_SHAPE; - drawSlotGraphic(ctx, pos, shape, horizontal); + this.drawSlotGraphic(ctx, pos, shape, horizontal); if(!low_quality) ctx.stroke(); From 5fdce48481a937ecd2a5d927d2befde8214813b6 Mon Sep 17 00:00:00 2001 From: ilya Date: Mon, 13 Jul 2020 20:10:30 +0300 Subject: [PATCH 2/2] Fixed broken connect method --- src/litegraph.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/litegraph.js b/src/litegraph.js index 0b5b3792c..65117d8f1 100755 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -3603,10 +3603,14 @@ return null; } + var output = this.outputs[slot]; + var input = target_node.inputs[target_slot]; + if (LiteGraph.isValidConnection(output.type, input.type)) { if (target_node.onBeforeConnectInput) { // This way node can choose another slot (if selected is occupied) target_slot = target_node.onBeforeConnectInput(target_slot); + input = target_node.inputs[target_slot]; } //if there is something already plugged there, disconnect @@ -3618,8 +3622,6 @@ //this.setDirtyCanvas(false,true); //this.graph.connectionChange( this ); - var output = this.outputs[slot]; - //allows nodes to block connection if (target_node.onConnectInput) { if ( target_node.onConnectInput(target_slot, output.type, output, this, slot) === false ) { @@ -3627,7 +3629,6 @@ } } - var input = target_node.inputs[target_slot]; var link_info = null; link_info = new LLink(