mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-07 16:40:05 +00:00
Integration and Fixes
- few new nodes - onAction, onExecute, onTrigger has the third parameters for additional options - onAction has to refresh the getInputData values for future behaviours - prefer 0 or "*" for slot type instead of empty string ""
This commit is contained in:
@@ -997,7 +997,7 @@ LiteGraph.registerNodeType("audio/waveShaper", LGAudioWaveShaper);
|
||||
this.audionode = LGAudio.getAudioContext().createGain();
|
||||
this.audionode.gain.value = 0;
|
||||
this.addInput("in", "audio");
|
||||
this.addInput("gate", "bool");
|
||||
this.addInput("gate", "boolean");
|
||||
this.addOutput("out", "audio");
|
||||
this.gate = false;
|
||||
}
|
||||
|
||||
@@ -724,9 +724,10 @@
|
||||
LiteGraph.registerNodeType("basic/const", ConstantNumber);
|
||||
|
||||
function ConstantBoolean() {
|
||||
this.addOutput("", "boolean");
|
||||
this.addOutput("bool", "boolean");
|
||||
this.addProperty("value", true);
|
||||
this.widget = this.addWidget("toggle","value",true,"value");
|
||||
this.serialize_widgets = true;
|
||||
this.widgets_up = true;
|
||||
this.size = [140, 30];
|
||||
}
|
||||
@@ -753,7 +754,7 @@
|
||||
LiteGraph.registerNodeType("basic/boolean", ConstantBoolean);
|
||||
|
||||
function ConstantString() {
|
||||
this.addOutput("", "string");
|
||||
this.addOutput("string", "string");
|
||||
this.addProperty("value", "");
|
||||
this.widget = this.addWidget("text","value","","value"); //link to property value
|
||||
this.widgets_up = true;
|
||||
@@ -800,8 +801,8 @@
|
||||
LiteGraph.registerNodeType( "basic/object", ConstantObject );
|
||||
|
||||
function ConstantFile() {
|
||||
this.addInput("url", "");
|
||||
this.addOutput("", "");
|
||||
this.addInput("url", "string");
|
||||
this.addOutput("file", "string");
|
||||
this.addProperty("url", "");
|
||||
this.addProperty("type", "text");
|
||||
this.widget = this.addWidget("text","url","","url");
|
||||
@@ -899,7 +900,7 @@
|
||||
|
||||
//to store json objects
|
||||
function ConstantData() {
|
||||
this.addOutput("", "");
|
||||
this.addOutput("data", "object");
|
||||
this.addProperty("value", "");
|
||||
this.widget = this.addWidget("text","json","","value");
|
||||
this.widgets_up = true;
|
||||
@@ -934,10 +935,10 @@
|
||||
|
||||
//to store json objects
|
||||
function ConstantArray() {
|
||||
this._value = [];
|
||||
this.addInput("", "");
|
||||
this.addOutput("", "array");
|
||||
this.addOutput("length", "number");
|
||||
this._value = [];
|
||||
this.addInput("json", "");
|
||||
this.addOutput("arrayOut", "array");
|
||||
this.addOutput("length", "number");
|
||||
this.addProperty("value", "[]");
|
||||
this.widget = this.addWidget("text","array",this.properties.value,"value");
|
||||
this.widgets_up = true;
|
||||
@@ -974,7 +975,7 @@
|
||||
for(var i = 0; i < v.length; ++i)
|
||||
this._value[i] = v[i];
|
||||
}
|
||||
this.setOutputData(0, this._value );
|
||||
this.setOutputData(0, this._value);
|
||||
this.setOutputData(1, this._value ? ( this._value.length || 0) : 0 );
|
||||
};
|
||||
|
||||
@@ -988,7 +989,7 @@
|
||||
this.addInput("value", "");
|
||||
this.addOutput("arr", "array");
|
||||
this.properties = { index: 0 };
|
||||
this.widget = this.addWidget("number","i",this.properties.index,"index");
|
||||
this.widget = this.addWidget("number","i",this.properties.index,"index",{precision: 0, step: 10, min: 0});
|
||||
}
|
||||
|
||||
SetArray.title = "Set Array";
|
||||
@@ -1062,9 +1063,9 @@
|
||||
LiteGraph.registerNodeType("basic/table[][]", TableElement);
|
||||
|
||||
function ObjectProperty() {
|
||||
this.addInput("obj", "");
|
||||
this.addOutput("", "");
|
||||
this.addProperty("value", "");
|
||||
this.addInput("obj", "object");
|
||||
this.addOutput("property", 0);
|
||||
this.addProperty("value", 0);
|
||||
this.widget = this.addWidget("text","prop.","",this.setValue.bind(this) );
|
||||
this.widgets_up = true;
|
||||
this.size = [140, 30];
|
||||
@@ -1146,9 +1147,9 @@
|
||||
|
||||
|
||||
function MergeObjects() {
|
||||
this.addInput("A", "");
|
||||
this.addInput("B", "");
|
||||
this.addOutput("", "");
|
||||
this.addInput("A", "object");
|
||||
this.addInput("B", "object");
|
||||
this.addOutput("out", "object");
|
||||
this._result = {};
|
||||
var that = this;
|
||||
this.addWidget("button","clear","",function(){
|
||||
@@ -1396,21 +1397,27 @@
|
||||
Console.desc = "Show value inside the console";
|
||||
|
||||
Console.prototype.onAction = function(action, param) {
|
||||
// param is the action
|
||||
var msg = this.getInputData(1); //getInputDataByName("msg");
|
||||
//if (msg == null || typeof msg == "undefined") return;
|
||||
if (!msg) msg = this.properties.msg;
|
||||
if (!msg) msg = "Event: "+param; // msg is undefined if the slot is lost?
|
||||
if (action == "log") {
|
||||
console.log(param);
|
||||
console.log(msg);
|
||||
} else if (action == "warn") {
|
||||
console.warn(param);
|
||||
console.warn(msg);
|
||||
} else if (action == "error") {
|
||||
console.error(param);
|
||||
console.error(msg);
|
||||
}
|
||||
};
|
||||
|
||||
Console.prototype.onExecute = function() {
|
||||
var msg = this.getInputData(1);
|
||||
if (msg !== null) {
|
||||
var msg = this.getInputData(1); //getInputDataByName("msg");
|
||||
if (!msg) msg = this.properties.msg;
|
||||
if (msg != null && typeof msg != "undefined") {
|
||||
this.properties.msg = msg;
|
||||
console.log(msg);
|
||||
}
|
||||
console.log(msg);
|
||||
};
|
||||
|
||||
Console.prototype.onGetInputs = function() {
|
||||
@@ -1455,9 +1462,9 @@
|
||||
function NodeScript() {
|
||||
this.size = [60, 30];
|
||||
this.addProperty("onExecute", "return A;");
|
||||
this.addInput("A", "");
|
||||
this.addInput("B", "");
|
||||
this.addOutput("out", "");
|
||||
this.addInput("A", 0);
|
||||
this.addInput("B", 0);
|
||||
this.addOutput("out", 0);
|
||||
|
||||
this._func = null;
|
||||
this.data = {};
|
||||
@@ -1534,4 +1541,102 @@
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("basic/script", NodeScript);
|
||||
|
||||
|
||||
function GenericCompare() {
|
||||
this.addInput("A", 0);
|
||||
this.addInput("B", 0);
|
||||
this.addOutput("true", "boolean");
|
||||
this.addOutput("false", "boolean");
|
||||
this.addProperty("A", 1);
|
||||
this.addProperty("B", 1);
|
||||
this.addProperty("OP", "==", "enum", { values: GenericCompare.values });
|
||||
this.addWidget("combo","Op.",this.properties.OP,{ property: "OP", values: GenericCompare.values } );
|
||||
|
||||
this.size = [80, 60];
|
||||
}
|
||||
|
||||
GenericCompare.values = ["==", "!="]; //[">", "<", "==", "!=", "<=", ">=", "||", "&&" ];
|
||||
GenericCompare["@OP"] = {
|
||||
type: "enum",
|
||||
title: "operation",
|
||||
values: GenericCompare.values
|
||||
};
|
||||
|
||||
GenericCompare.title = "Compare *";
|
||||
GenericCompare.desc = "evaluates condition between A and B";
|
||||
|
||||
GenericCompare.prototype.getTitle = function() {
|
||||
return "*A " + this.properties.OP + " *B";
|
||||
};
|
||||
|
||||
GenericCompare.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
if (A === undefined) {
|
||||
A = this.properties.A;
|
||||
} else {
|
||||
this.properties.A = A;
|
||||
}
|
||||
|
||||
var B = this.getInputData(1);
|
||||
if (B === undefined) {
|
||||
B = this.properties.B;
|
||||
} else {
|
||||
this.properties.B = B;
|
||||
}
|
||||
|
||||
var result = false;
|
||||
if (typeof A == typeof B){
|
||||
switch (this.properties.OP) {
|
||||
case "==":
|
||||
case "!=":
|
||||
// traverse both objects.. consider that this is not a true deep check! consider underscore or other library for thath :: _isEqual()
|
||||
result = true;
|
||||
switch(typeof A){
|
||||
case "object":
|
||||
var aProps = Object.getOwnPropertyNames(A);
|
||||
var bProps = Object.getOwnPropertyNames(B);
|
||||
if (aProps.length != bProps.length){
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
for (var i = 0; i < aProps.length; i++) {
|
||||
var propName = aProps[i];
|
||||
if (A[propName] !== B[propName]) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
result = A == B;
|
||||
}
|
||||
if (this.properties.OP == "!=") result = !result;
|
||||
break;
|
||||
/*case ">":
|
||||
result = A > B;
|
||||
break;
|
||||
case "<":
|
||||
result = A < B;
|
||||
break;
|
||||
case "<=":
|
||||
result = A <= B;
|
||||
break;
|
||||
case ">=":
|
||||
result = A >= B;
|
||||
break;
|
||||
case "||":
|
||||
result = A || B;
|
||||
break;
|
||||
case "&&":
|
||||
result = A && B;
|
||||
break;*/
|
||||
}
|
||||
}
|
||||
this.setOutputData(0, result);
|
||||
this.setOutputData(1, !result);
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("basic/CompareValues", GenericCompare);
|
||||
|
||||
})(this);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
LogEvent.title = "Log Event";
|
||||
LogEvent.desc = "Log event in console";
|
||||
|
||||
LogEvent.prototype.onAction = function(action, param) {
|
||||
LogEvent.prototype.onAction = function(action, param, options) {
|
||||
console.log(action, param);
|
||||
};
|
||||
|
||||
@@ -31,18 +31,18 @@
|
||||
TriggerEvent.title = "TriggerEvent";
|
||||
TriggerEvent.desc = "Triggers event if input evaluates to true";
|
||||
|
||||
TriggerEvent.prototype.onExecute = function(action, param) {
|
||||
TriggerEvent.prototype.onExecute = function( param, options) {
|
||||
var v = this.getInputData(0);
|
||||
var changed = (v != this.prev);
|
||||
if(this.prev === 0)
|
||||
changed = false;
|
||||
var must_resend = (changed && this.properties.only_on_change) || (!changed && !this.properties.only_on_change);
|
||||
if(v && must_resend )
|
||||
this.triggerSlot(0, param);
|
||||
this.triggerSlot(0, param, null, options);
|
||||
if(!v && must_resend)
|
||||
this.triggerSlot(2, param);
|
||||
this.triggerSlot(2, param, null, options);
|
||||
if(changed)
|
||||
this.triggerSlot(1, param);
|
||||
this.triggerSlot(1, param, null, options);
|
||||
this.prev = v;
|
||||
};
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
|
||||
//Sequencer for events
|
||||
function Sequencer() {
|
||||
var that = this;
|
||||
this.addInput("", LiteGraph.ACTION);
|
||||
this.addInput("", LiteGraph.ACTION);
|
||||
this.addInput("", LiteGraph.ACTION);
|
||||
@@ -72,10 +71,13 @@
|
||||
return "";
|
||||
};
|
||||
|
||||
Sequencer.prototype.onAction = function(action, param) {
|
||||
Sequencer.prototype.onAction = function(action, param, options) {
|
||||
if (this.outputs) {
|
||||
options = options || {};
|
||||
for (var i = 0; i < this.outputs.length; ++i) {
|
||||
this.triggerSlot(i, param);
|
||||
// CREATE A NEW ID FOR THE ACTION
|
||||
options.action_call = options.action_call?options.action_call+"_seq_"+i:this.id+"_"+(action?action:"action")+"_seq_"+i+"_"+Math.floor(Math.random()*9999);
|
||||
this.triggerSlot(i, param, null, options);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -97,7 +99,7 @@
|
||||
FilterEvent.title = "Filter Event";
|
||||
FilterEvent.desc = "Blocks events that do not match the filter";
|
||||
|
||||
FilterEvent.prototype.onAction = function(action, param) {
|
||||
FilterEvent.prototype.onAction = function(action, param, options) {
|
||||
if (param == null) {
|
||||
return;
|
||||
}
|
||||
@@ -120,7 +122,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
this.triggerSlot(0, param);
|
||||
this.triggerSlot(0, param, null, options);
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("events/filter", FilterEvent);
|
||||
@@ -142,8 +144,9 @@
|
||||
this._value = this.getInputData(1);
|
||||
}
|
||||
|
||||
EventBranch.prototype.onAction = function(action, param) {
|
||||
this.triggerSlot(this._value ? 0 : 1);
|
||||
EventBranch.prototype.onAction = function(action, param, options) {
|
||||
this._value = this.getInputData(1);
|
||||
this.triggerSlot(this._value ? 0 : 1, param, null, options);
|
||||
}
|
||||
|
||||
LiteGraph.registerNodeType("events/branch", EventBranch);
|
||||
@@ -155,6 +158,8 @@
|
||||
this.addInput("reset", LiteGraph.ACTION);
|
||||
this.addOutput("change", LiteGraph.EVENT);
|
||||
this.addOutput("num", "number");
|
||||
this.addProperty("doCountExecution", false, "boolean", {name: "Count Executions"});
|
||||
this.addWidget("toggle","Count Exec.",this.properties.doCountExecution,"doCountExecution");
|
||||
this.num = 0;
|
||||
}
|
||||
|
||||
@@ -168,7 +173,7 @@
|
||||
return this.title;
|
||||
};
|
||||
|
||||
EventCounter.prototype.onAction = function(action, param) {
|
||||
EventCounter.prototype.onAction = function(action, param, options) {
|
||||
var v = this.num;
|
||||
if (action == "inc") {
|
||||
this.num += 1;
|
||||
@@ -193,6 +198,9 @@
|
||||
};
|
||||
|
||||
EventCounter.prototype.onExecute = function() {
|
||||
if(this.properties.doCountExecution){
|
||||
this.num += 1;
|
||||
}
|
||||
this.setOutputData(1, this.num);
|
||||
};
|
||||
|
||||
@@ -211,16 +219,16 @@
|
||||
DelayEvent.title = "Delay";
|
||||
DelayEvent.desc = "Delays one event";
|
||||
|
||||
DelayEvent.prototype.onAction = function(action, param) {
|
||||
DelayEvent.prototype.onAction = function(action, param, options) {
|
||||
var time = this.properties.time_in_ms;
|
||||
if (time <= 0) {
|
||||
this.trigger(null, param);
|
||||
this.trigger(null, param, options);
|
||||
} else {
|
||||
this._pending.push([time, param]);
|
||||
}
|
||||
};
|
||||
|
||||
DelayEvent.prototype.onExecute = function() {
|
||||
DelayEvent.prototype.onExecute = function(param, options) {
|
||||
var dt = this.graph.elapsed_time * 1000; //in ms
|
||||
|
||||
if (this.isInputConnected(1)) {
|
||||
@@ -228,9 +236,9 @@
|
||||
}
|
||||
|
||||
for (var i = 0; i < this._pending.length; ++i) {
|
||||
var action = this._pending[i];
|
||||
action[0] -= dt;
|
||||
if (action[0] > 0) {
|
||||
var actionPass = this._pending[i];
|
||||
actionPass[0] -= dt;
|
||||
if (actionPass[0] > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -239,7 +247,7 @@
|
||||
--i;
|
||||
|
||||
//trigger
|
||||
this.trigger(null, action[1]);
|
||||
this.trigger(null, actionPass[1], options);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -359,9 +367,9 @@
|
||||
|
||||
|
||||
function DataStore() {
|
||||
this.addInput("data", "");
|
||||
this.addInput("data", 0);
|
||||
this.addInput("assign", LiteGraph.ACTION);
|
||||
this.addOutput("data", "");
|
||||
this.addOutput("data", 0);
|
||||
this._last_value = null;
|
||||
this.properties = { data: null, serialize: true };
|
||||
var that = this;
|
||||
@@ -379,7 +387,7 @@
|
||||
this.setOutputData(0, this.properties.data );
|
||||
}
|
||||
|
||||
DataStore.prototype.onAction = function(action, param) {
|
||||
DataStore.prototype.onAction = function(action, param, options) {
|
||||
this.properties.data = this._last_value;
|
||||
};
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@
|
||||
local_pos[1] < this.size[1] - 2
|
||||
) {
|
||||
this.clicked = true;
|
||||
this.setOutputData(1, this.clicked);
|
||||
this.triggerSlot(0, this.properties.message);
|
||||
return true;
|
||||
}
|
||||
@@ -672,7 +673,7 @@
|
||||
typeof v == "number" ? v.toFixed(this.properties["decimals"]) : v;
|
||||
|
||||
if (typeof this.str == "string") {
|
||||
var lines = this.str.split("\\n");
|
||||
var lines = this.str.replace(/[\r\n]/g, "\\n").split("\\n");
|
||||
for (var i=0; i < lines.length; i++) {
|
||||
ctx.fillText(
|
||||
lines[i],
|
||||
|
||||
@@ -82,4 +82,120 @@
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("logic/sequence", Sequence);
|
||||
|
||||
|
||||
function logicAnd(){
|
||||
this.properties = { };
|
||||
this.addInput("a", "boolean");
|
||||
this.addInput("b", "boolean");
|
||||
this.addOutput("out", "boolean");
|
||||
}
|
||||
logicAnd.title = "AND";
|
||||
logicAnd.desc = "Return true if all inputs are true";
|
||||
logicAnd.prototype.onExecute = function() {
|
||||
ret = true;
|
||||
for (inX in this.inputs){
|
||||
if (!this.getInputData(inX)){
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.setOutputData(0, ret);
|
||||
};
|
||||
logicAnd.prototype.onGetInputs = function() {
|
||||
return [
|
||||
["and", "boolean"]
|
||||
];
|
||||
};
|
||||
LiteGraph.registerNodeType("logic/AND", logicAnd);
|
||||
|
||||
|
||||
function logicOr(){
|
||||
this.properties = { };
|
||||
this.addInput("a", "boolean");
|
||||
this.addInput("b", "boolean");
|
||||
this.addOutput("out", "boolean");
|
||||
}
|
||||
logicOr.title = "OR";
|
||||
logicOr.desc = "Return true if at least one input is true";
|
||||
logicOr.prototype.onExecute = function() {
|
||||
ret = false;
|
||||
for (inX in this.inputs){
|
||||
if (this.getInputData(inX)){
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.setOutputData(0, ret);
|
||||
};
|
||||
logicOr.prototype.onGetInputs = function() {
|
||||
return [
|
||||
["or", "boolean"]
|
||||
];
|
||||
};
|
||||
LiteGraph.registerNodeType("logic/OR", logicOr);
|
||||
|
||||
|
||||
function logicNot(){
|
||||
this.properties = { };
|
||||
this.addInput("in", "boolean");
|
||||
this.addOutput("out", "boolean");
|
||||
}
|
||||
logicNot.title = "NOT";
|
||||
logicNot.desc = "Return the logical negation";
|
||||
logicNot.prototype.onExecute = function() {
|
||||
var ret = !this.getInputData(0);
|
||||
this.setOutputData(0, ret);
|
||||
};
|
||||
LiteGraph.registerNodeType("logic/NOT", logicNot);
|
||||
|
||||
|
||||
function logicCompare(){
|
||||
this.properties = { };
|
||||
this.addInput("a", "boolean");
|
||||
this.addInput("b", "boolean");
|
||||
this.addOutput("out", "boolean");
|
||||
}
|
||||
logicCompare.title = "bool == bool";
|
||||
logicCompare.desc = "Compare for logical equality";
|
||||
logicCompare.prototype.onExecute = function() {
|
||||
last = null;
|
||||
ret = true;
|
||||
for (inX in this.inputs){
|
||||
if (last === null) last = this.getInputData(inX);
|
||||
else
|
||||
if (last != this.getInputData(inX)){
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.setOutputData(0, ret);
|
||||
};
|
||||
logicCompare.prototype.onGetInputs = function() {
|
||||
return [
|
||||
["bool", "boolean"]
|
||||
];
|
||||
};
|
||||
LiteGraph.registerNodeType("logic/CompareBool", logicCompare);
|
||||
|
||||
|
||||
function logicBranch(){
|
||||
this.properties = { };
|
||||
this.addInput("onTrigger", LiteGraph.ACTION);
|
||||
this.addInput("condition", "boolean");
|
||||
this.addOutput("true", LiteGraph.EVENT);
|
||||
this.addOutput("false", LiteGraph.EVENT);
|
||||
this.mode = LiteGraph.ON_TRIGGER;
|
||||
}
|
||||
logicBranch.title = "Branch";
|
||||
logicBranch.desc = "Branch execution on condition";
|
||||
logicBranch.prototype.onExecute = function(param, options) {
|
||||
var condtition = this.getInputData(1);
|
||||
if (condtition){
|
||||
this.triggerSlot(0);
|
||||
}else{
|
||||
this.triggerSlot(1);
|
||||
}
|
||||
};
|
||||
LiteGraph.registerNodeType("logic/IF", logicBranch);
|
||||
})(this);
|
||||
|
||||
2658
src/nodes/math.js
2658
src/nodes/math.js
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
// extra generic nodes
|
||||
@@ -17,7 +17,7 @@
|
||||
return String(a);
|
||||
}
|
||||
|
||||
LiteGraph.wrapFunctionAsNode("string/toString", toString, [""], "String");
|
||||
LiteGraph.wrapFunctionAsNode("string/toString", toString, [""], "string");
|
||||
|
||||
function compare(a, b) {
|
||||
return a == b;
|
||||
@@ -85,8 +85,10 @@
|
||||
else if( str.constructor === Array )
|
||||
{
|
||||
var r = [];
|
||||
for(var i = 0; i < str.length; ++i)
|
||||
r[i] = str[i].split(separator || " ");
|
||||
for(var i = 0; i < str.length; ++i){
|
||||
if (typeof str[i] == "string")
|
||||
r[i] = str[i].split(separator || " ");
|
||||
}
|
||||
return r;
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user