From ac14de7e59eae6fede96120bd50fd2d2d23c54ce Mon Sep 17 00:00:00 2001 From: tamat Date: Fri, 31 May 2019 12:21:22 +0200 Subject: [PATCH] added limit for runStep, fixed some nodes --- src/litegraph.js | 10 +++++++--- src/nodes/base.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/litegraph.js b/src/litegraph.js index 5d3d293f1..80863467b 100755 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -719,9 +719,11 @@ * Run N steps (cycles) of the graph * @method runStep * @param {number} num number of steps to run, default is 1 + * @param {Boolean} do_not_catch_errors [optional] if you want to try/catch errors + * @param {number} limit max number of nodes to execute (used to execute from start to a node) */ - LGraph.prototype.runStep = function(num, do_not_catch_errors) { + LGraph.prototype.runStep = function(num, do_not_catch_errors, limit ) { num = num || 1; var start = LiteGraph.getTime(); @@ -734,10 +736,12 @@ return; } + limit = limit || nodes.length; + if (do_not_catch_errors) { //iterations for (var i = 0; i < num; i++) { - for (var j = 0, l = nodes.length; j < l; ++j) { + for (var j = 0; j < limit; ++j) { var node = nodes[j]; if (node.mode == LiteGraph.ALWAYS && node.onExecute) { node.onExecute(); @@ -757,7 +761,7 @@ try { //iterations for (var i = 0; i < num; i++) { - for (var j = 0, l = nodes.length; j < l; ++j) { + for (var j = 0; j < limit; ++j) { var node = nodes[j]; if (node.mode == LiteGraph.ALWAYS && node.onExecute) { node.onExecute(); diff --git a/src/nodes/base.js b/src/nodes/base.js index a39eedb67..ae9b044e1 100755 --- a/src/nodes/base.js +++ b/src/nodes/base.js @@ -607,6 +607,53 @@ LiteGraph.registerNodeType("basic/object_property", ObjectProperty); + function ObjectKeys() { + this.addInput("obj", ""); + this.addOutput("keys", "array"); + this.size = [140, 30]; + } + + ObjectKeys.title = "Object keys"; + ObjectKeys.desc = "Outputs an array with the keys of an object"; + + ObjectKeys.prototype.onExecute = function() { + var data = this.getInputData(0); + if (data != null) { + this.setOutputData(0, Object.keys(data) ); + } + }; + + LiteGraph.registerNodeType("basic/object_keys", ObjectKeys); + + function MergeObjects() { + this.addInput("A", "object"); + this.addInput("B", "object"); + this.addOutput("", "object"); + this._result = {}; + var that = this; + this.addWidget("button","clear",function(){ + that._result = {}; + }); + } + + MergeObjects.title = "Merge Objects"; + MergeObjects.desc = "Creates an object copying properties from others"; + + MergeObjects.prototype.onExecute = function() { + var A = this.getInputData(0); + var B = this.getInputData(1); + var C = this._result; + if(A) + for(var i in A) + C[i] = A[i]; + if(B) + for(var i in B) + C[i] = B[i]; + this.setOutputData(0,C); + }; + + LiteGraph.registerNodeType("basic/merge_objects", MergeObjects ); + //Watch a value in the editor function Watch() { this.size = [60, 20];