Gui.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //import CoreSystem from 'core-system';
  2. import ToolBox from './ToolBox';
  3. import Keyboard from './keyboard';
  4. import Mouse from './mouse';
  5. import React from 'react';
  6. import {StyleSheet, View, Text} from 'react-native';
  7. import Library from 'trapilib/dist/lib';
  8. import SideBar from './SideBar';
  9. import MainBar from './MainBar';
  10. import ModuleBar from './ModuleBar';
  11. let {
  12. CoreSystem,
  13. ViewSystem
  14. } = Library;
  15. export default class Gui {
  16. constructor() {
  17. this.ModuleBar = new ModuleBar();
  18. this.Keyboard = new Keyboard();
  19. this.phoneRef = React.createRef();
  20. this.phone = this.phoneRef;
  21. this.toolboxRef = React.createRef();
  22. this.toolbox = this.toolboxRef;
  23. this.CoreSystem = { render: () => null};
  24. this.ToolBox = new ToolBox();
  25. this.MainBar = new MainBar();
  26. this.load();
  27. this.__onUpdate = null;
  28. this.SideBar = new SideBar();
  29. this.ToolBox.onUpdate( () =>{
  30. let SideBarProps = {
  31. tool:this.ToolBox.activeTool
  32. }
  33. this.SideBar = new SideBar(SideBarProps)
  34. this.forceUpdate()
  35. })
  36. this.MainBar.onSave( () => {
  37. this.saveEnv();
  38. this.forceUpdate()
  39. })
  40. }
  41. onMount() {
  42. if(this.phone){
  43. // thats fine
  44. this.ToolBoxMouse = new Mouse(this.toolbox.current);
  45. this.phoneMouse = new Mouse(this.phone.current);
  46. }
  47. if(this.ToolBoxMouse !== undefined){
  48. this.ToolBoxMouse.listen()
  49. .on('LeftDown',(e) => this.ToolManagement(e))
  50. this.phoneMouse.listen()
  51. .on('LeftDown',(e) => this.ToolManagement(e))
  52. }
  53. }
  54. saveEnv(){
  55. let env = this.CoreSystem.export();
  56. localStorage.setItem('environment', JSON.stringify(env));
  57. this.forceUpdate();
  58. try{
  59. this.CoreSystem.import(JSON.parse(js));
  60. this.forceUpdate();
  61. } catch(e) {
  62. console.log(e);
  63. }
  64. }
  65. ToolManagement(e){
  66. console.log("whattttt")
  67. if(this.ToolBox.activeTool === null){
  68. return null;
  69. }else{
  70. this.processElement(e)
  71. }
  72. }
  73. onUpdate(fn){
  74. this.__onUpdate = fn
  75. }
  76. forceUpdate(){
  77. this.__onUpdate && this.__onUpdate();
  78. }
  79. load() {
  80. this.CoreSystem = new CoreSystem();
  81. this.ToolBox = new ToolBox(this.CoreSystem);
  82. try{
  83. let env = localStorage.getItem('environment');
  84. if( env === null){
  85. this.CoreSystem.import(JSON.parse(jsLoad));
  86. }else{
  87. this.CoreSystem.import(JSON.parse(env));
  88. }
  89. this.forceUpdate();
  90. } catch(e) {
  91. console.log(e);
  92. }
  93. }
  94. processElement(event){
  95. console.log(event)
  96. console.log('sdasdwd')
  97. let Node = this.CoreSystem.ray({event});
  98. let NewNode = this.ToolBox.editNode(Node);
  99. this.forceUpdate();
  100. }
  101. mobileRender(){
  102. return (
  103. <div ref={this.phoneRef}>
  104. <View style={styles.mobileView}>
  105. {this.CoreSystem.render()}
  106. </View>
  107. </div>
  108. )
  109. }
  110. renderSideBar(){
  111. return this.SideBar.render();
  112. }
  113. renderMainBar(){
  114. return this.MainBar.render();
  115. }
  116. renderToolBox(){
  117. return (
  118. <div ref = {this.toolboxRef}>
  119. <View style={styles.toolbarView}>
  120. {this.ToolBox.render()}
  121. </View>
  122. </div>)
  123. }
  124. renderModuleBar(){
  125. return (
  126. <View>
  127. {this.ModuleBar.render()}
  128. </View>
  129. )
  130. }
  131. }
  132. //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"}}}}}';
  133. //jsLoad Test
  134. 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":{"0.5907657036474692":{"id":0.5907657036474692,"depth":0,"isRow":true,"isCol":false},"0.51066596548815":{"id":0.51066596548815,"depth":1,"isRow":false,"isCol":true},"0.8855478722619232":{"id":0.8855478722619232,"depth":1,"isRow":false,"isCol":true,"content":{"id":"A","depth":null,"value":"RootComp","namespace":"default","props":{"text":"This is the Starting point!!!Try add on me ","style":{"container":22,"text":23}}}},"0.4630979404426283":{"id":0.4630979404426283,"depth":1,"isRow":false,"isCol":true},"0.7144981784945621":{"id":0.7144981784945621,"depth":2,"isRow":true,"isCol":false},"0.0666081688424911":{"id":0.0666081688424911,"depth":2,"isRow":true,"isCol":false}},"links":{"0.5907657036474692":{"out":[{"to":0.51066596548815,"from":0.5907657036474692},{"to":0.8855478722619232,"from":0.5907657036474692},{"to":0.4630979404426283,"from":0.5907657036474692}],"in":[]},"0.51066596548815":{"out":[],"in":[{"to":0.51066596548815,"from":0.5907657036474692}]},"0.8855478722619232":{"out":[{"to":0.7144981784945621,"from":0.8855478722619232},{"to":0.0666081688424911,"from":0.8855478722619232}],"in":[{"to":0.8855478722619232,"from":0.5907657036474692}]},"0.4630979404426283":{"out":[],"in":[{"to":0.4630979404426283,"from":0.5907657036474692}]},"0.7144981784945621":{"out":[],"in":[{"to":0.7144981784945621,"from":0.8855478722619232}]},"0.0666081688424911":{"out":[],"in":[{"to":0.0666081688424911,"from":0.8855478722619232}]}},"levels":[[0.5907657036474692],[0.51066596548815,0.8855478722619232,0.4630979404426283],[0.7144981784945621,0.0666081688424911]],"rootId":0.5907657036474692}}}}}'
  135. const styles = StyleSheet.create({
  136. container: {
  137. flex: 1,
  138. backgroundColor: '#fff',
  139. alignItems: 'center',
  140. justifyContent: 'space-between',
  141. flexDirection: 'row'
  142. },
  143. toolbarView: {
  144. justifyContent: 'space-around',
  145. alignItems: 'center',
  146. padding: 16
  147. },
  148. mainView: {
  149. backgroundColor: '#065b69',
  150. alignSelf:'stretch',
  151. flex: 1,
  152. justifyContent: 'center',
  153. alignItems: 'center'
  154. },
  155. mobileView: {
  156. backgroundColor: 'white',
  157. borderWidth: 4,
  158. borderColor: 'orange',
  159. // iphone X
  160. width:1125/3,
  161. height: 2436/3
  162. },
  163. attributesView: {
  164. width:256,
  165. alignSelf: 'stretch',
  166. flexDirection: 'column',
  167. }
  168. });