ServiceSystem.js 3.2 KB

123
  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 ModuleSystem from'./ModuleSystem.js';import{FontAwesomeIcon}from'@fortawesome/react-fontawesome';import Logger from'./Logger';import{Tabs,Tab,Card}from'react-materialize';import Systems from'./Systems';class ServiceSystem extends ModuleSystem{constructor(a){//this.systemID = systemID; // it' s in super!!
  2. super(a),this.availableModules=Systems.getServices()}loadService(a,b=!1){let{ctor:c,id:d,inputs:e,outputs:f,shadow:g}=a;if(void 0===this.availableModules[c])return void Logger.warning('Service '+c+' is not bundled! You either forgot to add it to ServiceSystem or it doesn\'t exist!');let h=[];for(var j in this.availableModules[c].Inputs){let a=this.availableModules[c].Inputs[j].defaultValue;e[j]&&(a=e[j].value||a),e[j]={name:j,value:a,pid:d,type:this.availableModules[c].Inputs[j].type},h[j]=this.LinkManager.addInputRef(e[j])}let k=[];for(var j in this.availableModules[c].Outputs)f[j]={name:j,pid:d,type:this.availableModules[c].Outputs[j].type},k[j]=this.LinkManager.addOutputRef(f[j]);this.__addToScene(_extends({},a,{inrefs:h,outrefs:k,key:''+d+d,children:[]}))}__Factory(a){let b=this.availableModules[a.ctor],c=a;return c.System=this,c.systemID=this.systemID,new b(c)}_shuffleAllKeys(){}__resolveItem(a){if(this.LinkManager.isReady(a)){this.resolved[a.id]=a;let b=this.__Factory(a);a.reactElement=b,delete this.modules[a.id],this.modules[a.id]=b,delete this.noresolve[a.id],this.dirty=!0}}render(){let a=[];for(var b in this.modules)a.push(this.modules[b]);return React.createElement(ServiceUI,{modules:a})}change(a,b,c){this.resolved[a].inputs[b].value=c,this.resolved[a].inrefs[b].value=c,this.noresolve=_extends({},this.resolved),this.modules={}}addChild(){}remove(a){delete this.modules[a],delete this.resolved[a],delete this.metamodules[a],this.LinkManager.breakLinks(a)}export(){return Object.keys(this.resolved).map(a=>{let b=this.resolved[a];return{ctor:b.ctor,id:b.id,inputs:b.inputs,outputs:b.outputs,key:b.key}})}}class ServiceUI extends React.Component{constructor(a){super(a),this.state={vision:!1,activeMod:localStorage.getItem('ServiceDisplay')||-1//this.t = setInterval(() => this.forceUpdate(), 1000);
  3. }}toggle(){this.setState({vision:!this.state.vision})}go(a){localStorage.setItem('ServiceDisplay',a),this.setState({activeMod:a})}render(){let a=Object.keys(this.props.modules).map(a=>React.createElement(this.props.modules[a].constructor,this.props.modules[a].props)),b=Object.keys(this.props.modules).map(a=>(''+this.props.modules[a].getId()).toUpperCase()||this.props.modules[a].constructor.name),c=b.indexOf(this.state.activeMod),d=[React.createElement('div',{className:'ServiceBar',key:'SB'+Math.random()},React.createElement(Tabs,{onChange:(b,a)=>{this.go(a.target.innerText)}},React.createElement(Tab,{active:'X'===this.state.activeMod,title:'X'}),b.map((a,b)=>React.createElement(Tab,{key:b,title:a,active:this.state.activeMod===a}))))];return-1<c&&d.push(React.createElement(Card,{key:'SDisplay',className:'ServiceDisplay blue lighten-3',header:React.createElement('h5',null,b[c])},a[c])),d}}export default ServiceSystem;