//import CoreSystem from 'core-system'; import ToolBox from './ToolBox'; import Keyboard from './keyboard'; import Mouse from './mouse'; import React from 'react'; import {Dimensions, StyleSheet, View, Text , Button, TouchableOpacity } from 'react-native'; import { Icon } from 'react-native-elements' import Library from 'trapilib/dist/lib'; import SideBar from './SideBar'; import MainBar from './MainBar'; import ModuleBar from './ModuleBar'; import { ViewNode, Node } from 'trapilib/dist/lib/systems/ViewSystem'; import Environment from './Environment'; import BaseSystem from './System'; let { CoreSystem, ViewSystem, } = Library; export default class Gui extends BaseSystem { constructor() { super(); this.phoneRef = React.createRef(); this.phone = this.phoneRef; this.toolboxRef = React.createRef(); this.toolbox = this.toolboxRef; this.disabledTools = true; this.CoreSystem = new CoreSystem(true); this.CoreSystem.onUpdate(() => { this.forceUpdate(); }) this.Keyboard = new Keyboard().listen(); this.Keyboard.on('s', () => { this.ToolBox.selectTool('Select'); this.forceUpdate(); }); this.ToolBox = new ToolBox(this.CoreSystem); this.MainBar = new MainBar(this.CoreSystem); this.ModuleBar = new ModuleBar(this.CoreSystem); // Add CoreSystem deps this.SideBar = new SideBar(this.CoreSystem, this.ToolBox); this.Environment = new Environment(this.CoreSystem, this.ToolBox, this.phoneRef); this.Environment.onUpdate(() => this.forceUpdate()) this.SideBar.onUpdate(() => this.forceUpdate()) this.ToolBox.onUpdate( () => { this.disabledTools = !this.ToolBox.activeTool; this.CoreSystem.ActionSystem.toggle(!this.disabledTools); this.SideBar.tool = this.ToolBox.activeTool; this.forceUpdate(); }); this.ModuleBar.onUpdate(() => this.forceUpdate()) this.MainBar.onUpdate(() => this.forceUpdate()) this.MainBar.onSave( () => { this.saveEnv(); this.forceUpdate() }) this.load(); // Setup mainContainer let cview = this.CoreSystem.getCurrentView(); let container = cview.getDefaultContainer(); let mainContent = new ViewNode(Math.random(), 'BaseContainer', {width: 375, height: 667}); cview.setContent(mainContent, container); } onMount() { this.forceUpdate(); if(this.phone){ // thats fine this.ToolBoxMouse = new Mouse(this.toolbox.current); this.phoneMouse = new Mouse(this.phone.current).droppable(); } if(this.ToolBoxMouse !== undefined){ this.ToolBoxMouse.listen() .on('LeftDown',(e) => this.ToolManagement(e)) this.phoneMouse.listen() .on('LeftDown',(e) => this.ToolManagement(e)) .on('Drop', (e) => this.dropContent(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){ if(this.ToolBox.activeTool !== null && !this.disabledTools){ this.processElement(e) } } load() { try{ let env = localStorage.getItem('environment'); if( env === null){ // this.CoreSystem.import(JSON.parse(jsLoad)); this.CoreSystem.fresh(); }else{ this.CoreSystem.import(JSON.parse(env)); } this.forceUpdate(); } catch(e) { console.log(e); } } processElement(event){ let Node = this.CoreSystem.ray({event}); let NewNode = this.ToolBox.editNode(Node); this.forceUpdate(); } dropContent({event, data}) { data = JSON.parse(data); let targetNode = this.CoreSystem.ray({event}); // targetNode.content targetNode.props.selected = true; let node = new ViewNode(Math.random(), data.ctor, {}, data.namespace); let containerNode = new Node(Math.random(), {}, node); let View = this.CoreSystem.getCurrentView(); View.addViewNode(containerNode, targetNode); this.forceUpdate(); } mobileRender(){ return this.Environment.render(); } renderSideBar(){ return this.SideBar.render(); } renderMainBar(){ return this.MainBar.render(); } renderToolBox(){ return (