//import CoreSystem from 'core-system'; import ToolBox from './ToolBox'; import Keyboard from './keyboard'; import Mouse from './mouse'; import React from 'react'; import {StyleSheet, View, Text} from 'react-native'; import Library from 'trapilib/dist/lib'; import SideBar from './SideBar'; import MainBar from './MainBar'; let { CoreSystem, ViewSystem } = Library; export default class Gui { constructor(phone , toolbox) { this.Keyboard = new Keyboard(); this.phone = phone; this.toolbox = toolbox; if(this.phone){ this.ToolBoxMouse = new Mouse(this.toolbox); this.phoneMouse = new Mouse(this.phone) } this.CoreSystem = { render: () => null}; this.ToolBox = new ToolBox(); this.MainBar = new MainBar(); this.load(); this.__onUpdate = null; this.SideBar = new SideBar(); this.ToolBox.onUpdate( () =>{ let SideBarProps = { tool:this.ToolBox.activeTool } this.SideBar = new SideBar(SideBarProps) this.forceUpdate() }) this.MainBar.onSave( () => { this.saveEnv(); this.forceUpdate() }) if(this.ToolBoxMouse !== undefined){ this.ToolBoxMouse.listen() .on('LeftDown',(e) => this.ToolManagement(e)) this.phoneMouse.listen() .on('LeftDown',(e) => this.ToolManagement(e)) } } saveEnv(){ let env = this.CoreSystem.export(); localStorage.setItem('environment', JSON.stringify(env)); this.forceUpdate(); try{ this.CoreSystem.import(JSON.parse(js)); this.forceUpdate(); } catch(e) { console.log(e); } } ToolManagement(e){ console.log("whattttt") if(this.ToolBox.activeTool === null){ return null; }else{ this.processElement(e) } } onUpdate(fn){ this.__onUpdate = fn } forceUpdate(){ this.__onUpdate && this.__onUpdate(); } load() { this.CoreSystem = new CoreSystem(); this.ToolBox = new ToolBox(this.CoreSystem.ViewSystem); try{ let env = localStorage.getItem('environment'); if( env === null){ this.CoreSystem.import(JSON.parse(jsLoad)); }else{ this.CoreSystem.import(JSON.parse(env)); } this.forceUpdate(); } catch(e) { console.log(e); } } processElement(event){ console.log(event) console.log('sdasdwd') let ViewNode = this.CoreSystem.ray({event}) let NewNode = this.ToolBox.editNode(ViewNode); this.forceUpdate(); } mobileRender(){ return ( {this.CoreSystem.render()} ) } renderSideBar(){ return this.SideBar.render(); } renderMainBar(){ return this.MainBar.render(); } renderToolBox(){ return ( {this.ToolBox.render()} ) } } //const jsLoad = '{"Routing":{"topology":{"nodes":{"test":{"id":"test","routeName":"test","uri":"test","view":"VS1","defaultLink":null},"sample":{"id":"sample","routeName":"sample","uri":"sample","view":"VS2","defaultLink":null}},"links":{"test":{"out":[],"in":[]},"sample":{"out":[],"in":[]}}},"home":"test"},"Views":{"views":{"VS1":{"tree":{"nodes":{"A":{"id":"A","depth":0,"value":"RootComp","namespace":"default","props":{}},"B":{"id":"B","depth":1,"value":"ViewComp","namespace":"default","props":{"text":"ASD LOOK AT ME LOOK OO O.O (O.O)"}},"C":{"id":"C","depth":1,"value":"ViewComp","namespace":"default","props":{}}},"links":{"A":{"out":[{"to":"B","from":"A"},{"to":"C","from":"A"}],"in":[]},"B":{"out":[],"in":[{"to":"B","from":"A"}]},"C":{"out":[],"in":[{"to":"C","from":"A"}]}},"levels":[["A"],["B","C"]],"rootId":"A"}},"VS2":{"tree":{"nodes":{"P":{"id":"P","depth":0,"value":"RootComp","namespace":"default","props":{}}},"links":{"P":{"out":[],"in":[]}},"levels":[["P"]],"rootId":"P"}}}}}'; //jsLoad Test const jsLoad = '{"Routing":{"topology":{"nodes":{"test":{"id":"test","routeName":"test","uri":"test","view":"VS1","defaultLink":null}},"links":{"test":{"out":[],"in":[]}}},"home":"test"},"Views":{"views":{"VS1":{"tree":{"nodes":{"A":{"id":"A","depth":0,"value":"RootComp","namespace":"default","props":{"text":"This is the Starting point!!!Try add on me ","style":{"container":22,"text":23}}}},"links":{"A":{"out":[],"in":[]}},"levels":[["A"]],"rootId":"A"}}}}}' const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'space-between', flexDirection: 'row' }, toolbarView: { justifyContent: 'space-around', alignItems: 'center', padding: 16 }, mainView: { backgroundColor: '#065b69', alignSelf:'stretch', flex: 1, justifyContent: 'center', alignItems: 'center' }, mobileView: { backgroundColor: 'white', borderWidth: 4, borderColor: 'orange', // iphone X width:1125/3, height: 2436/3 }, attributesView: { width:256, alignSelf: 'stretch', flexDirection: 'column', backgroundColor:'blue' } });