1 |
- 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 Module from'../Module';import Modules from'../';import Logger from'../../systems/Logger';import Systems from'../../systems/Systems';import CoreSystem from'../../systems/CoreSystem';class SubSystem extends Module{constructor(a){super(a),this.view='',this.import.onUpdate(a=>{this.load(a),this.forceUpdate()}),this.load(this.import.value),this.loadIO()}load(a){this.success=!1;try{this.data=JSON.parse(a);let b=new CoreSystem(this.getId());Systems.addSystem(b),b.import(this.data),this.success=!0}catch(a){Logger.warning('Cannot Parse import field! No json!',a)}}loadIO(){let a=Systems.getSystem(this.getId());for(let b in a.inputs){this.generateOutput(this.LinkManager.addOutputRef(this[b]||(this.props.outputs[b]?_extends({},this.props.outputs[b],{pid:this.getId()}):null)||a.inputs[b]),b);let c=a.getInput(b);c.onUpdate(()=>this[b].set(c.value))}for(let b in a.outputs){this.generateInput(this.LinkManager.addInputRef(this[b]||(this.props.inputs[b]?_extends({},this.props.inputs[b],{pid:this.getId()}):null)||a.outputs[b]),b);let c=a.getOutput(b);this[b].value&&c.set(this[b].value),this[b].onUpdate(()=>c.set(this[b].value))}}render(){return this.success?React.createElement('div',{className:'SubSystem'},Systems.getSystem(this.getId()).renderModules(),super.render()):React.createElement('div',null,'SubSystem',super.render())}}SubSystem.EditPosition='top-right',SubSystem.Inputs={import:{type:Module.Types.Text,defaultValue:'{}'}},SubSystem.Category='Subsystem';export default SubSystem;
|