editor-new.js 159 KB

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