Gui.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. let {
  11. CoreSystem,
  12. ViewSystem
  13. } = Library;
  14. export default class Gui {
  15. constructor(phone , toolbox) {
  16. this.Keyboard = new Keyboard();
  17. this.phone = phone;
  18. this.toolbox = toolbox;
  19. if(this.phone){
  20. this.ToolBoxMouse = new Mouse(this.toolbox);
  21. this.phoneMouse = new Mouse(this.phone)
  22. }
  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. if(this.ToolBoxMouse !== undefined){
  41. this.ToolBoxMouse.listen()
  42. .on('LeftDown',(e) => this.ToolManagement(e))
  43. this.phoneMouse.listen()
  44. .on('LeftDown',(e) => this.ToolManagement(e))
  45. }
  46. }
  47. saveEnv(){
  48. let env = this.CoreSystem.export();
  49. localStorage.setItem('environment', JSON.stringify(env));
  50. this.forceUpdate();
  51. try{
  52. this.CoreSystem.import(JSON.parse(js));
  53. this.forceUpdate();
  54. } catch(e) {
  55. console.log(e);
  56. }
  57. }
  58. ToolManagement(e){
  59. console.log("whattttt")
  60. if(this.ToolBox.activeTool === null){
  61. return null;
  62. }else{
  63. this.processElement(e)
  64. }
  65. }
  66. onUpdate(fn){
  67. this.__onUpdate = fn
  68. }
  69. forceUpdate(){
  70. this.__onUpdate && this.__onUpdate();
  71. }
  72. load() {
  73. this.CoreSystem = new CoreSystem();
  74. this.ToolBox = new ToolBox(this.CoreSystem.ViewSystem);
  75. try{
  76. let env = localStorage.getItem('environment');
  77. if( env === null){
  78. this.CoreSystem.import(JSON.parse(jsLoad));
  79. }else{
  80. this.CoreSystem.import(JSON.parse(env));
  81. }
  82. this.forceUpdate();
  83. } catch(e) {
  84. console.log(e);
  85. }
  86. }
  87. processElement(event){
  88. console.log(event)
  89. console.log('sdasdwd')
  90. let ViewNode = this.CoreSystem.ray({event})
  91. let NewNode = this.ToolBox.editNode(ViewNode);
  92. this.forceUpdate();
  93. }
  94. mobileRender(){
  95. return (
  96. <View ref = {this.phoneRef} style={styles.mobileView}>
  97. {this.CoreSystem.render()}
  98. </View>
  99. )
  100. }
  101. renderSideBar(){
  102. return this.SideBar.render();
  103. }
  104. renderMainBar(){
  105. return this.MainBar.render();
  106. }
  107. renderToolBox(){
  108. return (
  109. <View style={styles.toolbarView}>
  110. {this.ToolBox.render()}
  111. </View>)
  112. }
  113. }
  114. //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"}}}}}';
  115. //jsLoad Test
  116. 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"}}}}}'
  117. const styles = StyleSheet.create({
  118. container: {
  119. flex: 1,
  120. backgroundColor: '#fff',
  121. alignItems: 'center',
  122. justifyContent: 'space-between',
  123. flexDirection: 'row'
  124. },
  125. toolbarView: {
  126. justifyContent: 'space-around',
  127. alignItems: 'center',
  128. padding: 16
  129. },
  130. mainView: {
  131. backgroundColor: '#065b69',
  132. alignSelf:'stretch',
  133. flex: 1,
  134. justifyContent: 'center',
  135. alignItems: 'center'
  136. },
  137. mobileView: {
  138. backgroundColor: 'white',
  139. borderWidth: 4,
  140. borderColor: 'orange',
  141. // iphone X
  142. width:1125/3,
  143. height: 2436/3
  144. },
  145. attributesView: {
  146. width:256,
  147. alignSelf: 'stretch',
  148. flexDirection: 'column',
  149. backgroundColor:'blue'
  150. }
  151. });