diff --git a/build/litegraph.core.js b/build/litegraph.core.js index 1aa50702b..bc137a94f 100644 --- a/build/litegraph.core.js +++ b/build/litegraph.core.js @@ -1073,6 +1073,7 @@ for (var i = 0; i < num; i++) { for (var j = 0; j < limit; ++j) { var node = nodes[j]; + node.executePendingActions(); if (node.mode == LiteGraph.ALWAYS && node.onExecute) { //wrap node.onExecute(); node.doExecute(); @@ -1094,6 +1095,7 @@ for (var i = 0; i < num; i++) { for (var j = 0; j < limit; ++j) { var node = nodes[j]; + node.executePendingActions(); if (node.mode == LiteGraph.ALWAYS && node.onExecute) { node.onExecute(); } @@ -3190,10 +3192,26 @@ this.mode = modeTo; return true; }; + + /** + * Triggers the execution of actions that were deferred when the action was triggered + * @method executePendingActions + */ + LGraphNode.prototype.executePendingActions = function() { + if(!this._waiting_actions || !this._waiting_actions.length) + return; + for(var i = 0; i < this._waiting_actions.length;++i) + { + var p = this._waiting_actions[i]; + this.onAction(p[0],p[1],p[2],p[3],p[4]); + } + this._waiting_actions.length = 0; + } + /** * Triggers the node code execution, place a boolean/counter to mark the node as being executed - * @method execute + * @method doExecute * @param {*} param * @param {*} options */ @@ -3204,13 +3222,6 @@ // enable this to give the event an ID if (!options.action_call) options.action_call = this.id+"_exec_"+Math.floor(Math.random()*9999); - if(this._waiting_actions && this._waiting_actions.length) - for(var i = 0; i < this._waiting_actions.length;++i) - { - var p = this._waiting_actions[i]; - this.onAction(p[0],p[1],p[2],p[3],p[4]); - } - this.graph.nodes_executing[this.id] = true; //.push(this.id); this.onExecute(param, options); @@ -3225,12 +3236,6 @@ } } else { - if(this._waiting_actions && this._waiting_actions.length) - for(var i = 0; i < this._waiting_actions.length;++i) - { - var p = this._waiting_actions[i]; - this.onAction(p[0],p[1],p[2],p[3],p[4]); - } } this.execute_triggered = 2; // the nFrames it will be used (-- each step), means "how old" is the event if(this.onAfterExecuteNode) this.onAfterExecuteNode(param, options); // callback diff --git a/build/litegraph.core.min.js b/build/litegraph.core.min.js index 85dd5b452..d0ffcf087 100644 --- a/build/litegraph.core.min.js +++ b/build/litegraph.core.min.js @@ -32,18 +32,18 @@ w.supported_types};w.STATUS_STOPPED=1;w.STATUS_RUNNING=2;w.prototype.clear=funct 0;this.elapsed_time=this.fixedtime_lapse=.01;this.starttime=this.last_update_time=0;this.catch_errors=!0;this.nodes_executing=[];this.nodes_actioning=[];this.nodes_executedAction=[];this.inputs={};this.outputs={};this.change();this.sendActionToCanvas("clear")};w.prototype.attachCanvas=function(a){if(a.constructor!=q)throw"attachCanvas expects a LGraphCanvas instance";a.graph&&a.graph!=this&&a.graph.detachCanvas(a);a.graph=this;this.list_of_graphcanvas||(this.list_of_graphcanvas=[]);this.list_of_graphcanvas.push(a)}; w.prototype.detachCanvas=function(a){if(this.list_of_graphcanvas){var b=this.list_of_graphcanvas.indexOf(a);-1!=b&&(a.graph=null,this.list_of_graphcanvas.splice(b,1))}};w.prototype.start=function(a){if(this.status!=w.STATUS_RUNNING){this.status=w.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=h.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){function c(){if(-1==b.execution_timer_id){window.requestAnimationFrame(c); if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()}}this.execution_timer_id=-1;c()}else this.execution_timer_id=setInterval(function(){if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()},a)}};w.prototype.stop=function(){if(this.status!=w.STATUS_STOPPED){this.status=w.STATUS_STOPPED;if(this.onStopEvent)this.onStopEvent();null!=this.execution_timer_id&&(-1!=this.execution_timer_id&&clearInterval(this.execution_timer_id), -this.execution_timer_id=null);this.sendEventToAllNodes("onStop")}};w.prototype.runStep=function(a,b,c){a=a||1;var d=h.getTime();this.globaltime=.001*(d-this.starttime);var e=this._nodes_executable?this._nodes_executable:this._nodes;if(e){c=c||e.length;if(b){for(var f=0;fg&&(g=l.size[n]);k+=l.size[b==h.VERTICAL_LAYOUT?0:1]+a+h.NODE_TITLE_HEIGHT}c+=g+a}this.setDirtyCanvas(!0,!0)};w.prototype.getTime=function(){return this.globaltime};w.prototype.getFixedTime=function(){return this.fixedtime};w.prototype.getElapsedTime=function(){return this.elapsed_time};w.prototype.sendEventToAllNodes=function(a,b,c){c=c||h.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,f=d.length;e< -f;++e){var g=d[e];if(g.constructor===h.Subgraph&&"onExecute"!=a)g.mode==c&&g.sendEventToAllNodes(a,b,c);else if(g[a]&&g.mode==c)if(void 0===b)g[a]();else if(b&&b.constructor===Array)g[a].apply(g,b);else g[a](b)}};w.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var c=0;c=h.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";if(h.use_uuids){if(null==a.id||-1==a.id)a.id=h.uuidv4()}else null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_idg&&(g=l.size[n]);k+=l.size[b==h.VERTICAL_LAYOUT?0:1]+a+h.NODE_TITLE_HEIGHT}c+=g+a}this.setDirtyCanvas(!0,!0)};w.prototype.getTime=function(){return this.globaltime};w.prototype.getFixedTime=function(){return this.fixedtime};w.prototype.getElapsedTime=function(){return this.elapsed_time};w.prototype.sendEventToAllNodes=function(a,b,c){c=c||h.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order: +this._nodes;if(d)for(var e=0,f=d.length;e=h.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";if(h.use_uuids){if(null==a.id||-1==a.id)a.id=h.uuidv4()}else null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id=this.outputs.length?null:this.outputs[a]._data};v.prototype.getOutputInfo=function(a){return this.outputs?a=this.outputs.length)return null;a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],c=0;ca&&this.pos[1]-e-cb)return!0;return!1};v.prototype.getSlotInPosition=function(a,b){var c=new Float32Array(2);if(this.inputs)for(var d=0,e=this.inputs.length;d=this.outputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor=== -Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return h.debug&&console.log("Connect: Error, no slot of name "+c),null}else if(c===h.EVENT)if(h.do_add_triggers_slots)b.changeMode(h.ON_TRIGGER),c=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||c>=b.inputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),null;var d=b.inputs[c],e=this.outputs[a];if(!this.outputs[a])return null; -b.onBeforeConnectInput&&(c=b.onBeforeConnectInput(c));if(!1===c||null===c||!h.isValidConnection(e.type,d.type))return this.setDirtyCanvas(!1,!0),null;if(b.onConnectInput&&!1===b.onConnectInput(c,e.type,e,this,a)||this.onConnectOutput&&!1===this.onConnectOutput(a,d.type,d,b,c))return null;b.inputs[c]&&null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c,{doProcessChange:!1}));if(null!==e.links&&e.links.length)switch(e.type){case h.EVENT:h.allow_multi_output_for_events||(this.graph.beforeChange(), -this.disconnectOutput(a,!1,{doProcessChange:!1}))}var f=h.use_uuids?h.uuidv4():++this.graph.last_link_id;f=new Y(f,d.type||e.type,this.id,a,b.id,c);this.graph.links[f.id]=f;null==e.links&&(e.links=[]);e.links.push(f.id);b.inputs[c].link=f.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,a,!0,f,e);if(b.onConnectionsChange)b.onConnectionsChange(h.INPUT,c,!0,f,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(h.INPUT, -b,c,this,a),this.graph.onNodeConnectionChange(h.OUTPUT,this,a,b,c));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,f);return f};v.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return h.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),!1;var c=this.outputs[a];if(!c||!c.links||0==c.links.length)return!1; -if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var d=0,e=c.links.length;da&&this.pos[1]-e-cb)return!0;return!1};v.prototype.getSlotInPosition=function(a,b){var c=new Float32Array(2);if(this.inputs)for(var d=0,e=this.inputs.length;d=this.outputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b)); +if(!b)throw"target node is null";if(b==this)return null;if(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return h.debug&&console.log("Connect: Error, no slot of name "+c),null}else if(c===h.EVENT)if(h.do_add_triggers_slots)b.changeMode(h.ON_TRIGGER),c=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||c>=b.inputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),null;var d=b.inputs[c],e=this.outputs[a];if(!this.outputs[a])return null;b.onBeforeConnectInput&& +(c=b.onBeforeConnectInput(c));if(!1===c||null===c||!h.isValidConnection(e.type,d.type))return this.setDirtyCanvas(!1,!0),null;if(b.onConnectInput&&!1===b.onConnectInput(c,e.type,e,this,a)||this.onConnectOutput&&!1===this.onConnectOutput(a,d.type,d,b,c))return null;b.inputs[c]&&null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c,{doProcessChange:!1}));if(null!==e.links&&e.links.length)switch(e.type){case h.EVENT:h.allow_multi_output_for_events||(this.graph.beforeChange(),this.disconnectOutput(a, +!1,{doProcessChange:!1}))}var f=h.use_uuids?h.uuidv4():++this.graph.last_link_id;f=new Y(f,d.type||e.type,this.id,a,b.id,c);this.graph.links[f.id]=f;null==e.links&&(e.links=[]);e.links.push(f.id);b.inputs[c].link=f.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,a,!0,f,e);if(b.onConnectionsChange)b.onConnectionsChange(h.INPUT,c,!0,f,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(h.INPUT,b,c,this,a),this.graph.onNodeConnectionChange(h.OUTPUT, +this,a,b,c));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,f);return f};v.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return h.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),!1;var c=this.outputs[a];if(!c||!c.links||0==c.links.length)return!1;if(b){b.constructor===Number&&(b= +this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var d=0,e=c.links.length;d=this.inputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var c=this.inputs[a].link;if(null!=c){this.inputs[a].link=null;var d=this.graph.links[c];if(d){var e=this.graph.getNodeById(d.origin_id);if(!e)return!1;var f=e.outputs[d.origin_slot];if(!f||!f.links||0==f.links.length)return!1;for(var g=0,k=f.links.length;g