Skip to content

Instantly share code, notes, and snippets.

@ThomasKruegl
Created July 5, 2018 00:16
Show Gist options
  • Save ThomasKruegl/699334c44c58a137c32fd71935f028a3 to your computer and use it in GitHub Desktop.
Save ThomasKruegl/699334c44c58a137c32fd71935f028a3 to your computer and use it in GitHub Desktop.
const litegraph = require("litegraph.js").LiteGraph;
litegraph.debug = true;
class TickEVENT extends (litegraph.LGraphNode as { new(): any; }) {
public static title: string = "Event Tick";
public static desc: string = "";
constructor() {
super();
this.size = [60,20];
this.addOutput("Start", litegraph.EVENT);
this.properties = {
equal_to: "",
has_property: "",
property_equal_to: ""
}
}
public onExecute() {
this.triggerSlot(0);
}
public onAction(action: any, param: any) {
if( param == null )
return;
if( this.properties.equal_to && this.properties.equal_to != param )
return;
if( this.properties.has_property )
{
const prop = param[ this.properties.has_property ];
if( prop == null )
return;
if( this.properties.property_equal_to && this.properties.property_equal_to != prop )
return;
}
this.triggerSlot(0,param);
}
}
litegraph.registerNodeType("events/TickEvent", TickEVENT );
class MyAddNode extends (litegraph.LGraphNode as { new(): any; }) {
public static title: string = "Sum";
constructor() {
super();
this.addInput("A", "number");
this.addInput("B", "number");
this.addOutput("A+B", "number");
}
public onExecute() {
let A = this.getInputData(0);
if (A === undefined) {
A = 0;
}
let B = this.getInputData(1);
if (B === undefined) {
B = 0;
}
this.setOutputData(0, A + B);
}
}
litegraph.registerNodeType("foo/sum", MyAddNode);
const graph = new litegraph.LGraph();
const node_time = litegraph.createNode("basic/time");
graph.add(node_time);
const node_console = litegraph.createNode("basic/console");
node_console.mode = litegraph.ALWAYS;
graph.add(node_console);
node_time.connect( 0, node_console, 1 );
graph.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment