12345678910111213 |
- var _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a};import React from'react';import Logger from'./Logger';import Types from'../modules/Types';import'./ModuleLoader.css';import{Resolver}from'../modules/ModuleUtilities';class LinkManager{constructor(){this.__disableCore=!1,this.clean()}disableCore(){this.__disableCore=!0}clean(){this.links={},this.reverseLinks={},this.inputs={},this.outputs={}}_resolve(a,b){//console.log("Resolve", output, value);
- let c=a.pid;if(!('core'===c&&this.__disableCore)){// find all links
- let e=this.links[c][a.name];// find all inputs
- for(var d=0;d<e.length;d++){let{pid:c,name:f}=e[d];// resolve
- this.inputs[c][f]&&this.inputs[c][f].update(b,''+a.id+a.name)}}}addOutputRef(a){return a=this.ghostOutputRef(a,!1),this.outputs[a.pid]=_extends({},this.outputs[a.pid],{[a.name]:a}),this.links[a.pid]=_extends({[a.name]:[]},this.links[a.pid]),a}addInputRef(a){return a=this.ghostInputRef(a),this.inputs[a.pid]=_extends({},this.inputs[a.pid],{[a.name]:a}),this.reverseLinks[a.pid]=_extends({[a.name]:[]},this.reverseLinks[a.pid]),a}ghostInputRef(a){this;return _extends({},a,{value:Resolver(a),onUpdate:function(a){this._onUpdate=a},update:function(b){void 0===b||(this.value=Resolver(a,b),this._onUpdate&&this._onUpdate(this.value))}})}ghostOutputRef(a,b=!0,c={}){let d=this;return _extends({},a,{set:function(e){this.value=e,c[a.name]&&c[a.name](this.value),b||d._resolve(this,this.value)}})}createLink(a,b){// check if they exists
- this.inputs[a.pid]&&this.outputs[b.pid]&&(('core'!==b.pid||!this.__disableCore)&&this.inputs[a.pid][a.name]&&this.outputs[b.pid][b.name]&&(this.inputs[a.pid][a.name].value=this.outputs[b.pid][b.name].value),!this.links[b.pid][b.name]&&(this.links[b.pid][b.name]=[]),this.links[b.pid][b.name].push({pid:a.pid,name:a.name}),!this.reverseLinks[a.pid][a.name]&&(this.reverseLinks[a.pid][a.name]=[]),this.reverseLinks[a.pid][a.name].push({pid:b.pid,name:b.name}))}addLink(a){this.createLink(a.input,a.output)}clearLinks(a){for(var b in this.links)a[b]||'core'==b||this.breakLinks(b);for(var b in this.reverseLinks)a[b]||'core'==b||this.breakLinks(b)}breakInputLinks(a){if(a.pid){let d=a.pid,e=this.reverseLinks[d],f=e[a.name];for(var b=0;b<f.length;b++){let{pid:e,name:g}=f[b];// resolve
- for(var c=0;c<this.links[e][g].length;c++)this.links[e][g][c].pid==d&&this.links[e][g][c].name==a.name&&(this.links[e][g].splice(c,1),--c)}this.reverseLinks[d][a.name]=[]}}breakOutputLinks(a){if(a.pid){let d=a.pid,e=this.links[d],f=e[a.name];for(var b=0;b<f.length;b++){let{pid:e,name:g}=f[b];// resolve
- for(var c=0;c<this.reverseLinks[e][g].length;c++)this.reverseLinks[e][g][c].pid==d&&this.reverseLinks[e][g][c].name==a.name&&(this.reverseLinks[e][g].splice(c,1),--c)}this.links[d][a.name]=[]}}breakLinks(a){for(var b in this.reverseLinks[a]){let e=this.reverseLinks[a][b];for(var c=0;c<e.length;c++){let{pid:b,name:f}=e[c];// resolve
- for(var d=0;d<this.links[b][f].length;d++)this.links[b][f][d].pid==a&&(this.links[b][f].splice(d,1),--d)}}delete this.reverseLinks[a],delete this.links[a],delete this.inputs[a],delete this.outputs[a]}rename(a,b){for(var c in this.reverseLinks[a]){let f=this.reverseLinks[a][c];for(var d=0;d<f.length;d++){let{pid:c,name:g}=f[d];// resolve
- for(var e=0;e<this.links[c][g].length;e++)this.links[c][g][e].pid==a&&(this.links[c][g][e].pid=b)}}// NEED TO BE HERE
- for(var c in this.reverseLinks[b]=this.reverseLinks[a],this.links[a]){let f=this.links[a][c];for(var d=0;d<f.length;d++){let{pid:c,name:g}=f[d];// resolve
- for(var e=0;e<this.reverseLinks[c][g].length;e++)this.reverseLinks[c][g][e].pid==a&&(this.reverseLinks[c][g][e].pid=b)}}this.links[b]=this.links[a],this.inputs[b]=this.inputs[a],this.outputs[b]=this.outputs[a],delete this.inputs[a],delete this.outputs[a],delete this.reverseLinks[a],delete this.links[a]}connect(a,b){this.createLink(a,b)}getOutputConnections(a){return this.links[a.pid][a.name]}getInputConnections(a){return this.reverseLinks[a.pid][a.name]}isReady(a){for(var b=0;b<a.inputs.length;b++)if(!this.inputs[a.id][a.inputs[b].name])return!1;for(var b=0;b<a.outputs.length;b++)if(!this.outputs[a.id][a.outputs[b].name])return!1;// maybe check more here!
- return!0}selectOutput(a){this.__selectedOutput=a}connectSelected(a){this.__selectedOutput&&this.createLink(a,this.__selectedOutput)}export(){let a=[];for(var b in this.links)for(var c in this.links[b])if(this.links[b][c].length)for(var d in this.links[b][c]){let e={output:{name:c,pid:b},input:this.links[b][c][d]};a.push(e)}return a}}export default LinkManager;
|