Gui.js 5.2 KB

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