editor-new.js 148 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399
  1. "use strict";
  2. // Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  3. // Secretary of Defense (Personnel & Readiness).
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed under the License
  11. // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  12. // or implied. See the License for the specific language governing permissions and limitations under
  13. // the License.
  14. /// vwf/view/editor creates a view interface for editor functions.
  15. ///
  16. /// @module vwf/view/editor
  17. /// @requires version
  18. /// @requires vwf/view
  19. /// @requires vwf/utility
  20. define([
  21. "module",
  22. "version",
  23. "vwf/view",
  24. "vwf/utility",
  25. "vwf/view/lib/ace/ace",
  26. "vwf/view/lib/colorpicker/colorpicker.min",
  27. "vwf/view/widgets"
  28. ], function (module, version, view, utility, ace, colorpicker, widgets) {
  29. var self;
  30. return view.load(module, {
  31. // == Module Definition ====================================================================
  32. initialize: function () {
  33. self = this;
  34. this.ace = window.ace;
  35. this.widgets = widgets;
  36. this.nodes = {};
  37. this.scenes = {};
  38. this.allScripts = {};
  39. //$(document.head).append('<style type="text/css" media="screen"> #editorlive { height: 500px; width: 800px; } </style>');
  40. document.querySelector('head').innerHTML += '<style type="text/css" media="screen"> #editorlive { height: 500px; width: 800px; } </style>';
  41. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/editorLive.css">';
  42. //document.querySelector('head').innerHTML += '<script type="text/javascript" src="vwf/view/lib/colorpicker/colorpicker.min.js">';
  43. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/colorpicker/themes.css">';
  44. //$(document.head).append('<meta name="viewport" content="width=device-width, initial-scale=1">');
  45. document.querySelector('head').innerHTML += '<meta name="viewport" content="width=device-width, initial-scale=1">';
  46. // $('body').append('<script>mdc.autoInit()</script>');
  47. this.removeProps = (obj) => {
  48. Object.keys(obj).forEach(key =>
  49. (key === 'id' || key === 'patches' || key === 'random' || key === 'sequence') && delete obj[key] ||
  50. (obj[key] && typeof obj[key] === 'object') && this.removeProps(obj[key])
  51. );
  52. return obj;
  53. };
  54. this.getNodeDef = function (nodeID) {
  55. let node = vwf.getNode(nodeID, true);
  56. let nodeDef = self.removeProps(node);
  57. return nodeDef
  58. }
  59. this.GUID = function () {
  60. var S4 = function () {
  61. return Math.floor(
  62. Math.random() * 0x10000 /* 65536 */
  63. ).toString(16);
  64. };
  65. return (
  66. S4() + S4() + "-" +
  67. S4() + "-" +
  68. S4() + "-" +
  69. S4() + "-" +
  70. S4() + S4() + S4()
  71. );
  72. }
  73. this.getRoot = function () {
  74. var app = window.location.pathname;
  75. var pathSplit = app.split('/');
  76. if (pathSplit[0] == "") {
  77. pathSplit.shift();
  78. }
  79. if (pathSplit[pathSplit.length - 1] == "") {
  80. pathSplit.pop();
  81. }
  82. var instIndex = pathSplit.length - 1;
  83. if (pathSplit.length > 2) {
  84. if (pathSplit[pathSplit.length - 2] == "load") {
  85. instIndex = pathSplit.length - 3;
  86. }
  87. }
  88. if (pathSplit.length > 3) {
  89. if (pathSplit[pathSplit.length - 3] == "load") {
  90. instIndex = pathSplit.length - 4;
  91. }
  92. }
  93. var root = "";
  94. for (var i = 0; i < instIndex; i++) {
  95. if (root != "") {
  96. root = root + "/";
  97. }
  98. root = root + pathSplit[i];
  99. }
  100. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  101. return root
  102. };
  103. this.getRandomInt = function (min, max) {
  104. min = Math.ceil(min);
  105. max = Math.floor(max);
  106. return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
  107. };
  108. ["drawer", "toolbar", "sideBar", "propWindow", "clientsWindow", "codeEditorWindow", "propEditorWindow", "viewSceneProps"].forEach(item => {
  109. let el = document.createElement("div");
  110. el.setAttribute("id", item);
  111. document.body.appendChild(el);
  112. }
  113. );
  114. this.avatarCardDef = function (src, desc, onclickfunc) {
  115. return {
  116. $cell: true,
  117. $type: "div",
  118. class: "mdc-card avatar-card",
  119. $init: function () {
  120. this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.0) ), url(' + src + ')'
  121. },
  122. onclick: onclickfunc,
  123. $components: [
  124. {
  125. $type: "section",
  126. class: "mdc-card__primary",
  127. $components: [
  128. {
  129. $type: "h1",
  130. class: "mdc-card__title mdc-card__title--large",
  131. $text: desc.subtitle
  132. },
  133. {
  134. $type: "h2",
  135. class: "mdc-card__subtitle",
  136. $text: desc.title
  137. }
  138. ]
  139. },
  140. {
  141. $type: "section",
  142. class: "mdc-card__actions",
  143. $components: [
  144. {
  145. $type: "button",
  146. class: "mdc-button mdc-button--compact mdc-card__action",
  147. //$text: "Use it",
  148. onclick: onclickfunc
  149. }
  150. ]
  151. }
  152. ]
  153. }
  154. }
  155. let avatarSettings =
  156. {
  157. $cell: true,
  158. $type: "div",
  159. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  160. $components: [
  161. {
  162. $cell: true,
  163. $type: "div",
  164. class: "mdc-layout-grid__inner",
  165. $components: [
  166. {
  167. $cell: true,
  168. $type: "div",
  169. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  170. $components: [
  171. {
  172. $cell: true,
  173. $type: "button",
  174. class: "mdc-button mdc-button--raised",
  175. $text: "Go forward",
  176. onclick: function (e) {
  177. function getMovementVector(el) {
  178. var directionVector = new THREE.Vector3(0, 0, 0);
  179. var rotationEuler = new THREE.Euler(0, 0, 0, 'YXZ');
  180. var rotation = el.getAttribute('rotation');
  181. var velocity = new THREE.Vector3(0, 0, -0.5);
  182. var xRotation;
  183. directionVector.copy(velocity);
  184. directionVector.multiplyScalar(1.0);
  185. // Absolute.
  186. if (!rotation) { return directionVector; }
  187. xRotation = 0;
  188. // Transform direction relative to heading.
  189. rotationEuler.set(THREE.Math.degToRad(xRotation), THREE.Math.degToRad(rotation.y), 0);
  190. directionVector.applyEuler(rotationEuler);
  191. return directionVector;
  192. }
  193. let el = document.querySelector('#avatarControl');
  194. let currentPosition = el.getAttribute('position');
  195. let movementVector = getMovementVector(el);
  196. let position = {};
  197. position.x = currentPosition.x + movementVector.x;
  198. position.y = currentPosition.y + movementVector.y;
  199. position.z = currentPosition.z + movementVector.z;
  200. el.setAttribute('position', position);
  201. }
  202. },
  203. ]
  204. },
  205. {
  206. $cell: true,
  207. $type: "div",
  208. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  209. $components: [
  210. {
  211. $cell: true,
  212. $type: "button",
  213. class: "mdc-button mdc-button--raised",
  214. $text: "Reset camera view",
  215. onclick: function (e) {
  216. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  217. let controlEl = document.querySelector('#avatarControl');
  218. controlEl.setAttribute('camera', 'active', true);
  219. }
  220. },
  221. {
  222. $cell: true,
  223. $type: "button",
  224. class: "mdc-button mdc-button--raised",
  225. $text: "Hide cursor",
  226. onclick: function (e) {
  227. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  228. let avatarID = 'avatar-' + self.kernel.moniker();
  229. let cursorID = 'myCursor-' + avatarID;
  230. let controlEl = document.querySelector("[id='" + cursorID + "']");
  231. let vis = controlEl.getAttribute('visible');
  232. this.$text = vis ? 'Show cursor' : 'Hide cursor';
  233. vwf_view.kernel.callMethod(avatarID, "showHideCursor", [!vis]);
  234. //controlEl.setAttribute('visible', !vis);
  235. }
  236. }
  237. ]
  238. },
  239. {
  240. $cell: true,
  241. $type: "div",
  242. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  243. $components: [
  244. {
  245. $type: "div",
  246. class: "mdc-layout-grid",
  247. $components: [
  248. {
  249. $type: "div",
  250. class: "mdc-layout-grid__inner",
  251. $components: [
  252. {
  253. $cell: true,
  254. $type: "div",
  255. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  256. $components: [
  257. self.avatarCardDef("/../assets/avatars/ico/simple.jpg", { title: "Simple", subtitle: "Cube" },
  258. function (e) {
  259. let avatarID = 'avatar-' + self.kernel.moniker();
  260. vwf_view.kernel.callMethod(avatarID, "createSimpleAvatar");
  261. }
  262. )
  263. ]
  264. },
  265. {
  266. $cell: true,
  267. $type: "div",
  268. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  269. $components: [
  270. self.avatarCardDef("/../assets/avatars/ico/female.jpg", { title: "Human", subtitle: "Female" },
  271. function (e) {
  272. let avatarID = 'avatar-' + self.kernel.moniker();
  273. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/female/avatar1.gltf"]);
  274. }
  275. )]
  276. },
  277. {
  278. $cell: true,
  279. $type: "div",
  280. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  281. $components: [
  282. self.avatarCardDef("/../assets/avatars/ico/male.jpg", { title: "Human", subtitle: "Male" },
  283. function (e) {
  284. let avatarID = 'avatar-' + self.kernel.moniker();
  285. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/male/avatar1.gltf"]);
  286. }
  287. )]
  288. }
  289. ]
  290. }
  291. ]
  292. }
  293. ]
  294. }
  295. ]
  296. }
  297. ]
  298. }
  299. let viewSettings =
  300. {
  301. $cell: true,
  302. $type: "div",
  303. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  304. $components: [
  305. {
  306. $cell: true,
  307. $type: "div",
  308. class: "mdc-layout-grid__inner",
  309. $components: [
  310. {
  311. $cell: true,
  312. $type: "div",
  313. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  314. $components: [
  315. {
  316. $cell: true,
  317. $type: "button",
  318. class: "mdc-button mdc-button--raised",
  319. $text: "OSC Settings",
  320. onclick: function (e) {
  321. let sideBar = document.querySelector('#sideBar');
  322. sideBar._sideBarComponent = oscSettings;
  323. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  324. }
  325. }
  326. ]
  327. }
  328. ]
  329. }
  330. ]
  331. }
  332. let savedStateEl = function (item) {
  333. return {
  334. $type: "li",
  335. class: "mdc-list-item",
  336. role: "option",
  337. $components: [
  338. {
  339. $text: "Saved world"
  340. }
  341. ]
  342. }
  343. }
  344. let stateListElement = function (item) {
  345. let liEl = {
  346. $type: "li",
  347. class: "mdc-list-item",
  348. role: "option",
  349. id: "",
  350. applicationpath: "",
  351. $components: [
  352. {
  353. $text: "no saves"
  354. }
  355. ]
  356. }
  357. let applicationName = item.applicationpath.split("/");
  358. if (applicationName == "") {
  359. return liEl
  360. }
  361. if (applicationName.length > 0) {
  362. applicationName = applicationName[applicationName.length - 1];
  363. }
  364. if (applicationName.length > 0) {
  365. applicationName = applicationName.charAt(0).toUpperCase() + applicationName.slice(1);
  366. }
  367. if (item.latestsave) {
  368. liEl = {
  369. $type: "li",
  370. class: "mdc-list-item",
  371. role: "option",
  372. id: item.savename,
  373. applicationpath: item.applicationpath,
  374. $components: [
  375. {
  376. $text: applicationName + ": " + item.savename
  377. }
  378. ]
  379. }
  380. }
  381. else {
  382. liEl = {
  383. $type: "li",
  384. class: "mdc-list-item",
  385. role: "option",
  386. id: item.savename,
  387. revision: item.revision,
  388. applicationpath: item.applicationpath,
  389. $components: [
  390. {
  391. $text: applicationName + ": " + item.savename + " Rev(" + item.revision + ")"
  392. }
  393. ]
  394. }
  395. }
  396. return liEl
  397. }
  398. let oscSettings =
  399. {
  400. $cell: true,
  401. $type: "div",
  402. id: "oscSettings",
  403. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  404. _oscHost: '',
  405. _oscPort: '',
  406. _oscStatus: '',
  407. _updateStatus: function () {
  408. this._oscStatus = window._OSCManager.getStatus()
  409. },
  410. $init: function () {
  411. if (window._OSCManager) {
  412. this._oscHost = window._OSCManager.hostValue;
  413. this._oscPort = window._OSCManager.portValue;
  414. this._oscStatus = window._OSCManager.getStatus();
  415. // var t = this;
  416. // setInterval(function () {
  417. // t._updateStatus();
  418. // }, 1000);
  419. }
  420. },
  421. $update: function () {
  422. let that = this
  423. var buttonText = "Connect";
  424. var buttonFunc = function (e) {
  425. }
  426. if (this._oscStatus == 1) {
  427. buttonText = "Disconnect";
  428. buttonFunc = function (e) {
  429. window._OSCManager.disconnect();
  430. }
  431. } else {
  432. var buttonFunc = function (e) {
  433. window._OSCManager.connect();
  434. window._OSCManager.port.on("open", function () {
  435. that._oscStatus = window._OSCManager.getStatus();
  436. console.log("connected");
  437. });
  438. window._OSCManager.port.on("close", function () {
  439. that._oscStatus = window._OSCManager.getStatus();
  440. console.log("disconnected");
  441. });
  442. }
  443. }
  444. this.$components = [
  445. {
  446. $cell: true,
  447. $type: "div",
  448. class: "mdc-layout-grid__inner",
  449. $components: [
  450. {
  451. $cell: true,
  452. $type: "div",
  453. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  454. $components: [
  455. {
  456. $type: "span",
  457. $text: "Host: "
  458. },
  459. {
  460. class: "mdc-textfield",
  461. $cell: true,
  462. $type: "span",
  463. $components: [
  464. {
  465. class: "mdc-textfield__input",
  466. id: "oscHost",
  467. $cell: true,
  468. $type: "input",
  469. type: "text",
  470. value: this._oscHost,
  471. onchange: function (e) {
  472. this._oscHost = this.value;
  473. window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  474. }
  475. }
  476. ]
  477. }
  478. ]
  479. },
  480. {
  481. $cell: true,
  482. $type: "div",
  483. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  484. $components: [
  485. {
  486. $type: "span",
  487. $text: "Port: "
  488. },
  489. {
  490. class: "mdc-textfield",
  491. $cell: true,
  492. $type: "span",
  493. $components: [
  494. {
  495. class: "mdc-textfield__input",
  496. id: "oscPort",
  497. $cell: true,
  498. $type: "input",
  499. type: "text",
  500. value: this._oscPort,
  501. onchange: function (e) {
  502. this._oscPort = this.value;
  503. window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  504. }
  505. }
  506. ]
  507. }
  508. ]
  509. },
  510. {
  511. $cell: true,
  512. $type: "div",
  513. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  514. $components: [
  515. {
  516. $cell: true,
  517. $type: "button",
  518. class: "mdc-button mdc-button--raised",
  519. $text: buttonText,
  520. onclick: buttonFunc
  521. }
  522. ]
  523. }
  524. ]
  525. }
  526. ]
  527. }
  528. }
  529. let loadSaveSettings =
  530. {
  531. $cell: true,
  532. $type: "div",
  533. id: "loadSaveSettings",
  534. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  535. _saveStates: [],
  536. _getStates: async function () {
  537. let response = await fetch("/" + self.getRoot() + "/listallsaves");
  538. let data = await response.json();
  539. //this._saveStates = data;
  540. //let appName = self.getRoot();
  541. //console.log(data.filter(item => item.applicationpath.split("/")[1] == appName));
  542. let filterData = data.filter(item => item.applicationpath.split("/")[1] == self.getRoot());
  543. if (filterData.length !== 0) {
  544. this._saveStates = filterData
  545. //return filterData
  546. } else {
  547. this._saveStates = [{
  548. savename: "",
  549. latestsave: "",
  550. revision: "",
  551. applicationpath: "",
  552. url: ""
  553. }]
  554. }
  555. // this._saveStates.filter(item => item.applicationpath.split("/")[1] == self.getRoot()).map(stateListElement)
  556. //return data
  557. //console.log(data);
  558. return this._saveStates
  559. },
  560. $init: function () {
  561. this._getStates();
  562. },
  563. $update: function () {
  564. this.$components =
  565. [
  566. {
  567. $cell: true,
  568. $type: "div",
  569. class: "mdc-layout-grid__inner",
  570. $components: [
  571. {
  572. $cell: true,
  573. $type: "div",
  574. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  575. $components: [
  576. {
  577. class: "mdc-textfield",
  578. $cell: true,
  579. $type: "span",
  580. $components: [
  581. {
  582. class: "mdc-textfield__input",
  583. id: "fileName",
  584. $cell: true,
  585. $type: "input",
  586. type: "text",
  587. value: self.getRoot()
  588. }]
  589. }
  590. ]
  591. },
  592. {
  593. $cell: true,
  594. $type: "div",
  595. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  596. $components: [
  597. {
  598. $cell: true,
  599. $type: "button",
  600. class: "mdc-button mdc-button--raised",
  601. $text: "Save",
  602. onclick: function (e) {
  603. let fileName = document.querySelector('#fileName')
  604. saveStateAsFile.call(self, fileName.value);
  605. document.querySelector("#fileName").value = '';
  606. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  607. }
  608. }
  609. ]
  610. },
  611. {
  612. $cell: true,
  613. $type: "div",
  614. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  615. $components: [
  616. {
  617. $cell: true,
  618. $type: "div",
  619. class: "mdc-select",
  620. $init: function () {
  621. var MDCSelect = mdc.select.MDCSelect;
  622. const select = new MDCSelect(document.querySelector('.mdc-select'));
  623. select.listen('MDCSelect:change', () => {
  624. //this._selectedState = select.value;
  625. document.querySelector('#loadStateButton')._selectedState = select.selectedOptions[0];
  626. //console.log(select.value);
  627. //.selectedOptions[0]
  628. });
  629. },
  630. role: "listbox",
  631. $components: [
  632. {
  633. $type: "span",
  634. class: "mdc-select__selected-text",
  635. $text: "Select saved state"
  636. },
  637. {
  638. $type: "div",
  639. class: "mdc-simple-menu mdc-select__menu",
  640. $components: [
  641. {
  642. $type: "ul",
  643. class: "mdc-list mdc-simple-menu__items",
  644. $components: this._saveStates.map(stateListElement)
  645. }
  646. ]
  647. }
  648. ]
  649. }
  650. ]
  651. },
  652. {
  653. $cell: true,
  654. $type: "div",
  655. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  656. $components: [
  657. {
  658. $cell: true,
  659. $type: "button",
  660. _selectedState: {},
  661. id: "loadStateButton",
  662. class: "mdc-button mdc-button--raised",
  663. $text: "Load",
  664. onclick: function (e) {
  665. loadSavedState.call(self, this._selectedState.getAttribute('id'), this._selectedState.getAttribute('applicationpath'), this._selectedState.getAttribute('revision'));
  666. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  667. }
  668. }
  669. ]
  670. }
  671. ]
  672. }
  673. ]
  674. }
  675. }
  676. let protoPropertiesCell = function (m) {
  677. return {
  678. $type: "div",
  679. class: "mdc-layout-grid__inner",
  680. _prop: {},
  681. $init: function () {
  682. let prop = m[1].prop;
  683. if (prop.value == undefined && this._currentNode !== undefined) {
  684. prop.value = JSON.stringify(utility.transform(vwf.getProperty(this._currentNode, prop.name, []), utility.transforms.transit));
  685. }
  686. this._prop = prop
  687. },
  688. $update: function () {
  689. this.$components = [
  690. {
  691. $type: "div",
  692. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  693. $components: [
  694. { $text: this._prop.name }
  695. ]
  696. },
  697. {
  698. $type: "div",
  699. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  700. },
  701. {
  702. $type: "div",
  703. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  704. $components: [
  705. {
  706. class: "mdc-textfield",
  707. $cell: true,
  708. $type: "div",
  709. $components: [{
  710. class: "mdc-textfield__input",
  711. $cell: true,
  712. $type: "input",
  713. type: "text",
  714. value: this._prop.value,
  715. onchange: function (e) {
  716. let propValue = this.value;
  717. try {
  718. propValue = JSON.parse(propValue);
  719. self.kernel.setProperty(this._currentNode, this._prop.name, propValue);
  720. } catch (e) {
  721. // restore the original value on error
  722. this.value = propValue;
  723. }
  724. }
  725. }]
  726. }
  727. ]
  728. }
  729. ]
  730. }
  731. }
  732. }
  733. let propertiesCell = function (m) {
  734. var editComponents = [{}, {}]
  735. if (m.name.indexOf("semantics") > -1) { }
  736. else if (m.name.indexOf("grammar") > -1) { }
  737. else if (m.name.indexOf("ohm") > -1) {
  738. editComponents = [
  739. {
  740. $type: "div",
  741. $cell: true,
  742. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  743. $components: [
  744. {
  745. $cell: true,
  746. $type: "button",
  747. class: "mdc-button",
  748. $text: "Edit", //edit grammar
  749. onclick: function (e) {
  750. var currentNode = document.querySelector('#currentNode')._currentNode;
  751. if (currentNode == '') {
  752. currentNode = vwf_view.kernel.find("", "/")[0];
  753. }
  754. let editor = document.querySelector('#livePropEditor');
  755. editor._setNode(currentNode);
  756. editor._propName = m.name;
  757. editor._prop = { body: m.rawValue, type: 'complex' }
  758. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  759. }
  760. }
  761. ]
  762. },
  763. {
  764. $type: "div",
  765. $cell: true,
  766. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  767. $components: []
  768. }
  769. ]
  770. } else {
  771. editComponents = [
  772. {
  773. $type: "div",
  774. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  775. $components: [
  776. {
  777. class: "mdc-textfield",
  778. $cell: true,
  779. $type: "span",
  780. $components: [
  781. {
  782. class: "mdc-textfield__input",
  783. id: "prop-" + m.name,
  784. $cell: true,
  785. $type: "input",
  786. type: "text",
  787. value: m.getValue(),
  788. onchange: function (e) {
  789. let propValue = this.value;
  790. try {
  791. propValue = JSON.parse(propValue);
  792. self.kernel.setProperty(this._currentNode, m.name, propValue);
  793. } catch (e) {
  794. // restore the original value on error
  795. this.value = propValue;
  796. }
  797. }
  798. }
  799. ]
  800. }
  801. ]
  802. },
  803. {
  804. $type: "div",
  805. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  806. $components: [
  807. {
  808. $cell: true,
  809. $type: "button",
  810. class: "mdc-button",
  811. $text: "^", //edit grammar
  812. onclick: function (e) {
  813. var currentNode = document.querySelector('#currentNode')._currentNode;
  814. if (currentNode == '') {
  815. currentNode = vwf_view.kernel.find("", "/")[0];
  816. }
  817. let editor = document.querySelector('#livePropEditor');
  818. editor._setNode(currentNode);
  819. editor._propName = m.name;
  820. editor._prop = { body: m.getValue(), type: 'simple' }
  821. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  822. }
  823. }
  824. ]
  825. }
  826. ];
  827. }
  828. return {
  829. $type: "div",
  830. class: "mdc-layout-grid__inner",
  831. $components: [
  832. {
  833. $type: "div",
  834. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  835. $components: [
  836. { $text: m.name }
  837. ]
  838. },
  839. {
  840. $type: "div",
  841. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  842. },
  843. editComponents[0],
  844. editComponents[1]
  845. ]
  846. }
  847. }
  848. let nodeLink = function (m) {
  849. var myClass = "nodeItem";
  850. let myAvatarName = 'avatar-' + self.kernel.moniker();
  851. (myAvatarName == m.name) ? (myClass = "avatarName mdc-typography--subheading2") :
  852. myClass = "nodeItem"
  853. return {
  854. $type: "li",
  855. class: "mdc-list-item",
  856. $components: [{
  857. $type: "a",
  858. class: "mdc-list-item",
  859. $href: "#",
  860. $components: [{
  861. $type: 'span',
  862. class: myClass,
  863. $text: m.name
  864. }
  865. ],
  866. onclick: function (e) {
  867. //self.currentNodeID = m.ID;
  868. document.querySelector('#currentNode')._setNode(m.ID);
  869. // document.querySelector('#liveCodeEditor')._editorNode = m.ID;
  870. // createAceEditor(self, m.ID);
  871. }
  872. }]
  873. }
  874. };
  875. let listDivider = {
  876. $cell: true,
  877. $type: "hr",
  878. class: "mdc-list-divider",
  879. }
  880. let webrtcGUI = {
  881. $type: "div",
  882. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  883. $components: [
  884. {
  885. $type: "div",
  886. class: "mdc-layout-grid__inner",
  887. $components: [
  888. {
  889. $type: "div",
  890. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  891. $components: [
  892. {
  893. $cell: true,
  894. $type: "span",
  895. $text: "ON",
  896. }
  897. ]
  898. },
  899. {
  900. $type: "div",
  901. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  902. $components: [
  903. widgets.switch({
  904. 'id': "webrtcswitch",
  905. 'init': function(){
  906. let driver = vwf.views["vwf/view/webrtc"];
  907. if (!driver) this.setAttribute('disabled', '');
  908. },
  909. "onchange": function(e){
  910. let driver = vwf.views["vwf/view/webrtc"];
  911. let avatarID = 'avatar-' + self.kernel.moniker();
  912. let chkAttr = this.checked;
  913. if (chkAttr) {
  914. driver.startWebRTC(avatarID);
  915. console.log("on")
  916. } else {
  917. driver.stopWebRTC(avatarID);
  918. console.log("off")
  919. }
  920. }
  921. })
  922. ]
  923. },
  924. {
  925. $type: "div",
  926. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  927. $components: [
  928. {
  929. $cell: true,
  930. $type: "span",
  931. $text: "Mic: ",
  932. }
  933. ]
  934. },
  935. {
  936. $type: "div",
  937. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  938. $components: [
  939. widgets.switch({
  940. 'id': "webrtcaudio",
  941. 'init': function(){
  942. let driver = vwf.views["vwf/view/webrtc"];
  943. if (!driver) this.setAttribute('disabled', '');
  944. },
  945. "onchange": function(e){
  946. let driver = vwf.views["vwf/view/webrtc"];
  947. let chkAttr = this.checked;
  948. if (chkAttr) {
  949. driver.muteAudio([chkAttr]);
  950. console.log("on")
  951. } else {
  952. driver.muteAudio([chkAttr]);
  953. console.log("off")
  954. }
  955. }
  956. })
  957. ]
  958. },
  959. {
  960. $type: "div",
  961. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  962. $components: [
  963. {
  964. $cell: true,
  965. $type: "span",
  966. $text: "Cam: ",
  967. }
  968. ]
  969. },
  970. {
  971. $type: "div",
  972. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  973. $components: [
  974. widgets.switch({
  975. 'id': "webrtcvideo",
  976. 'init': function(){
  977. let driver = vwf.views["vwf/view/webrtc"];
  978. if (!driver) this.setAttribute('disabled', '');
  979. },
  980. "onchange": function(e){
  981. let driver = vwf.views["vwf/view/webrtc"];
  982. let chkAttr = this.checked;
  983. if (chkAttr) {
  984. driver.muteVideo([chkAttr]);
  985. console.log("on")
  986. } else {
  987. driver.muteVideo([chkAttr]);
  988. console.log("off")
  989. }
  990. }
  991. })
  992. ]
  993. }
  994. ]
  995. }
  996. ]
  997. }
  998. let gizmoEdit = {
  999. $type: "div",
  1000. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1001. $components: [
  1002. {
  1003. $type: "div",
  1004. class: "mdc-layout-grid__inner",
  1005. $components: [
  1006. {
  1007. $type: "div",
  1008. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1009. $components: [
  1010. {
  1011. $cell: true,
  1012. $type: "span",
  1013. $text: "Edit: ",
  1014. }
  1015. ]
  1016. },
  1017. {
  1018. $type: "div",
  1019. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  1020. $components: [
  1021. widgets.switch({
  1022. 'id': 'editnode',
  1023. 'init': function(){
  1024. vwf_view.kernel.getProperty(this._currentNode, 'edit');
  1025. },
  1026. 'onchange': function(e){
  1027. var nodeID = document.querySelector('#currentNode')._currentNode;
  1028. let chkAttr = this.getAttribute('checked');
  1029. if (chkAttr == "") {
  1030. self.kernel.setProperty(this._currentNode, 'edit', false);
  1031. } else {
  1032. self.kernel.setProperty(this._currentNode, 'edit', true);
  1033. }
  1034. vwf_view.kernel.callMethod(nodeID, "showCloseGizmo");
  1035. }
  1036. }
  1037. )
  1038. ]
  1039. },
  1040. {
  1041. $type: "div",
  1042. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  1043. $components: [
  1044. {
  1045. $cell: true,
  1046. $type: "a",
  1047. class: "gizmomode",
  1048. $text: "T",
  1049. onclick: function (e) {
  1050. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['translate'])
  1051. }
  1052. }
  1053. ]
  1054. },
  1055. {
  1056. $type: "div",
  1057. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  1058. $components: [
  1059. {
  1060. $cell: true,
  1061. $type: "a",
  1062. class: "gizmomode",
  1063. $text: "R",
  1064. onclick: function (e) {
  1065. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['rotate'])
  1066. }
  1067. }
  1068. ]
  1069. },
  1070. {
  1071. $type: "div",
  1072. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  1073. $components: [
  1074. {
  1075. $cell: true,
  1076. $type: "a",
  1077. class: "gizmomode",
  1078. $text: "S",
  1079. onclick: function (e) {
  1080. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['scale'])
  1081. }
  1082. }
  1083. ]
  1084. }
  1085. ]
  1086. }
  1087. ]
  1088. }
  1089. let nodesCell = {
  1090. $cell: true,
  1091. $type: "div",
  1092. id: "currentNode",
  1093. _childNodes: [],
  1094. _currentNode: '',
  1095. _displayedProperties: {},
  1096. _setNode: function (aNode) {
  1097. this._currentNode = aNode;
  1098. document.querySelector('#sideBar')._sideCurrentNode = this._currentNode
  1099. },
  1100. $init: function () {
  1101. this._currentNode = document.querySelector('#sideBar')._sideCurrentNode
  1102. //this._currentNode = vwf_view.kernel.find("", "/")[0];
  1103. //this._currentNode = '3333';
  1104. },
  1105. _getChildNodes: function () {
  1106. this._childNodes = self.nodes[this._currentNode];
  1107. if (this._childNodes !== undefined) {
  1108. return this._childNodes.children
  1109. } else {
  1110. return []
  1111. }
  1112. //let nodeIDAlpha = he.encode(this._currentNode);
  1113. },
  1114. // _getNodeComplexProperties: function () {
  1115. // let node = self.nodes[this._currentNode];
  1116. // let props = this._getNodeProperties();
  1117. // let filterFunction = function (prop) {
  1118. // return (prop.name == 'ohmLang')
  1119. // };
  1120. // let complexProps = props.filter(filterFunction.bind(this));
  1121. // return complexProps
  1122. // },
  1123. _getNodeProperties: function () {
  1124. let node = self.nodes[this._currentNode];
  1125. this._displayedProperties = {};
  1126. let filterFunction = function (prop) {
  1127. return (!this._displayedProperties[prop.name] && prop.name.indexOf('$') === -1) ? (this._displayedProperties[prop.name] = "instance", true) : (false);
  1128. };
  1129. let props = node.properties.filter(filterFunction.bind(this));
  1130. return props
  1131. },
  1132. _getNodeProtoProperties: function () {
  1133. let node = self.nodes[this._currentNode];
  1134. let filterFunction = function (prop) {
  1135. return (!this._displayedProperties[prop[1].prop.name]) ? (this._displayedProperties[prop[1].prop.name] = prop[1].prototype, true) : (false);
  1136. };
  1137. let props = Object.entries(getProperties.call(self, self.kernel, node.extendsID)).filter(filterFunction.bind(this));
  1138. return props
  1139. },
  1140. $update: function () {
  1141. //this.$text = this._currentNode;
  1142. let node = self.nodes[this._currentNode];
  1143. let nodeProtos = getPrototypes(self.kernel, node.extendsID);
  1144. var viewerProps = {};
  1145. var viewerPropsCell = {};
  1146. var gizmoCell = {};
  1147. if (this._currentNode !== self.kernel.application()) {
  1148. if (nodeProtos.includes('http://vwf.example.com/aframe/componentNode.vwf')) {
  1149. //gizmoCell = {};
  1150. } else {
  1151. gizmoCell = gizmoEdit
  1152. }
  1153. }
  1154. if (node !== undefined) {
  1155. if (node.extendsID == "http://vwf.example.com/aframe/acamera.vwf") {
  1156. viewerProps = {
  1157. $type: "li",
  1158. class: "mdc-list-item",
  1159. $components: [
  1160. {
  1161. $text: "Viewer properties",
  1162. $type: "span",
  1163. class: "mdc-list-item__text mdc-typography--button"
  1164. }
  1165. ]
  1166. }
  1167. viewerPropsCell = {
  1168. $cell: true,
  1169. $type: "div",
  1170. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1171. $components: [
  1172. {
  1173. $cell: true,
  1174. $type: "div",
  1175. class: "mdc-layout-grid__inner",
  1176. $components: [
  1177. {
  1178. $cell: true,
  1179. $type: "div",
  1180. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1181. $components: [
  1182. {
  1183. $cell: true,
  1184. $type: "button",
  1185. class: "mdc-button mdc-button--raised",
  1186. $text: "Active",
  1187. onclick: function (e) {
  1188. let camera = document.querySelector('#' + this._currentNode);
  1189. camera.setAttribute('camera', 'active', true);
  1190. }
  1191. }
  1192. ]
  1193. }
  1194. ]
  1195. }
  1196. ]
  1197. //$components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1198. }
  1199. } else {
  1200. viewerProps = {};
  1201. viewerPropsCell = {};
  1202. }
  1203. }
  1204. this.$components = [
  1205. {
  1206. $cell: true,
  1207. $type: "ul",
  1208. class: "mdc-list",
  1209. $components: [
  1210. {
  1211. $cell: true,
  1212. $type: "button",
  1213. class: "mdc-list-item mdc-button mdc-button--raised",
  1214. $text: "<--",
  1215. onclick: function (e) {
  1216. let node = self.nodes[this._currentNode];
  1217. if (node.parentID !== 0) {
  1218. //self.currentNodeID = node.parentID,
  1219. document.querySelector('#currentNode')._setNode(node.parentID)
  1220. }
  1221. }
  1222. },
  1223. {
  1224. $type: "li",
  1225. class: "mdc-list-item",
  1226. $components: [
  1227. {
  1228. $text: "name",
  1229. $type: "span",
  1230. $init: function () {
  1231. let node = self.nodes[this._currentNode];
  1232. if (node) this.$text = node.name
  1233. },
  1234. class: "mdc-list-item__text mdc-typography--headline"
  1235. //<h1 class="mdc-typography--display4">Big header</h1>
  1236. }]
  1237. }, listDivider,
  1238. {
  1239. // $cell: true,
  1240. // $type: "ul",
  1241. // class: "mdc-list",
  1242. $type: "div",
  1243. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1244. $components: [
  1245. {
  1246. $type: "div",
  1247. class: "mdc-layout-grid__inner",
  1248. $components: [
  1249. {
  1250. $type: "div",
  1251. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1252. $components: [
  1253. {
  1254. $cell: true,
  1255. $type: "button",
  1256. class: "mdc-button mdc-button--raised",
  1257. $text: "Methods browser",
  1258. onclick: function (e) {
  1259. var currentNode = document.querySelector('#currentNode')._currentNode;
  1260. if (currentNode == '') {
  1261. currentNode = vwf_view.kernel.find("", "/")[0];
  1262. }
  1263. document.querySelector('#liveCodeEditor')._setNode(currentNode);
  1264. //createAceEditor(self, currentNode);
  1265. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  1266. }
  1267. }
  1268. ]
  1269. }
  1270. ]
  1271. }
  1272. ]
  1273. },
  1274. gizmoCell,
  1275. listDivider,
  1276. {
  1277. $type: "li",
  1278. class: "mdc-list-item",
  1279. $components: [
  1280. {
  1281. $text: "Children",
  1282. $type: "span",
  1283. class: "mdc-list-item__text mdc-typography--button"
  1284. }]
  1285. },
  1286. {
  1287. $cell: true,
  1288. $type: "ul",
  1289. class: "mdc-list",
  1290. $components: this._getChildNodes().map(nodeLink)
  1291. }, listDivider, {
  1292. $type: "li",
  1293. class: "mdc-list-item",
  1294. $components: [
  1295. {
  1296. $text: "Properties",
  1297. $type: "span",
  1298. class: "mdc-list-item__text mdc-typography--button"
  1299. //<h1 class="mdc-typography--display4">Big header</h1>
  1300. }]
  1301. },
  1302. {
  1303. // $cell: true,
  1304. // $type: "ul",
  1305. // class: "mdc-list",
  1306. $type: "div",
  1307. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1308. $components: this._getNodeProperties().map(propertiesCell)
  1309. },
  1310. listDivider,
  1311. {
  1312. $type: "li",
  1313. class: "mdc-list-item",
  1314. $components: [
  1315. {
  1316. $text: "Proto properties",
  1317. $type: "span",
  1318. class: "mdc-list-item__text mdc-typography--button"
  1319. }]
  1320. },
  1321. {
  1322. $cell: true,
  1323. $type: "div",
  1324. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1325. $components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1326. }, listDivider,
  1327. viewerProps,
  1328. viewerPropsCell
  1329. ]
  1330. }
  1331. ]
  1332. }
  1333. }
  1334. let colorPickerComponent = {
  1335. $cell: true,
  1336. $type: "div",
  1337. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  1338. $init: function () {
  1339. let myEl = this;
  1340. let cp = ColorPicker(
  1341. document.getElementById('slide'),
  1342. document.getElementById('picker'),
  1343. function (hex, hsv, rgb, mousePicker, mouseSlide) {
  1344. ColorPicker.positionIndicators(
  1345. document.getElementById('slide-indicator'),
  1346. document.getElementById('picker-indicator'),
  1347. mouseSlide, mousePicker
  1348. );
  1349. if (myEl._propName == 'color') {
  1350. // console.log(hex);
  1351. document.querySelector('#propAceEditor').env.editor.setValue(JSON.stringify(hex));
  1352. self.kernel.setProperty(myEl._editorNode, myEl._propName, hex);
  1353. }
  1354. });
  1355. if (myEl._propName == 'color') {
  1356. cp.setHex(JSON.parse(myEl._prop.body));
  1357. }
  1358. },
  1359. $components: [
  1360. {
  1361. $cell: true,
  1362. $type: "div",
  1363. id: "color-picker",
  1364. class: "cp-default",
  1365. $components: [
  1366. {
  1367. $cell: true,
  1368. $type: "div",
  1369. class: "picker-wrapper",
  1370. $components: [
  1371. {
  1372. $cell: true,
  1373. $type: "div",
  1374. id: "picker",
  1375. class: "picker",
  1376. style: "width: 130px; height: 130px"
  1377. },
  1378. {
  1379. $cell: true,
  1380. $type: "div",
  1381. id: "picker-indicator",
  1382. class: "picker-indicator"
  1383. }
  1384. ]
  1385. },
  1386. {
  1387. $cell: true,
  1388. $type: "div",
  1389. class: "slide-wrapper",
  1390. $components: [
  1391. {
  1392. $cell: true,
  1393. $type: "div",
  1394. id: "slide",
  1395. class: "slide",
  1396. style: "width: 30px; height: 130px"
  1397. },
  1398. {
  1399. $cell: true,
  1400. $type: "div",
  1401. id: "slide-indicator",
  1402. class: "slide-indicator"
  1403. }
  1404. ]
  1405. }
  1406. ]
  1407. }
  1408. // {
  1409. // $cell: true,
  1410. // $type: "div",
  1411. // id: "color-picker",
  1412. // $init: function () {
  1413. // }
  1414. // }
  1415. ]
  1416. }
  1417. let propEditorWindow = {
  1418. $cell: true,
  1419. $type: "div",
  1420. _editorNode: '',
  1421. _prop: { body: '', type: 'simple' },
  1422. _propName: '',
  1423. id: "livePropEditor",
  1424. _setNode: function (node) {
  1425. this._editorNode = node;
  1426. this._prop.body = ''
  1427. },
  1428. class: "propEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1429. $update: function () {
  1430. var editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-8"
  1431. var livePropertyComponent = {}
  1432. if (this._prop.type == 'simple') {
  1433. if (this._propName == 'color') {
  1434. livePropertyComponent = colorPickerComponent
  1435. }
  1436. } else {
  1437. editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-12"
  1438. }
  1439. this.$components = [
  1440. {
  1441. $cell: true,
  1442. $type: "div",
  1443. class: "mdc-layout-grid__inner",
  1444. $components: [
  1445. {
  1446. $cell: true,
  1447. $type: "div",
  1448. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1449. $components: [
  1450. {
  1451. $cell: true,
  1452. $type: "button",
  1453. class: "mdc-button mdc-button--raised",
  1454. $text: "Update",
  1455. onclick: function (e) {
  1456. let editor = document.querySelector("#propAceEditor").env.editor;
  1457. let value = editor.getValue();
  1458. try {
  1459. let propValue = (this._prop.type == 'simple') ? (JSON.parse(value)) : (value)
  1460. //propValue = JSON.parse(value);
  1461. self.kernel.setProperty(this._editorNode, this._propName, propValue);
  1462. } catch (e) {
  1463. // restore the original value on error
  1464. this.value = propValue;
  1465. }
  1466. }
  1467. }]
  1468. },
  1469. {
  1470. $cell: true,
  1471. $type: "div",
  1472. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  1473. $components: [
  1474. {
  1475. $type: "h3",
  1476. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1477. $text: this._editorNode
  1478. }
  1479. ]
  1480. },
  1481. {
  1482. $cell: true,
  1483. $type: "div",
  1484. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  1485. $components: [
  1486. {
  1487. $type: "h3",
  1488. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1489. $text: this._propName
  1490. }
  1491. ]
  1492. }
  1493. ]
  1494. },
  1495. {
  1496. $cell: true,
  1497. $type: "div",
  1498. class: "mdc-layout-grid__inner",
  1499. $components: [
  1500. {
  1501. $cell: true,
  1502. $type: "div",
  1503. class: editorClass,
  1504. $components: [
  1505. {
  1506. $cell: true,
  1507. class: "aceEditor",
  1508. id: "propAceEditor",
  1509. $type: "div",
  1510. $text: this._prop.body,
  1511. $init: function () {
  1512. createAceEditor(self, this._editorNode, "propAceEditor");
  1513. this.env.editor.$blockScrolling = Infinity
  1514. }
  1515. }
  1516. ]
  1517. }, livePropertyComponent
  1518. // {
  1519. // $cell: true,
  1520. // $type: "div",
  1521. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1522. // $components: []
  1523. // },
  1524. ]
  1525. }
  1526. ]
  1527. //$components:
  1528. }
  1529. }
  1530. let codeEditorWindow = {
  1531. $cell: true,
  1532. $type: "div",
  1533. _editorNode: '',
  1534. _method: { body: '' },
  1535. _methodName: '',
  1536. _getNodeMethods: function () {
  1537. let node = self.nodes[this._editorNode];
  1538. return node.methods
  1539. },
  1540. _getProtoNodeMethods: function () {
  1541. let node = self.nodes[this._editorNode];
  1542. let prototypeMethods = getMethods.call(self, self.kernel, node.extendsID);
  1543. return prototypeMethods
  1544. },
  1545. id: "liveCodeEditor",
  1546. _setNode: function (node) {
  1547. this._editorNode = node;
  1548. this._method.body = ''
  1549. },
  1550. class: "codeEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1551. // _getComplexProps: function(){
  1552. // let node = self.nodes[this._editorNode];
  1553. // let currentNode = document.querySelector('#currentNode');
  1554. // var props = {}
  1555. // if (currentNode !== null) {
  1556. // props = currentNode._getNodeComplexProperties();
  1557. // }
  1558. // return props
  1559. // },
  1560. // _listPropertyElement: function (m) {
  1561. // return {
  1562. // $type: "li",
  1563. // class: "mdc-list-item",
  1564. // $components: [{
  1565. // $type: "a",
  1566. // class: "mdc-list-item",
  1567. // $href: "#",
  1568. // $text: m[1].name,
  1569. // onclick: function (e) {
  1570. // this._method = {};
  1571. // this._methodName = m[1].name;
  1572. // this._method.body = m[1].rawValue
  1573. // this._method.type = "complexProperty"
  1574. // }
  1575. // }]
  1576. // }
  1577. // },
  1578. _listElement: function (m) {
  1579. return {
  1580. $type: "li",
  1581. class: "mdc-list-item",
  1582. $components: [{
  1583. $type: "a",
  1584. class: "mdc-list-item",
  1585. $href: "#",
  1586. $text: m[0],
  1587. onclick: function (e) {
  1588. let method = vwf.getMethod(this._editorNode, m[0]);
  1589. //document.querySelector('#aceEditor').
  1590. this._method = method;
  1591. this._methodName = m[0];
  1592. //self.currentNodeID = m.ID;
  1593. //document.querySelector('#currentNode')._setNode(m.ID);
  1594. }
  1595. }]
  1596. }
  1597. },
  1598. $update: function () {
  1599. this.$components = [
  1600. {
  1601. $cell: true,
  1602. $type: "div",
  1603. class: "mdc-layout-grid__inner",
  1604. $components: [
  1605. {
  1606. $cell: true,
  1607. $type: "div",
  1608. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1609. $components: [
  1610. {
  1611. $type: "h3",
  1612. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1613. $text: this._editorNode
  1614. }
  1615. ]
  1616. },
  1617. {
  1618. $cell: true,
  1619. $type: "div",
  1620. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1621. $components: [
  1622. {
  1623. $cell: true,
  1624. $type: "button",
  1625. class: "mdc-button mdc-button--raised",
  1626. $text: "Update",
  1627. onclick: function (e) {
  1628. let editor = document.querySelector("#aceEditor").env.editor;
  1629. let evalText = editor.getValue();
  1630. // if (this._method.type == 'complexProperty') {
  1631. // let propValue = evalText;
  1632. // try {
  1633. // //propValue = JSON.parse(propValue);
  1634. // self.kernel.setProperty(this._editorNode, this._methodName, propValue);
  1635. // } catch (e) {
  1636. // // restore the original value on error
  1637. // this.value = propValue;
  1638. // }
  1639. // } else {
  1640. // }
  1641. self.kernel.setMethod(this._editorNode, this._methodName,
  1642. { body: evalText, type: "application/javascript", parameters: this._method.parameters });
  1643. }
  1644. }]
  1645. },
  1646. {
  1647. $cell: true,
  1648. $type: "div",
  1649. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1650. $components: [
  1651. {
  1652. $cell: true,
  1653. $type: "button",
  1654. class: "mdc-button mdc-button--raised",
  1655. $text: "Call",
  1656. onclick: function (e) {
  1657. var params = [];
  1658. if (this._method.parameters) {
  1659. let paramsLength = this._method.parameters.length
  1660. if (paramsLength >= 1) {
  1661. let paramsVal = document.querySelector("#methodParams").value;
  1662. try {
  1663. params = JSON.parse(paramsVal);
  1664. //params.push(prmtr);
  1665. } catch (e) {
  1666. self.logger.error('Invalid Value');
  1667. }
  1668. }
  1669. };
  1670. self.kernel.callMethod(this._editorNode, this._methodName, params);
  1671. }
  1672. }]
  1673. },
  1674. {
  1675. $cell: true,
  1676. $type: "div",
  1677. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1678. $components: [
  1679. {
  1680. $cell: true,
  1681. $type: "button",
  1682. class: "mdc-button mdc-button--raised",
  1683. $text: "Do It",
  1684. onclick: function (e) {
  1685. let editor = document.querySelector("#aceEditor").env.editor;
  1686. codeEditorDoit.call(self, editor, this._editorNode);
  1687. }
  1688. }]
  1689. },
  1690. {
  1691. $cell: true,
  1692. $type: "div",
  1693. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1694. $components: [
  1695. {
  1696. $cell: true,
  1697. $type: "button",
  1698. class: "mdc-button mdc-button--raised",
  1699. $text: "Print It",
  1700. onclick: function (e) {
  1701. let editor = document.querySelector("#aceEditor").env.editor;
  1702. codeEditorPrintit.call(self, editor, this._editorNode);
  1703. }
  1704. }]
  1705. }
  1706. ]
  1707. },
  1708. {
  1709. $cell: true,
  1710. $type: "div",
  1711. class: "mdc-layout-grid__inner",
  1712. $components: [
  1713. {
  1714. $cell: true,
  1715. $type: "div",
  1716. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1717. style: "overflow-y: scroll; max-height: 400px;",
  1718. $components: [
  1719. {
  1720. $cell: true,
  1721. $type: "div",
  1722. class: "mdc-list-group",
  1723. $components: [
  1724. {
  1725. $type: "h3",
  1726. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1727. $text: "Node methods"
  1728. },
  1729. {
  1730. $cell: true,
  1731. $type: "ul",
  1732. class: "mdc-list",
  1733. $components: Object.entries(this._getNodeMethods()).map(this._listElement)
  1734. }, listDivider,
  1735. {
  1736. $type: "h3",
  1737. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1738. $text: "Proto methods"
  1739. },
  1740. {
  1741. $cell: true,
  1742. $type: "ul",
  1743. class: "mdc-list",
  1744. $components: Object.entries(this._getProtoNodeMethods()).map(this._listElement)
  1745. }, listDivider,
  1746. {
  1747. $type: "h3",
  1748. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1749. $text: "Events"
  1750. }
  1751. // {
  1752. // $cell: true,
  1753. // $type: "ul",
  1754. // class: "mdc-list",
  1755. // $components: Object.entries(this._getComplexProps()).map(this._listPropertyElement)
  1756. // }
  1757. ]
  1758. }
  1759. ]
  1760. },
  1761. {
  1762. $cell: true,
  1763. $type: "div",
  1764. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-9",
  1765. $components: [
  1766. {
  1767. $cell: true,
  1768. class: "aceEditor",
  1769. id: "aceEditor",
  1770. $type: "div",
  1771. $text: this._method.body,
  1772. $init: function () {
  1773. createAceEditor(self, this._editorNode, "aceEditor");
  1774. }
  1775. }
  1776. ]
  1777. }
  1778. ]
  1779. },
  1780. {
  1781. $cell: true,
  1782. $type: "div",
  1783. class: "mdc-layout-grid__inner",
  1784. $components: [
  1785. {
  1786. $cell: true,
  1787. $type: "div",
  1788. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1789. $components: [
  1790. {
  1791. $type: "span",
  1792. $text: "*"
  1793. }
  1794. ]
  1795. }
  1796. ]
  1797. },
  1798. { //params input
  1799. $cell: true,
  1800. $type: "div",
  1801. class: "mdc-layout-grid__inner",
  1802. $components: [
  1803. {
  1804. $cell: true,
  1805. $type: "div",
  1806. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1807. $components: [
  1808. {
  1809. class: "mdc-textfield",
  1810. $cell: true,
  1811. $type: "div",
  1812. $components: [{
  1813. class: "mdc-textfield__input",
  1814. id: "methodName",
  1815. $cell: true,
  1816. $type: "input",
  1817. type: "text",
  1818. value: "newMethodName",
  1819. onchange: function (e) {
  1820. let propValue = this.value;
  1821. try {
  1822. } catch (e) {
  1823. // restore the original value on error
  1824. }
  1825. }
  1826. }]
  1827. }
  1828. ]
  1829. },
  1830. {
  1831. $cell: true,
  1832. $type: "div",
  1833. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  1834. $components: [
  1835. {
  1836. class: "mdc-textfield params-textfield-input",
  1837. $cell: true,
  1838. $type: "div",
  1839. $components: [{
  1840. class: "mdc-textfield__input",
  1841. id: "methodParams",
  1842. $cell: true,
  1843. $type: "input",
  1844. type: "text",
  1845. value: JSON.stringify(this._method.parameters),
  1846. onchange: function (e) {
  1847. let propValue = this.value;
  1848. try {
  1849. } catch (e) {
  1850. // restore the original value on error
  1851. }
  1852. }
  1853. }]
  1854. }
  1855. ]
  1856. },
  1857. {
  1858. $cell: true,
  1859. $type: "div",
  1860. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1861. $components: [
  1862. {
  1863. $cell: true,
  1864. $type: "button",
  1865. class: "mdc-button mdc-button--raised",
  1866. $text: "Create",
  1867. onclick: function (e) {
  1868. let methodName = document.querySelector('#methodName').value;
  1869. //let methodParams = document.querySelector('#methodParams');
  1870. var params = [];
  1871. let body = '';
  1872. let paramsVal = document.querySelector("#methodParams").value;
  1873. if (paramsVal !== '') {
  1874. try {
  1875. params = JSON.parse(paramsVal);
  1876. //params.push(prmtr);
  1877. } catch (e) {
  1878. self.logger.error('Invalid Value');
  1879. }
  1880. }
  1881. self.kernel.createMethod(this._editorNode, methodName, params, body);
  1882. this._setNode(this._editorNode);
  1883. // let editor = document.querySelector("#aceEditor").env.editor;
  1884. // codeEditorDoit.call(self, editor, this._editorNode);
  1885. }
  1886. }
  1887. ]
  1888. }
  1889. ]
  1890. }
  1891. ]
  1892. //$components:
  1893. }
  1894. }
  1895. let propWindow = {
  1896. $cell: true,
  1897. $type: "div",
  1898. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1899. style: "overflow-y: scroll; max-height: 800px;",
  1900. $components: [
  1901. {
  1902. $type: "div",
  1903. class: "mdc-layout-grid__inner",
  1904. $components: [
  1905. {
  1906. $cell: true,
  1907. $type: "div",
  1908. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1909. $components: [
  1910. nodesCell
  1911. ]
  1912. }
  1913. ]
  1914. }
  1915. // <button class="mdc-button">
  1916. // Flat button
  1917. // </button>
  1918. ]
  1919. }
  1920. let clientListCell = {
  1921. $cell: true,
  1922. $type: "div",
  1923. class: "mdc-list",
  1924. id: "clientsList",
  1925. _watchNodes: [],
  1926. _listElement: function (m) {
  1927. return {
  1928. $type: "a",
  1929. class: "mdc-list-item",
  1930. $href: "#",
  1931. $text: m.name,
  1932. onclick: function (e) {
  1933. //self.currentNodeID = m.ID;
  1934. //document.querySelector('#currentNode')._setNode(m.ID);
  1935. }
  1936. }
  1937. },
  1938. $init: function () {
  1939. var t = this;
  1940. setInterval(function () {
  1941. t._updateMe();
  1942. }, 1000);
  1943. },
  1944. _updateMe: function () {
  1945. this._watchNodes = self.nodes["http://vwf.example.com/clients.vwf"].children.slice()
  1946. },
  1947. $update: function () {
  1948. //this._clientNodes
  1949. this.$components = this._watchNodes.map(this._listElement)
  1950. }
  1951. }
  1952. //createCellWindow("clientsWindow", clientListCell, "Clients");
  1953. //createCellWindow("propWindow", propWindow, "Scene");
  1954. createCellWindow("codeEditorWindow", codeEditorWindow, "Code editor");
  1955. createCellWindow("propEditorWindow", propEditorWindow, "Prop editor");
  1956. let viewSceneProps = {
  1957. $cell: true,
  1958. $type: "div",
  1959. class: "propGrid mdc-layout-grid mdc-layout-grid--align-left",
  1960. //style: "overflow-y: scroll; max-height: 500px; overflow-x: hidden;",
  1961. $components: [
  1962. {
  1963. $type: "div",
  1964. class: "mdc-layout-grid__inner",
  1965. $components: [
  1966. {
  1967. $cell: true,
  1968. $type: "div",
  1969. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1970. $components: [
  1971. nodesCell
  1972. ]
  1973. }
  1974. ]
  1975. }
  1976. ]
  1977. }
  1978. let sideBar = {
  1979. $cell: true,
  1980. $type: "div",
  1981. id: 'sideBar',
  1982. class: "sideBar mdc-toolbar-fixed-adjust",
  1983. _sideBarComponent: {},
  1984. _sideCurrentNode: '',
  1985. $init: function () {
  1986. this.style.visibility = 'hidden';
  1987. this._importScript("/" + self.getRoot() + "/appui.js");
  1988. },
  1989. _importScript: function (sSrc, fOnload) {
  1990. var oScript = document.createElement("script");
  1991. oScript.type = "text\/javascript";
  1992. oScript.async = false;
  1993. //oScript.onerror = loadError;
  1994. if (fOnload) { oScript.onload = fOnload; }
  1995. oScript.src = sSrc;
  1996. //let sideBar = document.querySelector('#sideBar');
  1997. this.appendChild(oScript);
  1998. },
  1999. _getAppDef: async function () {
  2000. let response = await fetch("/" + self.getRoot() + "/appui.js");
  2001. let data = await response.text();
  2002. //console.log(data)
  2003. return data
  2004. },
  2005. $update: function () {
  2006. this.$components = [
  2007. {
  2008. $cell: true,
  2009. $type: "button",
  2010. class: "mdc-button mdc-button--compact",
  2011. $text: "X",
  2012. onclick: function (e) {
  2013. document.querySelector('#sideBar').style.visibility = 'hidden';
  2014. }
  2015. },
  2016. this._sideBarComponent
  2017. ]
  2018. }
  2019. //$components: [this._sideComponents]
  2020. }
  2021. document.querySelector('#' + 'sideBar').$cell(sideBar)
  2022. let defaultApp = function () {
  2023. return {
  2024. $cell: true,
  2025. $type: "div",
  2026. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  2027. $components: [
  2028. {
  2029. $cell: true,
  2030. $type: "div",
  2031. class: "mdc-layout-grid__inner",
  2032. $components: [
  2033. {
  2034. $cell: true,
  2035. $type: "div",
  2036. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2037. $components: [
  2038. {
  2039. $cell: true,
  2040. $type: "h3",
  2041. class: "mdc-typography--headline",
  2042. $text: "Application",
  2043. }
  2044. ]
  2045. }
  2046. ]
  2047. }
  2048. ]
  2049. }
  2050. }
  2051. let drawerCell = {
  2052. $cell: true,
  2053. $type: "nav",
  2054. class: "mdc-temporary-drawer__drawer",
  2055. $components: [
  2056. {
  2057. $cell: true,
  2058. $type: "header",
  2059. class: "mdc-temporary-drawer__header",
  2060. $components: [
  2061. {
  2062. $cell: true,
  2063. $type: "div",
  2064. class: "mdc-temporary-drawer__header-content mdc-theme--primary-bg mdc-theme--text-primary-on-primary",
  2065. $text: "Home"
  2066. }
  2067. ]
  2068. },
  2069. {
  2070. $cell: true,
  2071. $type: "nav",
  2072. class: "mdc-temporary-drawer__content mdc-list-group",
  2073. $components: [
  2074. {
  2075. $cell: true,
  2076. $type: "div",
  2077. class: "mdc-list",
  2078. $components: [
  2079. {
  2080. $cell: true,
  2081. $type: "a",
  2082. class: "mdc-list-item",
  2083. $href: "#",
  2084. onclick: function (e) {
  2085. let sideBar = document.querySelector('#sideBar');
  2086. try {
  2087. sideBar._sideBarComponent = createApp.call(self);
  2088. } catch (e) {
  2089. sideBar._sideBarComponent = defaultApp();
  2090. }
  2091. drawer.open = !drawer.open
  2092. document.querySelector('#sideBar').style.visibility = 'visible';
  2093. },
  2094. $components: [{
  2095. $type: "i",
  2096. class: "material-icons mdc-list-item__start-detail",
  2097. 'aria-hidden': "true",
  2098. $text: "play_arrow"
  2099. },
  2100. {
  2101. $text: "App"
  2102. }]
  2103. },
  2104. {
  2105. $cell: true,
  2106. $type: "a",
  2107. class: "mdc-list-item",
  2108. $href: "#",
  2109. onclick: function (e) {
  2110. let sideBar = document.querySelector('#sideBar');
  2111. sideBar._sideBarComponent = viewSceneProps;
  2112. let currentNode = document.querySelector('#sideBar')._sideCurrentNode;
  2113. currentNode == '' ? document.querySelector('#sideBar')._sideCurrentNode = (vwf_view.kernel.find("", "/")[0]) :
  2114. document.querySelector('#sideBar')._sideCurrentNode = currentNode;
  2115. document.querySelector('#sideBar').style.visibility = 'visible';
  2116. drawer.open = !drawer.open
  2117. // let currentNode = document.querySelector('#currentNode')._currentNode;
  2118. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  2119. // document.querySelector('#currentNode')._setNode(currentNode);
  2120. },
  2121. $components: [{
  2122. $cell: true,
  2123. $type: "i",
  2124. class: "material-icons mdc-list-item__start-detail",
  2125. $text: "description"
  2126. },
  2127. {
  2128. $text: "Scene"
  2129. }
  2130. ]
  2131. },
  2132. {
  2133. $cell: true,
  2134. $type: "a",
  2135. class: "mdc-list-item",
  2136. $href: "#",
  2137. onclick: function (e) {
  2138. // var currentNode = document.querySelector('#currentNode')._currentNode;
  2139. // if (currentNode == '') {
  2140. // currentNode = vwf_view.kernel.find("", "/")[0];
  2141. // }
  2142. document.querySelector('#liveCodeEditor')._setNode(vwf_view.kernel.find("", "/")[0]);
  2143. //createAceEditor(self, currentNode);
  2144. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  2145. },
  2146. $components: [{
  2147. $type: "i",
  2148. class: "material-icons mdc-list-item__start-detail",
  2149. 'aria-hidden': "true",
  2150. $text: "code"
  2151. },
  2152. {
  2153. $text: "Code editor"
  2154. }]
  2155. },
  2156. {
  2157. $cell: true,
  2158. $type: "a",
  2159. class: "mdc-list-item",
  2160. $href: "#",
  2161. onclick: function (e) {
  2162. //self.currentNodeID = m.ID;
  2163. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2164. // document.querySelector('#clientsWindow').style.visibility = 'visible';
  2165. let sideBar = document.querySelector('#sideBar');
  2166. sideBar._sideBarComponent = avatarSettings;
  2167. drawer.open = !drawer.open
  2168. document.querySelector('#sideBar').style.visibility = 'visible';
  2169. },
  2170. $components: [{
  2171. $type: "i",
  2172. class: "material-icons mdc-list-item__start-detail",
  2173. 'aria-hidden': "true",
  2174. $text: "account_circle"
  2175. },
  2176. {
  2177. $text: "My Avatar"
  2178. }]
  2179. },
  2180. {
  2181. $cell: true,
  2182. $type: "a",
  2183. class: "mdc-list-item",
  2184. $href: "#",
  2185. onclick: function (e) {
  2186. //self.currentNodeID = m.ID;
  2187. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2188. let sideBar = document.querySelector('#sideBar');
  2189. sideBar._sideBarComponent = viewSettings;
  2190. drawer.open = !drawer.open
  2191. document.querySelector('#sideBar').style.visibility = 'visible';
  2192. },
  2193. $components: [{
  2194. $type: "i",
  2195. class: "material-icons mdc-list-item__start-detail",
  2196. 'aria-hidden': "true",
  2197. $text: "settings"
  2198. },
  2199. {
  2200. $text: "Settings"
  2201. }]
  2202. },
  2203. {
  2204. $cell: true,
  2205. $type: "a",
  2206. class: "mdc-list-item",
  2207. $href: "#",
  2208. onclick: function (e) {
  2209. //self.currentNodeID = m.ID;
  2210. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2211. let sideBar = document.querySelector('#sideBar');
  2212. sideBar._sideBarComponent = loadSaveSettings;
  2213. if (document.querySelector('#loadSaveSettings')) {
  2214. document.querySelector('#loadSaveSettings')._getStates();
  2215. }
  2216. //sideBar._sideBarComponent._getStates();
  2217. drawer.open = !drawer.open
  2218. document.querySelector('#sideBar').style.visibility = 'visible';
  2219. },
  2220. $components: [{
  2221. $type: "i",
  2222. class: "material-icons mdc-list-item__start-detail",
  2223. 'aria-hidden': "true",
  2224. $text: "save"
  2225. },
  2226. {
  2227. $text: "Load/Save"
  2228. }]
  2229. }
  2230. ]
  2231. },
  2232. widgets.divider,
  2233. widgets.headerH3("h3", "Users online", "userList mdc-list-group__subheader"),
  2234. clientListCell,
  2235. widgets.divider,
  2236. widgets.headerH3("h3", "WebRTC", "userList mdc-list-group__subheader"),
  2237. webrtcGUI
  2238. ]
  2239. }
  2240. // {
  2241. // $cell: true,
  2242. // $type: "div",
  2243. // class: "mdc-persistent-drawer__toolbar-spacer",
  2244. // },
  2245. // {
  2246. // $cell: true,
  2247. // $type: "div",
  2248. // class: "mdc-list-group",
  2249. // $components: [{
  2250. // $cell: true,
  2251. // $type: "nav",
  2252. // class: "mdc-list",
  2253. // $components: [
  2254. // ]
  2255. // }]
  2256. // }
  2257. ]
  2258. };
  2259. // <div class="mdc-form-field">
  2260. // <input type="checkbox" id="input">
  2261. // <label for="input">Input Label</label>
  2262. // </div>
  2263. document.querySelector("#drawer").$cell({
  2264. $cell: true,
  2265. $type: "aside",
  2266. class: "mdc-temporary-drawer",
  2267. $components: [drawerCell]
  2268. }
  2269. );
  2270. let toolbar = {
  2271. $cell: true,
  2272. $type: "div",
  2273. class: "mdc-toolbar__row",
  2274. $components: [{
  2275. $type: "section",
  2276. class: "mdc-toolbar__section mdc-toolbar__section--align-start",
  2277. $components: [
  2278. {
  2279. $type: "button",
  2280. class: "demo-menu material-icons mdc-toolbar__icon--menu",
  2281. $text: "menu"
  2282. },
  2283. {
  2284. $type: "span",
  2285. class: "mdc-toolbar__title catalog-title",
  2286. $text: "LiveCoding.space"
  2287. }
  2288. ]
  2289. }]
  2290. };
  2291. document.querySelector("#toolbar").$cell({
  2292. $cell: true,
  2293. $type: "div",
  2294. class: "mdc-toolbar mdc-toolbar--fixed",
  2295. $components: [toolbar]
  2296. }
  2297. );
  2298. // let drawer = new mdc.drawer.MDCTemporaryDrawer(document.querySelector('.mdc-temporary-drawer'));
  2299. // document.querySelector('.menu').addEventListener('click', () => drawer.open = true);
  2300. var drawerEl = document.querySelector('.mdc-temporary-drawer');
  2301. var MDCTemporaryDrawer = mdc.drawer.MDCTemporaryDrawer;
  2302. var drawer = new MDCTemporaryDrawer(drawerEl);
  2303. document.querySelector('.demo-menu').addEventListener('click', function () {
  2304. //self.currentNodeID = (self.currentNodeID == '') ? (vwf_view.kernel.find("", "/")[0]) : self.currentNodeID;
  2305. // let currentNode = document.querySelector('#currentNode')._currentNode;
  2306. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  2307. // document.querySelector('#currentNode')._setNode(currentNode);
  2308. //document.querySelector('#currentNode')._setNode(self.currentNodeID);
  2309. drawer.open = !drawer.open;
  2310. });
  2311. drawerEl.addEventListener('MDCTemporaryDrawer:open', function () {
  2312. //console.log('Received MDCPersistentDrawer:open');
  2313. });
  2314. drawerEl.addEventListener('MDCTemporaryDrawer:close', function () {
  2315. //console.log('Received MDCPersistentDrawer:close');
  2316. });
  2317. //==============
  2318. },
  2319. createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  2320. childSource, childType, childIndex, childName, callback /* ( ready ) */) {
  2321. var nodeIDAttribute = $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  2322. var childIDAttribute = $.encoder.encodeForHTMLAttribute("id", childID, true);
  2323. var childIDAlpha = $.encoder.encodeForAlphaNumeric(childID);
  2324. var kernel = this.kernel;
  2325. var self = this;
  2326. var parent = this.nodes[nodeID];
  2327. var node = this.nodes[childID] = {
  2328. children: [],
  2329. properties: [],
  2330. events: {},
  2331. methods: {},
  2332. parent: parent,
  2333. parentID: nodeID,
  2334. ID: childID,
  2335. extendsID: childExtendsID,
  2336. implementsIDs: childImplementsIDs,
  2337. source: childSource,
  2338. name: childName,
  2339. };
  2340. if (parent) {
  2341. parent.children.push(node);
  2342. }
  2343. if (childID == vwf_view.kernel.find("", "/")[0] && childExtendsID && this.kernel.test(childExtendsID,
  2344. "self::element(*,'http://vwf.example.com/aframe/ascene.vwf')", childExtendsID)) {
  2345. this.scenes[childID] = node;
  2346. }
  2347. let nodeCell = document.querySelector("#currentNode");
  2348. if (nodeCell !== null) {
  2349. if (nodeCell._currentNode === nodeID) {
  2350. nodeCell._getChildNodes();
  2351. }
  2352. }
  2353. if (nodeID === this.kernel.application()) {
  2354. // document.querySelector('a-scene').classList.add("mdc-toolbar-fixed-adjust");
  2355. document.querySelector('body').classList.add("editor-body");
  2356. }
  2357. },
  2358. createdProperty: function (nodeID, propertyName, propertyValue) {
  2359. return this.initializedProperty(nodeID, propertyName, propertyValue);
  2360. },
  2361. initializedProperty: function (nodeID, propertyName, propertyValue) {
  2362. var node = this.nodes[nodeID];
  2363. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2364. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  2365. node.properties.push(property);
  2366. },
  2367. deletedNode: function (nodeID) {
  2368. var node = this.nodes[nodeID];
  2369. node.parent.children.splice(node.parent.children.indexOf(node), 1);
  2370. delete this.nodes[nodeID];
  2371. let nodeCell = document.querySelector("#currentNode");
  2372. if (nodeCell) {
  2373. if (nodeCell._currentNode !== "") {
  2374. if (nodeCell._currentNode !== nodeID) {
  2375. //&& (this.nodes[nodeID] !== undefined)
  2376. nodeCell._getChildNodes();
  2377. } else {
  2378. nodeCell._setNode(vwf_view.kernel.find("", "/")[0]);
  2379. nodeCell._getChildNodes();
  2380. }
  2381. }
  2382. }
  2383. },
  2384. //addedChild: [ /* nodeID, childID, childName */ ],
  2385. //removedChild: [ /* nodeID, childID */ ],
  2386. satProperty: function (nodeID, propertyName, propertyValue) {
  2387. var node = this.nodes[nodeID];
  2388. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2389. // It is possible for a property to have satProperty called for it without ever getting an
  2390. // initializedProperty (if that property delegated to itself or another on replication)
  2391. // Catch that case here and create the property
  2392. if (!node.properties[propertyName]) {
  2393. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  2394. node.properties.push(property);
  2395. }
  2396. try {
  2397. propertyValue = utility.transform(propertyValue, utility.transforms.transit);
  2398. node.properties[propertyName].value = JSON.stringify(propertyValue);
  2399. node.properties[propertyName].rawValue = propertyValue;
  2400. } catch (e) {
  2401. this.logger.warnx("satProperty", nodeID, propertyName, propertyValue,
  2402. "stringify error:", e.message);
  2403. node.properties[propertyName].value = propertyValue;
  2404. }
  2405. let nodeCell = document.querySelector('#currentNode');
  2406. if (nodeCell !== null) {
  2407. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  2408. console.log('EDIT !!!')
  2409. }
  2410. }
  2411. let propCell = document.querySelector("#currentNode #prop-" + propertyName);
  2412. if (propCell !== null) {
  2413. if (propCell._currentNode == nodeID) {
  2414. propCell.value = node.properties[propertyName].getValue();
  2415. }
  2416. }
  2417. },
  2418. //gotProperty: [ /* nodeID, propertyName, propertyValue */ ],
  2419. gotProperty: function (nodeID, propertyName, propertyValue) {
  2420. var node = this.nodes[nodeID];
  2421. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2422. let nodeCell = document.querySelector('#currentNode');
  2423. if (nodeCell !== null) {
  2424. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  2425. let editCheckBox = document.querySelector("#currentNode #editnode");
  2426. if (editCheckBox) {
  2427. if (propertyValue) {
  2428. editCheckBox.setAttribute('checked', '');
  2429. } else {
  2430. let checkAttr = editCheckBox.getAttribute('checked');
  2431. if (checkAttr) editCheckBox.removeAttribute('checked');
  2432. }
  2433. }
  2434. console.log('EDIT !!! is ' + propertyValue)
  2435. }
  2436. }
  2437. },
  2438. createdMethod: function (nodeID, methodName, methodParameters, methodBody) {
  2439. var node = this.nodes[nodeID];
  2440. if (node) {
  2441. node.methods[methodName] = methodParameters;
  2442. }
  2443. },
  2444. //calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {
  2445. //},
  2446. createdEvent: function (nodeID, eventName, eventParameters) {
  2447. var node = this.nodes[nodeID];
  2448. if (node) {
  2449. node.events[eventName] = eventParameters;
  2450. }
  2451. },
  2452. firedEvent: function (nodeID, eventName, eventParameters) {
  2453. },
  2454. executed: function (nodeID, scriptText, scriptType) {
  2455. // var nodeScript = {
  2456. // text: scriptText,
  2457. // type: scriptType,
  2458. // };
  2459. // if ( !this.allScripts[ nodeID ] ) {
  2460. // var nodeScripts = new Array();
  2461. // nodeScripts.push(nodeScript);
  2462. // this.allScripts[ nodeID ] = nodeScripts;
  2463. // }
  2464. // else {
  2465. // this.allScripts[ nodeID ].push(nodeScript);
  2466. // }
  2467. },
  2468. //ticked: [ /* time */ ],
  2469. });
  2470. function createCellWindow(elementID, cellNode, title) {
  2471. document.querySelector('#' + elementID).$cell({
  2472. $cell: true,
  2473. $type: "div",
  2474. id: elementID,
  2475. class: 'draggable',
  2476. $init: function () {
  2477. // let draggie = new Draggabilly('.draggable', {
  2478. // handle: '.handle',
  2479. // containment: true
  2480. // });
  2481. // get all draggie elements
  2482. var draggableElems = document.querySelectorAll('.draggable');
  2483. // array of Draggabillies
  2484. var draggies = []
  2485. // init Draggabillies
  2486. for (var i = 0, len = draggableElems.length; i < len; i++) {
  2487. var draggableElem = draggableElems[i];
  2488. var draggie = new Draggabilly(draggableElem, {
  2489. handle: '.handle',
  2490. containment: true
  2491. });
  2492. draggies.push(draggie);
  2493. }
  2494. this.style.visibility = 'hidden';
  2495. },
  2496. $components: [
  2497. {
  2498. $cell: true,
  2499. $type: "div",
  2500. class: "handle",
  2501. $components: [
  2502. {
  2503. $cell: true,
  2504. $type: "button",
  2505. class: "mdc-button mdc-button--compact",
  2506. $text: "X",
  2507. onclick: function (e) {
  2508. //self.currentNodeID = m.ID;
  2509. document.querySelector('#' + elementID).style.visibility = 'hidden';
  2510. }
  2511. },
  2512. {
  2513. $cell: true,
  2514. $type: "span",
  2515. class: "mdc-typography--button",
  2516. $text: title
  2517. }
  2518. ]
  2519. },
  2520. cellNode,
  2521. {
  2522. $cell: true,
  2523. $type: "div",
  2524. class: "handle",
  2525. style: "height: 10px; width: inherit;",
  2526. //$text: "sdfsdf"
  2527. }
  2528. // { $text: "23423"}
  2529. ]
  2530. }
  2531. );
  2532. }
  2533. // -- getChildByName --------------------------------------------------------------------
  2534. function getChildByName(node, childName) {
  2535. var childNode = undefined;
  2536. for (var i = 0; i < node.children.length && childNode === undefined; i++) {
  2537. if (node.children[i].name == childName) {
  2538. childNode = node.children[i];
  2539. }
  2540. }
  2541. return childNode;
  2542. };
  2543. // -- viewScript ------------------------------------------------------------------------
  2544. function createAceEditor(view, nodeID, elID) {
  2545. var editor = view.ace.edit(elID);
  2546. editor.setTheme("ace/theme/monokai");
  2547. editor.setFontSize(16);
  2548. editor.getSession().setMode("ace/mode/javascript");
  2549. editor.commands.addCommand({
  2550. name: "doit",
  2551. bindKey: { win: "Ctrl-e", mac: "Command-e" },
  2552. exec: function () {
  2553. codeEditorDoit(editor, nodeID);
  2554. }
  2555. });
  2556. editor.commands.addCommand({
  2557. name: "printit",
  2558. bindKey: { win: "Ctrl-b", mac: "Command-b" },
  2559. exec: function () {
  2560. codeEditorPrintit(editor, nodeID);
  2561. }
  2562. });
  2563. return editor;
  2564. }
  2565. function getPrototypes(kernel, extendsID) {
  2566. var prototypes = [];
  2567. var id = extendsID;
  2568. while (id !== undefined) {
  2569. prototypes.push(id);
  2570. id = kernel.prototype(id);
  2571. }
  2572. return prototypes;
  2573. }
  2574. function getPrototypes(kernel, extendsID) {
  2575. var prototypes = [];
  2576. var id = extendsID;
  2577. while (id !== undefined) {
  2578. prototypes.push(id);
  2579. id = kernel.prototype(id);
  2580. }
  2581. return prototypes;
  2582. }
  2583. function createProperty(node, propertyName, propertyValue) {
  2584. var property = {
  2585. name: propertyName,
  2586. rawValue: propertyValue,
  2587. value: undefined,
  2588. getValue: function () {
  2589. var propertyValue;
  2590. if (this.value == undefined) {
  2591. try {
  2592. propertyValue = utility.transform(this.rawValue, utility.transforms.transit);
  2593. this.value = JSON.stringify(propertyValue);
  2594. } catch (e) {
  2595. this.logger.warnx("createdProperty", nodeID, this.propertyName, this.rawValue,
  2596. "stringify error:", e.message);
  2597. this.value = this.rawValue;
  2598. }
  2599. }
  2600. return this.value;
  2601. }
  2602. };
  2603. return property;
  2604. }
  2605. function getProperties(kernel, extendsID) {
  2606. var pTypes = getPrototypes(kernel, extendsID);
  2607. var pProperties = {};
  2608. if (pTypes) {
  2609. for (var i = 0; i < pTypes.length; i++) {
  2610. var nd = this.nodes[pTypes[i]];
  2611. if (nd && nd.properties) {
  2612. for (var key in nd.properties) {
  2613. pProperties[key] = { "prop": nd.properties[key], "prototype": pTypes[i] };
  2614. }
  2615. }
  2616. }
  2617. }
  2618. return pProperties;
  2619. }
  2620. function getChildren(kernel, extendsID) {
  2621. var pTypes = getPrototypes(kernel, extendsID);
  2622. var pChildren = {};
  2623. if (pTypes) {
  2624. for (var i = 0; i < pTypes.length; i++) {
  2625. var nd = this.nodes[pTypes[i]];
  2626. if (nd && nd.children) {
  2627. for (var key in nd.children) {
  2628. pChildren[key] = nd.children[key];
  2629. }
  2630. }
  2631. }
  2632. }
  2633. return pChildren;
  2634. }
  2635. function getEvents(kernel, extendsID) {
  2636. var pTypes = getPrototypes(kernel, extendsID);
  2637. var events = {};
  2638. if (pTypes) {
  2639. for (var i = 0; i < pTypes.length; i++) {
  2640. var nd = this.nodes[pTypes[i]];
  2641. if (nd && nd.events) {
  2642. for (var key in nd.events) {
  2643. events[key] = nd.events[key];
  2644. }
  2645. }
  2646. }
  2647. }
  2648. return events;
  2649. }
  2650. function getMethods(kernel, extendsID) {
  2651. var pTypes = getPrototypes(kernel, extendsID);
  2652. var methods = {};
  2653. if (pTypes) {
  2654. for (var i = 0; i < pTypes.length; i++) {
  2655. var nd = this.nodes[pTypes[i]];
  2656. if (nd && nd.methods) {
  2657. for (var key in nd.methods) {
  2658. methods[key] = nd.methods[key];
  2659. }
  2660. }
  2661. }
  2662. }
  2663. return methods;
  2664. }
  2665. // -- Show Code Editor tab
  2666. function codeEditorDoit(editor, nodeID) {
  2667. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  2668. if (selectedText == "") {
  2669. var currline = editor.getSelectionRange().start.row;
  2670. var selectedText = editor.session.getLine(currline);
  2671. }
  2672. //console.log(selectedText);
  2673. //var sceneID = self.kernel.application();
  2674. vwf_view.kernel.execute(nodeID, selectedText);
  2675. }
  2676. function codeEditorPrintit(editor, nodeID) {
  2677. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  2678. if (selectedText == "") {
  2679. var currline = editor.getSelectionRange().start.row;
  2680. var selectedText = editor.session.getLine(currline);
  2681. }
  2682. //console.log(selectedText);
  2683. //var sceneID = self.kernel.application();
  2684. let scriptText = 'console.log(' + selectedText + ');'
  2685. self.kernel.execute(nodeID, scriptText);
  2686. }
  2687. function saveStateAsFile(filename) // invoke with the view as "this"
  2688. {
  2689. this.logger.info("Saving: " + filename);
  2690. var clients = this.nodes["http://vwf.example.com/clients.vwf"];
  2691. if (supportAjaxUploadWithProgress.call(this)) {
  2692. var xhr = new XMLHttpRequest();
  2693. // Save State Information
  2694. var state = vwf.getState();
  2695. state.nodes[0].children = {};
  2696. var timestamp = state["queue"].time;
  2697. timestamp = Math.round(timestamp * 1000);
  2698. var objectIsTypedArray = function (candidate) {
  2699. var typedArrayTypes = [
  2700. Int8Array,
  2701. Uint8Array,
  2702. // Uint8ClampedArray,
  2703. Int16Array,
  2704. Uint16Array,
  2705. Int32Array,
  2706. Uint32Array,
  2707. Float32Array,
  2708. Float64Array
  2709. ];
  2710. var isTypedArray = false;
  2711. if (typeof candidate == "object" && candidate != null) {
  2712. typedArrayTypes.forEach(function (typedArrayType) {
  2713. isTypedArray = isTypedArray || candidate instanceof typedArrayType;
  2714. });
  2715. }
  2716. return isTypedArray;
  2717. };
  2718. var transitTransformation = function (object) {
  2719. return objectIsTypedArray(object) ?
  2720. Array.prototype.slice.call(object) : object;
  2721. };
  2722. var json = JSON.stringify(
  2723. require("vwf/utility").transform(
  2724. state, transitTransformation
  2725. )
  2726. );
  2727. json = $.encoder.encodeForURL(json);
  2728. var path = window.location.pathname;
  2729. var pathSplit = path.split('/');
  2730. if (pathSplit[0] == "") {
  2731. pathSplit.shift();
  2732. }
  2733. if (pathSplit[pathSplit.length - 1] == "") {
  2734. pathSplit.pop();
  2735. }
  2736. var inst = undefined;
  2737. var instIndex = pathSplit.length - 1;
  2738. if (pathSplit.length > 2) {
  2739. if (pathSplit[pathSplit.length - 2] == "load") {
  2740. instIndex = pathSplit.length - 3;
  2741. }
  2742. }
  2743. if (pathSplit.length > 3) {
  2744. if (pathSplit[pathSplit.length - 3] == "load") {
  2745. instIndex = pathSplit.length - 4;
  2746. }
  2747. }
  2748. inst = pathSplit[instIndex];
  2749. var root = "";
  2750. for (var i = 0; i < instIndex; i++) {
  2751. if (root != "") {
  2752. root = root + "/";
  2753. }
  2754. root = root + pathSplit[i];
  2755. }
  2756. if (filename == '') filename = inst;
  2757. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  2758. xhr.open("POST", "/" + root + "/save/" + filename, true);
  2759. xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  2760. xhr.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.json" + "&jsonState=" + json);
  2761. // Save Config Information
  2762. var config = { "info": {}, "model": {}, "view": {} };
  2763. // Save browser title
  2764. config["info"]["title"] = document.title//$('title').html();
  2765. // Save model drivers
  2766. Object.keys(vwf_view.kernel.kernel.models).forEach(function (modelDriver) {
  2767. if (modelDriver.indexOf('vwf/model/') != -1) config["model"][modelDriver] = "";
  2768. });
  2769. // If neither glge or threejs model drivers are defined, specify nodriver
  2770. if (config["model"]["vwf/model/glge"] === undefined && config["model"]["vwf/model/threejs"] === undefined) config["model"]["nodriver"] = "";
  2771. // Save view drivers and associated parameters, if any
  2772. Object.keys(vwf_view.kernel.kernel.views).forEach(function (viewDriver) {
  2773. if (viewDriver.indexOf('vwf/view/') != -1) {
  2774. if (vwf_view.kernel.kernel.views[viewDriver].parameters) {
  2775. config["view"][viewDriver] = vwf_view.kernel.kernel.views[viewDriver].parameters;
  2776. }
  2777. else config["view"][viewDriver] = "";
  2778. }
  2779. });
  2780. var jsonConfig = $.encoder.encodeForURL(JSON.stringify(config));
  2781. // Save config file to server
  2782. var xhrConfig = new XMLHttpRequest();
  2783. xhrConfig.open("POST", "/" + root + "/save/" + filename, true);
  2784. xhrConfig.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  2785. xhrConfig.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.config.json" + "&jsonState=" + jsonConfig);
  2786. }
  2787. else {
  2788. console.error("Unable to save state.");
  2789. }
  2790. }
  2791. // -- LoadSavedState --------------------------------------------------------------------------
  2792. function loadSavedState(filename, applicationpath, revision) {
  2793. this.logger.info("Loading: " + filename);
  2794. // Redirect until setState ID conflict is resolved
  2795. var path = window.location.pathname;
  2796. var inst = path.substring(path.length - 17, path.length - 1);
  2797. var pathSplit = path.split('/');
  2798. if (pathSplit[0] == "") {
  2799. pathSplit.shift();
  2800. }
  2801. if (pathSplit[pathSplit.length - 1] == "") {
  2802. pathSplit.pop();
  2803. }
  2804. var inst = undefined;
  2805. var instIndex = pathSplit.length - 1;
  2806. if (pathSplit.length > 2) {
  2807. if (pathSplit[pathSplit.length - 2] == "load") {
  2808. instIndex = pathSplit.length - 3;
  2809. }
  2810. }
  2811. if (pathSplit.length > 3) {
  2812. if (pathSplit[pathSplit.length - 3] == "load") {
  2813. instIndex = pathSplit.length - 4;
  2814. }
  2815. }
  2816. inst = pathSplit[instIndex];
  2817. if (revision) {
  2818. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/' + revision + '/';
  2819. }
  2820. else {
  2821. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/';
  2822. }
  2823. // $.get(filename,function(data,status){
  2824. // vwf.setState(data);
  2825. // });
  2826. }
  2827. // -- SupportAjax -----------------------------------------------------------------------------
  2828. function supportAjaxUploadWithProgress() {
  2829. return supportAjaxUploadProgressEvents();
  2830. function supportAjaxUploadProgressEvents() {
  2831. var xhr = new XMLHttpRequest();
  2832. return !!(xhr && ('upload' in xhr) && ('onprogress' in xhr.upload));
  2833. }
  2834. }
  2835. });