editor.js 225 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692
  1. /*
  2. The MIT License (MIT)
  3. Copyright (c) 2014-2020 Nikolai Suslov and the Krestianstvo.org project contributors. (https://github.com/NikolaySuslov/livecodingspace/blob/master/LICENSE.md)
  4. Virtual World Framework Apache 2.0 license (https://github.com/NikolaySuslov/livecodingspace/blob/master/licenses/LICENSE_VWF.md)
  5. */
  6. //
  7. /// vwf/view/editor creates a view interface for editor functions.
  8. ///
  9. /// @module vwf/view/editor
  10. /// @requires version
  11. /// @requires vwf/view
  12. /// @requires vwf/utility
  13. import { Widgets } from '/lib/ui/widgets.js';
  14. import { Utility } from '/core/vwf/utility/utility.js';
  15. import { Fabric } from '/core/vwf/fabric.js';
  16. class LCSEditor extends Fabric {
  17. constructor(module) {
  18. console.log("Editor constructor");
  19. super(module, 'View');
  20. this.widgets = new Widgets;
  21. }
  22. factory(){
  23. let _self_ = this;
  24. return this.load( this.module,
  25. {
  26. // == Module Definition ====================================================================
  27. initialize: function () {
  28. let self = this;
  29. this.ace = window.ace;
  30. this.widgets = _self_.widgets; //widgets;
  31. this.lang = _LangManager.language;
  32. this.helpers = _self_.helpers;
  33. this.nodes = {};
  34. this.scenes = {};
  35. this.allScripts = {};
  36. document.querySelector('body').classList.add("editor-body", "mdc-typography");
  37. document.querySelector('body').innerHTML +=
  38. `<div id="ui-controls" class="guiwindow">
  39. <button id="hideui"
  40. class="mdc-icon-button"
  41. role="button" aria-pressed="true">
  42. <i class="material-icons mdc-icon-button__icon mdc-icon-button__icon--on">grid_off</i>
  43. <i class="material-icons mdc-icon-button__icon">grid_on</i>
  44. </button>
  45. <button id="fullscreenui"
  46. class="mdc-icon-button"
  47. role="button" aria-pressed="true">
  48. <i class="material-icons mdc-icon-button__icon mdc-icon-button__icon--on">fullscreen_exit</i>
  49. <i class="material-icons mdc-icon-button__icon">fullscreen</i>
  50. </button>
  51. <!-- <button id="qrcodeui"
  52. class="mdc-icon-button"
  53. role="button" aria-pressed="true">
  54. <i class="material-icons mdc-icon-button__icon mdc-icon-button__icon--on">qr_code_2</i>
  55. <i class="material-icons mdc-icon-button__icon">qr_code_2</i>
  56. </button> -->
  57. </div>
  58. `
  59. function initOverGUI() {
  60. // window.addEventListener("load", function (event) {
  61. // console.log("All resources finished loading!");
  62. const iconEl = document.querySelector('#hideui');
  63. const compHideUI = new mdc.iconButton.MDCIconButtonToggle(iconEl);
  64. compHideUI.listen('MDCIconButtonToggle:change', (e) => {
  65. let ui = document.querySelector('.mdc-top-app-bar');
  66. if (ui) {
  67. let chkAttr = ui.style.visibility; //e.detail.isOn;
  68. if (chkAttr == 'hidden') {
  69. ui.style.visibility = 'visible'
  70. } else {
  71. ui.style.visibility = 'hidden'
  72. }
  73. }
  74. });
  75. const fullScreenToggle = document.querySelector('#fullscreenui');
  76. const compfullScreen = new mdc.iconButton.MDCIconButtonToggle(fullScreenToggle);
  77. fullScreenToggle.addEventListener('MDCIconButtonToggle:change', (e) => {
  78. if (screenfull.enabled) {
  79. screenfull.toggle();
  80. } else {
  81. // Ignore or do something else
  82. }
  83. });
  84. // const qrEl = document.querySelector('#qrcodeui');
  85. // const compQrUI = new mdc.iconButton.MDCIconButtonToggle(qrEl);
  86. // compQrUI.listen('MDCIconButtonToggle:change', (e) => {
  87. // if(self.qrcodedialog){
  88. // self.qrcodedialog.open();
  89. // }
  90. // });
  91. }
  92. window.getWorldLink = function() {
  93. navigator.clipboard.writeText(window.location.href).then(function() {
  94. /* clipboard successfully set */
  95. console.log("Got Link successfully!")
  96. }, function() {
  97. console.log("Got Link failed!")
  98. /* clipboard write failed */
  99. });
  100. }
  101. function makeQRCode() {
  102. document.querySelector('body').innerHTML += `
  103. <div class="mdc-dialog" id="qrcodedialog">
  104. <div class="mdc-dialog__container">
  105. <div class="mdc-dialog__surface"
  106. role="alertdialog"
  107. aria-modal="true"
  108. aria-labelledby="my-dialog-title"
  109. aria-describedby="my-dialog-content">
  110. <!-- Title cannot contain leading whitespace due to mdc-typography-baseline-top() -->
  111. <h2 class="mdc-dialog__title" id="my-dialog-title">QR Code for this World</h2>
  112. <div class="mdc-dialog__content" id="my-dialog-content">
  113. <div id="qrcode"></div>
  114. </div>
  115. <div class="mdc-dialog__actions">
  116. <button type="button" class="mdc-button mdc-dialog__button" data-mdc-dialog-action="accept"
  117. onclick="getWorldLink()">
  118. <div class="mdc-button__ripple"></div>
  119. <span class="mdc-button__label">Copy link</span>
  120. </button>
  121. <button type="button" class="mdc-button mdc-dialog__button" data-mdc-dialog-action="accept">
  122. <div class="mdc-button__ripple"></div>
  123. <span class="mdc-button__label">OK</span>
  124. </button>
  125. </div>
  126. </div>
  127. </div>
  128. <div class="mdc-dialog__scrim"></div>
  129. </div>
  130. `
  131. self.qrcode = new QRCode(document.getElementById("qrcode"), window.location.href);
  132. self.qrcodedialog = new mdc.dialog.MDCDialog(document.getElementById('qrcodedialog'));
  133. }
  134. mdc.autoInit();
  135. // $('body').append('<script>mdc.autoInit()</script>');
  136. ["drawer", "toolbar", "sideBar", "propWindow", "clientsWindow", "codeEditorWindow", "propEditorWindow", "viewSceneProps"].forEach(item => {
  137. let el = document.createElement("div");
  138. el.setAttribute("id", item);
  139. document.body.appendChild(el);
  140. }
  141. );
  142. makeQRCode();
  143. initOverGUI();
  144. _LCSDB.on('auth', function (ack) {
  145. if (ack.sea.pub) {
  146. self.helpers.checkUserCollision();
  147. console.log(_LCSDB.user().is);
  148. let loadSave = document.querySelector('#loadSaveSettings');
  149. if(loadSave){
  150. }
  151. //self.authGUI();
  152. }
  153. });
  154. this.avatarCardDef = function (src, desc, onclickfunc) {
  155. return {
  156. $cell: true,
  157. $type: "div",
  158. class: "mdc-card avatar-card",
  159. $init: function () {
  160. this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.0) ), url(' + src + ')'
  161. },
  162. onclick: onclickfunc,
  163. $components: [
  164. {
  165. $type: "section",
  166. class: "mdc-card__primary",
  167. style: "padding: 1rem;",
  168. $components: [
  169. {
  170. $type: "h1",
  171. class: "mdc-card__title mdc-typography--title",
  172. $text: desc.subtitle
  173. },
  174. {
  175. $type: "h2",
  176. class: "mdc-typography--subheading1",
  177. $text: desc.title
  178. }
  179. ]
  180. },
  181. {
  182. $type: "section",
  183. class: "mdc-card__actions",
  184. $components: [
  185. {
  186. $type: "button",
  187. class: "mdc-button mdc-button--compact mdc-card__action",
  188. //$text: "Use it",
  189. onclick: onclickfunc
  190. }
  191. ]
  192. }
  193. ]
  194. }
  195. }
  196. let createSettings =
  197. {
  198. $cell: true,
  199. $type: "div",
  200. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  201. $components: [
  202. self.widgets.listTitle({text: 'Primitives'}),
  203. {
  204. $type: "div",
  205. class: "mdc-layout-grid__inner",
  206. $components: make3DPrimitiveList()
  207. },
  208. self.widgets.listTitle({text: 'Lights'}),
  209. {
  210. $type: "div",
  211. class: "mdc-layout-grid__inner",
  212. $components: makeLightsList()
  213. },
  214. self.widgets.listTitle({text: 'Objects'}),
  215. {
  216. $type: "div",
  217. class: "mdc-layout-grid__inner",
  218. $components: [
  219. self.widgets.gridListItem({
  220. imgSrc: "/drivers/view/editor/images/ui/icons/camera.png",
  221. title: 'Camera',
  222. imgSize: '30px',
  223. styleClass: "",
  224. onclickfunc: function () {
  225. let avatarID = 'avatar-' + vwf.moniker_;
  226. //let cubeName = self.GUID();
  227. vwf_view.kernel.callMethod(vwf.application(), "createCamera", [null, null, avatarID])
  228. //let cubeName = self.GUID();
  229. // vwf_view.kernel.callMethod(vwf.application(), "createFloor")
  230. }
  231. }),
  232. self.widgets.gridListItem({
  233. imgSrc: "/drivers/view/editor/images/ui/icons/camera_offset.png",
  234. title: 'Camera with view offset',
  235. imgSize: '30px',
  236. styleClass: "",
  237. onclickfunc: function () {
  238. let avatarID = 'avatar-' + vwf.moniker_;
  239. //let cubeName = self.GUID();
  240. vwf_view.kernel.callMethod(vwf.application(), "createCameraWithOffset", [null, null, avatarID])
  241. //let cubeName = self.GUID();
  242. // vwf_view.kernel.callMethod(vwf.application(), "createFloor")
  243. }
  244. }),
  245. self.widgets.gridListItem({
  246. imgSrc: "/drivers/view/editor/images/ui/icons/mirror.png",
  247. title: 'Mirror',
  248. imgSize: '30px',
  249. styleClass: "",
  250. onclickfunc: function () {
  251. let avatarID = 'avatar-' + vwf.moniker_;
  252. //let cubeName = self.GUID();
  253. vwf_view.kernel.callMethod(vwf.application(), "createMirror", [null, null, avatarID])
  254. //let cubeName = self.GUID();
  255. // vwf_view.kernel.callMethod(vwf.application(), "createFloor")
  256. }
  257. }),
  258. ]
  259. },
  260. self.widgets.listTitle({text: 'Assets'}),
  261. {
  262. $type: "div",
  263. class: "mdc-layout-grid__inner",
  264. $components: [
  265. {
  266. $type: "div",
  267. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  268. $components: [
  269. self.widgets.inputTextFieldOutlined({
  270. "id": 'assetsrc',
  271. "fieldStyle": 'width: 350px',
  272. "label": "Enter URL to asset source",
  273. "value": '',
  274. "change": function (e) {
  275. console.log(this.value)
  276. }
  277. })
  278. ]
  279. }
  280. ]
  281. },
  282. {
  283. $type: "div",
  284. class: "mdc-layout-grid__inner",
  285. $components: [
  286. {
  287. $type: "div",
  288. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  289. $components: [
  290. self.widgets.buttonSimple(
  291. {
  292. label: "Image",
  293. onclick: function (e) {
  294. let srcEl = document.querySelector('#assetsrc');
  295. let avatarID = 'avatar-' + vwf.moniker_;
  296. vwf_view.kernel.callMethod(vwf.application(), "createImage", [srcEl.value, null, null, avatarID])
  297. }
  298. }
  299. ),
  300. self.widgets.buttonSimple(
  301. {
  302. label: "Sound",
  303. onclick: function (e) {
  304. let srcEl = document.querySelector('#assetsrc');
  305. let avatarID = 'avatar-' + vwf.moniker_;
  306. vwf_view.kernel.callMethod(vwf.application(), "createAudio", [srcEl.value, null, null, avatarID])
  307. }
  308. }
  309. ),
  310. self.widgets.buttonSimple(
  311. {
  312. label: "Video",
  313. onclick: function (e) {
  314. let srcEl = document.querySelector('#assetsrc');
  315. let avatarID = 'avatar-' + vwf.moniker_;
  316. vwf_view.kernel.callMethod(vwf.application(), "createVideo", [srcEl.value, null, null, avatarID])
  317. }
  318. }
  319. ),
  320. self.widgets.buttonSimple(
  321. {
  322. label: "GLTF",
  323. onclick: function (e) {
  324. let srcEl = document.querySelector('#assetsrc');
  325. let avatarID = 'avatar-' + vwf.moniker_;
  326. if (srcEl.value.includes('.gltf'))
  327. vwf_view.kernel.callMethod(vwf.application(), "createModel", ['GLTF', srcEl.value, avatarID])
  328. }
  329. }
  330. ),
  331. self.widgets.buttonSimple(
  332. {
  333. label: "DAE",
  334. onclick: function (e) {
  335. let srcEl = document.querySelector('#assetsrc');
  336. let avatarID = 'avatar-' + vwf.moniker_;
  337. if (srcEl.value.includes('.dae'))
  338. vwf_view.kernel.callMethod(vwf.application(), "createModel", ['DAE', srcEl.value, avatarID])
  339. }
  340. }
  341. ),
  342. self.widgets.buttonSimple(
  343. {
  344. label: "OBJ",
  345. onclick: function (e) {
  346. let srcEl = document.querySelector('#assetsrc');
  347. let avatarID = 'avatar-' + vwf.moniker_;
  348. if (srcEl.value.includes('.obj'))
  349. vwf_view.kernel.callMethod(vwf.application(), "createModel", ['OBJ', srcEl.value, avatarID])
  350. }
  351. }
  352. )
  353. ]
  354. }
  355. ]
  356. },
  357. self.widgets.listTitle({text: 'Resources'}),
  358. {
  359. $type: "div",
  360. class: "mdc-layout-grid__inner",
  361. $components: [
  362. self.widgets.gridListItem({
  363. imgSrc: "/drivers/view/editor/images/ui/icons/3ditem.png",
  364. title: 'Asset item',
  365. imgSize: '30px',
  366. styleClass: "",
  367. onclickfunc: function () {
  368. let srcEl = document.querySelector('#assetsrc');
  369. vwf_view.kernel.callMethod(vwf.application(), "createAssetResource", ['ITEM', srcEl.value])
  370. }
  371. }),
  372. self.widgets.gridListItem({
  373. imgSrc: "/drivers/view/editor/images/ui/icons/image.png",
  374. title: 'Image',
  375. imgSize: '30px',
  376. styleClass: "",
  377. onclickfunc: function () {
  378. //let cubeName = self.GUID();
  379. let srcEl = document.querySelector('#assetsrc');
  380. vwf_view.kernel.callMethod(vwf.application(), "createAssetResource", ['IMG', srcEl.value])
  381. }
  382. }),
  383. self.widgets.gridListItem({
  384. imgSrc: "/drivers/view/editor/images/ui/icons/video.png",
  385. title: 'Video',
  386. imgSize: '30px',
  387. styleClass: "",
  388. onclickfunc: function () {
  389. let srcEl = document.querySelector('#assetsrc');
  390. vwf_view.kernel.callMethod(vwf.application(), "createAssetResource", ['VIDEO', srcEl.value])
  391. }
  392. }),
  393. self.widgets.gridListItem({
  394. imgSrc: "/drivers/view/editor/images/ui/icons/sound.png",
  395. title: 'Sound',
  396. imgSize: '30px',
  397. styleClass: "",
  398. onclickfunc: function () {
  399. let srcEl = document.querySelector('#assetsrc');
  400. vwf_view.kernel.callMethod(vwf.application(), "createAssetResource", ['AUDIO', srcEl.value])
  401. }
  402. }),
  403. self.widgets.buttonSimple(
  404. {
  405. label: "MTL",
  406. onclick: function (e) {
  407. let srcEl = document.querySelector('#assetsrc');
  408. if (srcEl.value.includes('.mtl'))
  409. vwf_view.kernel.callMethod(vwf.application(), "createAssetResource", ['ITEM', srcEl.value])
  410. }
  411. }
  412. )
  413. ]
  414. },
  415. {
  416. $type: "div",
  417. class: "mdc-layout-grid__inner",
  418. $components: [
  419. {
  420. $type: "div",
  421. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  422. $components: [
  423. self.widgets.divider
  424. ]
  425. },
  426. {
  427. $type: "div",
  428. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  429. $components: [
  430. {
  431. $type: "h3",
  432. class: "",
  433. $text: 'Google Poly'
  434. }
  435. ]
  436. },
  437. {
  438. $type: "div",
  439. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  440. $components: [
  441. self.widgets.inputTextFieldOutlined({
  442. "id": 'googlepolyid',
  443. "fieldStyle": 'width: 350px',
  444. "label": "Enter Google Poly model ID",
  445. "value": '',
  446. "change": function (e) {
  447. console.log(this.value)
  448. }
  449. })
  450. ]
  451. },
  452. {
  453. $type: "div",
  454. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  455. $components: [
  456. self.widgets.buttonSimple(
  457. {
  458. label: "Load from Poly",
  459. onclick: function (e) {
  460. let srcEl = document.querySelector('#googlepolyid');
  461. let avatarID = 'avatar-' + vwf.moniker_;
  462. vwf_view.kernel.callMethod(vwf.application(), "createGooglePoly", [srcEl.value, null, null, avatarID])
  463. }
  464. }
  465. )
  466. ]
  467. }
  468. ]
  469. }
  470. ]
  471. }
  472. function getUniqueDisplayName(newname, addcount) {
  473. if (!addcount) addcount = 0;
  474. if (!newname) newname = 'Object';
  475. newname = newname.replace(/[0-9]*$/g, "");
  476. var nodes = self.nodes; //vwf.models.object.objects;
  477. var count = 1 + addcount;
  478. for (var i in nodes) {
  479. if (nodes[i].id !== 0) {
  480. if (nodes[i].id !== "" && nodes[i].properties.length !== 0) {
  481. let thisname = vwf.getProperty(nodes[i].ID, 'displayName') || '';
  482. console.log(thisname);
  483. if (thisname.replace(/[0-9]*$/g, "") == newname)
  484. count++;
  485. }
  486. }
  487. }
  488. return newname + count;
  489. }
  490. function make3DPrimitiveList() {
  491. let nodeNames = ['Plane', 'Cube', 'Sphere', 'Cylinder', 'Cone', 'Text'];
  492. return nodeNames.map(el => {
  493. return self.widgets.gridListItem({
  494. imgSrc: "/drivers/view/editor/images/ui/icons/" + el.toLowerCase() + ".png",
  495. imgSize: "30px",
  496. styleClass:"", //"createListItem",
  497. title: el,
  498. onclickfunc: function () {
  499. let avatarID = 'avatar-' + vwf.moniker_;
  500. //let cubeName = self.GUID();
  501. let displayName = getUniqueDisplayName.call(self, el.toLowerCase());
  502. vwf_view.kernel.callMethod(vwf.application(), "createPrimitive", [el.toLowerCase(), {}, displayName, null, avatarID])
  503. }
  504. })
  505. })
  506. }
  507. function makeLightsList() {
  508. let nodeNames = ['Ambient', 'Directional', 'Hemisphere', 'Point', 'Spot'];
  509. return nodeNames.map(el => {
  510. return self.widgets.gridListItem({
  511. imgSize: "30px",
  512. styleClass: "",
  513. imgSrc: "/drivers/view/editor/images/ui/icons/light_" + el.toLowerCase() + ".png",
  514. title: el,
  515. onclickfunc: function () {
  516. let avatarID = 'avatar-' + vwf.moniker_;
  517. //let cubeName = self.GUID();
  518. let displayName = getUniqueDisplayName.call(self, el.toLowerCase());
  519. vwf_view.kernel.callMethod(vwf.application(), "createPrimitive", ["light", {type: el.toLowerCase()}, displayName, null, avatarID])
  520. }
  521. })
  522. })
  523. }
  524. var saveAvatar = {};
  525. var loadAvatar = {};
  526. if (_LCSDB.user().is) {
  527. saveAvatar = self.widgets.floatActionButton({
  528. label: "save",
  529. styleClass: "mdc-fab--mini",
  530. onclickfunc: function () {
  531. //var nodeID = document.querySelector('#currentNode')._currentNode;
  532. let nodeID = 'avatar-' + self.kernel.moniker();
  533. let node = self.nodes[nodeID];
  534. let nodeDef = self.helpers.getNodeDef(nodeID).children.avatarNode;
  535. console.log(nodeDef);
  536. _LCSDB.user().get('profile').get('avatarNode').put(JSON.stringify(nodeDef), acc => {
  537. console.log("saved: " + acc)
  538. });
  539. //vwf_view.kernel.deleteChild(node.parentID, node.name);
  540. //vwf_view.kernel.deleteNode(nodeID);
  541. //vwf_view.kernel.callMethod(node.parentID, "deleteNode", [node.name])
  542. }
  543. });
  544. loadAvatar = self.widgets.floatActionButton({
  545. label: "restore",
  546. styleClass: "mdc-fab--mini",
  547. onclickfunc: function () {
  548. let nodeID = 'avatar-' + self.kernel.moniker();
  549. _LCSDB.user().get('profile').get('avatarNode').once(res => {
  550. if (res) {
  551. var myNode = res;
  552. if (self.helpers.testJSON(res)){
  553. myNode = JSON.parse(res);
  554. }
  555. vwf_view.kernel.callMethod(nodeID, "changeCostume", [myNode, true]);
  556. }
  557. })
  558. }
  559. })
  560. }
  561. let avatarSettings =
  562. {
  563. $cell: true,
  564. $type: "div",
  565. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  566. $components: [
  567. {
  568. $type: "div",
  569. class: "mdc-layout-grid__inner",
  570. $components: [
  571. {
  572. $type: "div",
  573. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  574. $components: [
  575. self.widgets.icontoggle({
  576. 'id': "mobile_joystick",
  577. 'label': 'visibility',
  578. 'on': JSON.stringify({ "content": "gamepad", "label": "Show" }),
  579. 'off': JSON.stringify({ "content": "gamepad", "label": "Hide" }),
  580. 'state': false,
  581. 'init': function () {
  582. this._driver = vwf.views["/drivers/view/aframe"];
  583. this._comp = new mdc.iconButton.MDCIconButtonToggle(this);
  584. //mdc.iconButton.MDCIconButtonToggle.attachTo(this);
  585. if (document.getElementsByClassName('touchZone').length > 0){
  586. this._comp.on = true;
  587. this.style.color = "#3e7e40";
  588. } else {
  589. this._comp.on = false;
  590. this.style.color = "#333333";
  591. }
  592. this.addEventListener('MDCIconButtonToggle:change', (e) => {
  593. let chkAttr = e.detail.isOn;
  594. let driver = e.target._driver;
  595. if (chkAttr) {
  596. driver.state.showMobileJoystick();
  597. this.style.color = "#3e7e40";
  598. // this.classList.add('mdc-icon-toggle--enabled');
  599. console.log("on");
  600. } else {
  601. driver.state.hideMobileJoystick();
  602. this.style.color = "#333333";
  603. //this.classList.add('mdc-icon-toggle--disabled');
  604. console.log("off")
  605. }
  606. });
  607. }
  608. }),
  609. self.widgets.divider
  610. ]
  611. },
  612. {
  613. $type: "div",
  614. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  615. $components: [
  616. saveAvatar,
  617. loadAvatar,
  618. self.widgets.divider,
  619. self.widgets.buttonStroked(
  620. {
  621. "label": "Reset camera view",
  622. "onclick": function (e) {
  623. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  624. let controlEl = document.querySelector('#avatarControl');
  625. controlEl.setAttribute('camera', 'active', true);
  626. }
  627. }),
  628. self.widgets.buttonStroked(
  629. {
  630. "label": "Hide cursor",
  631. "onclick": function (e) {
  632. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  633. let cursorID = 'mouse-' + self.kernel.moniker();
  634. //let avatarID = 'avatar-' + self.kernel.moniker();
  635. // let cursorID = vwf.find(avatarID, "./avatarNode/myHead/myCursor")[0];
  636. let controlEl = document.querySelector("[id='" + cursorID + "']");
  637. let vis = controlEl.getAttribute('visible');
  638. this.$text = vis ? 'Show cursor' : 'Hide cursor';
  639. vwf_view.kernel.setProperty(cursorID, "visible", !vis);
  640. //vwf_view.kernel.callMethod(avatarID, "showHideCursor", [!vis]);
  641. //controlEl.setAttribute('visible', !vis);
  642. }
  643. }),
  644. self.widgets.buttonStroked(
  645. {
  646. "label": "Hide Avatar",
  647. "onclick": function (e) {
  648. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  649. let avatarID = 'avatar-' + self.kernel.moniker();
  650. //let cursorID = 'myCursor-' + avatarID;
  651. let controlEl = document.querySelector("[id='" + avatarID + "']");
  652. let vis = controlEl.getAttribute('visible');
  653. this.$text = vis ? 'Show Avatar' : 'Show Avatar';
  654. vwf_view.kernel.callMethod(avatarID, "showHideAvatar", [!vis]);
  655. //controlEl.setAttribute('visible', !vis);
  656. }
  657. }
  658. ),
  659. self.widgets.buttonStroked(
  660. {
  661. "label": "Reset Avatar",
  662. "onclick": function (e) {
  663. let avatarID = 'avatar-' + self.kernel.moniker();
  664. //TODO: add XR check
  665. vwf_view.kernel.callMethod(avatarID, "resetAvatar", []);
  666. }
  667. }
  668. )
  669. ]
  670. },
  671. {
  672. $type: "div",
  673. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  674. $components: [
  675. {
  676. $type: "div",
  677. class: "mdc-layout-grid",
  678. $components: [
  679. {
  680. $type: "div",
  681. class: "mdc-layout-grid__inner",
  682. $components: [
  683. {
  684. $type: "div",
  685. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  686. $components: [
  687. self.avatarCardDef("/defaults/assets/avatars/ico/simple.jpg", { title: "Simple", subtitle: "Cube" },
  688. function (e) {
  689. let avatarID = 'avatar-' + self.kernel.moniker();
  690. vwf_view.kernel.callMethod(avatarID, "createSimpleAvatar");
  691. }
  692. )
  693. ]
  694. },
  695. {
  696. $type: "div",
  697. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  698. $components: [
  699. self.avatarCardDef("/defaults/assets/avatars/ico/female.jpg", { title: "Human", subtitle: "Female" },
  700. function (e) {
  701. let avatarID = 'avatar-' + self.kernel.moniker();
  702. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/defaults/assets/avatars/female/avatar1.gltf"]);
  703. }
  704. )]
  705. },
  706. {
  707. $type: "div",
  708. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  709. $components: [
  710. self.avatarCardDef("/defaults/assets/avatars/ico/male.jpg", { title: "Human", subtitle: "Male" },
  711. function (e) {
  712. let avatarID = 'avatar-' + self.kernel.moniker();
  713. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/defaults/assets/avatars/male/avatar1.gltf"]);
  714. }
  715. )]
  716. }
  717. ]
  718. }
  719. ]
  720. }
  721. ]
  722. },
  723. {
  724. $type: "div",
  725. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  726. $components: [
  727. self.widgets.buttonStroked(
  728. {
  729. "label": "Wide",
  730. "onclick": function (e) {
  731. let avatarID = 'avatar-' + vwf.moniker_;
  732. vwf_view.kernel.callMethod(avatarID, "setBigVideoHead", []);
  733. }
  734. }),
  735. self.widgets.buttonStroked(
  736. {
  737. "label": "Small",
  738. "onclick": function (e) {
  739. let avatarID = 'avatar-' + vwf.moniker_;
  740. vwf_view.kernel.callMethod(avatarID, "setSmallVideoHead", []);
  741. }
  742. })
  743. ]
  744. }
  745. ]
  746. }
  747. ]
  748. }
  749. let viewSettings =
  750. {
  751. $cell: true,
  752. $type: "div",
  753. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  754. $components: [
  755. {
  756. $type: "div",
  757. class: "mdc-layout-grid__inner",
  758. $components: [
  759. {
  760. $type: "div",
  761. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  762. $components: [
  763. self.widgets.buttonStroked(
  764. {
  765. "label": "OSC Settings",
  766. "onclick": function (e) {
  767. let sideBar = document.querySelector('#sideBar');
  768. sideBar._sideBarComponent = oscSettings;
  769. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  770. }
  771. })
  772. ]
  773. }
  774. ]
  775. }
  776. ]
  777. }
  778. let savedStateEl = function (item) {
  779. return {
  780. $type: "li",
  781. class: "mdc-list-item",
  782. role: "option",
  783. $components: [
  784. {
  785. $text: "Saved world"
  786. }
  787. ]
  788. }
  789. }
  790. let stateListElement = function (item) {
  791. let liEl = {
  792. $type: "option",
  793. id: "",
  794. applicationpath: "",
  795. value: "no_saves",
  796. $components: [
  797. {
  798. $text: "no saves"
  799. }
  800. ]
  801. }
  802. let applicationName = item.applicationpath.split("/");
  803. if (applicationName == "") {
  804. return liEl
  805. }
  806. if (applicationName.length > 0) {
  807. applicationName = applicationName[applicationName.length - 1];
  808. }
  809. if (applicationName.length > 0) {
  810. applicationName = applicationName.charAt(0).toUpperCase() + applicationName.slice(1);
  811. }
  812. if (item.latestsave) {
  813. liEl = {
  814. $type: "option",
  815. id: item.savename,
  816. value: item.savename,
  817. applicationpath: item.applicationpath,
  818. $components: [
  819. {
  820. $text: applicationName + ": " + item.savename
  821. }
  822. ]
  823. }
  824. }
  825. else {
  826. liEl = {
  827. $type: "option",
  828. id: item.savename,
  829. value: item.savename,
  830. revision: item.revision,
  831. applicationpath: item.applicationpath,
  832. $components: [
  833. {
  834. $text: applicationName + ": " + item.savename + " Rev(" + item.revision + ")"
  835. }
  836. ]
  837. }
  838. }
  839. return liEl
  840. }
  841. let oscSettings =
  842. {
  843. $cell: true,
  844. $type: "div",
  845. id: "oscSettings",
  846. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  847. _oscHost: '',
  848. _oscPort: '',
  849. _oscStatus: '',
  850. _updateStatus: function () {
  851. this._oscStatus = window._OSCManager.getStatus()
  852. },
  853. $init: function () {
  854. if (window._OSCManager) {
  855. this._oscHost = window._OSCManager.hostValue;
  856. this._oscPort = window._OSCManager.portValue;
  857. this._oscStatus = window._OSCManager.getStatus();
  858. // var t = this;
  859. // setInterval(function () {
  860. // t._updateStatus();
  861. // }, 1000);
  862. }
  863. },
  864. $update: function () {
  865. let that = this
  866. var buttonText = "Connect";
  867. var buttonFunc = function (e) {
  868. }
  869. if (this._oscStatus == 1) {
  870. buttonText = "Disconnect";
  871. buttonFunc = function (e) {
  872. window._OSCManager.disconnect();
  873. }
  874. } else {
  875. var buttonFunc = function (e) {
  876. window._OSCManager.connect();
  877. window._OSCManager.port.on("open", function () {
  878. that._oscStatus = window._OSCManager.getStatus();
  879. console.log("connected");
  880. });
  881. window._OSCManager.port.on("close", function () {
  882. that._oscStatus = window._OSCManager.getStatus();
  883. console.log("disconnected");
  884. });
  885. }
  886. }
  887. this.$components = [
  888. {
  889. $type: "div",
  890. class: "mdc-layout-grid__inner",
  891. $components: [
  892. {
  893. $type: "div",
  894. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  895. $components: [
  896. self.widgets.inputTextFieldOutlined({
  897. "id": 'oscHostInput',
  898. "label": "Host",
  899. "value": this._oscHost,
  900. "change": function (e) {
  901. this._oscHost = this.value;
  902. window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  903. }
  904. })
  905. // {
  906. // $type: "span",
  907. // $text: "Host: "
  908. // },
  909. // {
  910. // class: "mdc-text-field",
  911. // $type: "span",
  912. // $components: [
  913. // {
  914. // class: "mdc-text-field__input prop-text-field-input",
  915. // id: "oscHost",
  916. // $type: "input",
  917. // type: "text",
  918. // value: this._oscHost,
  919. // onchange: function (e) {
  920. // this._oscHost = this.value;
  921. // window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  922. // }
  923. // }
  924. // ]
  925. // }
  926. ]
  927. },
  928. {
  929. $type: "div",
  930. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  931. $components: [
  932. self.widgets.inputTextFieldOutlined({
  933. "id": 'oscPortInput',
  934. "label": "Port",
  935. "value": this._oscPort,
  936. "change": function (e) {
  937. this._oscPort = this.value;
  938. window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  939. }
  940. })
  941. // {
  942. // $type: "span",
  943. // $text: "Port: "
  944. // },
  945. // {
  946. // class: "mdc-text-field",
  947. // $type: "span",
  948. // $components: [
  949. // {
  950. // class: "mdc-text-field__input prop-text-field-input",
  951. // id: "oscPort",
  952. // $type: "input",
  953. // type: "text",
  954. // value: this._oscPort,
  955. // onchange: function (e) {
  956. // this._oscPort = this.value;
  957. // window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  958. // }
  959. // }
  960. // ]
  961. // }
  962. ]
  963. },
  964. {
  965. $type: "div",
  966. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  967. $components: [
  968. self.widgets.buttonStroked(
  969. {
  970. "label": buttonText,
  971. "onclick": buttonFunc
  972. })
  973. ]
  974. }
  975. ]
  976. }
  977. ]
  978. }
  979. }
  980. let loadSaveSettings =
  981. {
  982. $cell: true,
  983. $type: "div",
  984. id: "loadSaveSettings",
  985. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  986. $init: function () {
  987. var userGUI = [];
  988. let worldOwner = self.helpers.getRoot().user;
  989. let genWorldID = 'world' + self.helpers.randId();
  990. if (_LCSDB.user().is) {
  991. if (worldOwner == _LCSDB.user().is.alias) {
  992. userGUI.push(
  993. {
  994. $type: "div",
  995. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  996. $components: [
  997. {
  998. $type: "h3",
  999. class: "mdc-typography--title",
  1000. $text: self.helpers.appPath
  1001. },
  1002. self.widgets.buttonStroked(
  1003. {
  1004. "label": "Save world",
  1005. "onclick": function (e) {
  1006. _app.saveWorld();
  1007. //let fileName = self.helpers.getRoot().root;
  1008. //_app.saveState(fileName);
  1009. //// let fileName = self.helpers.worldStateName;
  1010. ////_app.saveStateAsFile(fileName);
  1011. //document.querySelector('#fileName')
  1012. //document.querySelector("#fileName").value = '';
  1013. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  1014. }
  1015. })
  1016. ]
  1017. }
  1018. );
  1019. }
  1020. userGUI.push(
  1021. {
  1022. $type: "div",
  1023. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1024. $components: [
  1025. {
  1026. $type: "div",
  1027. $components: [
  1028. self.widgets.inputTextFieldOutlined({
  1029. "id": 'fileName',
  1030. "label": genWorldID,
  1031. //"value": 'world' + self.helpers.randId(), //self.getSaveName() //self.getRoot()
  1032. "change": function (e) {
  1033. }
  1034. })
  1035. // {
  1036. // class: "mdc-text-field__input prop-text-field-input",
  1037. // id: "fileName",
  1038. // $type: "input",
  1039. // type: "text",
  1040. // value: 'world' + self.helpers.randId() //self.getSaveName() //self.getRoot()
  1041. // }
  1042. ]
  1043. }
  1044. ]
  1045. },
  1046. {
  1047. $type: "div",
  1048. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1049. $components: [
  1050. self.widgets.buttonStroked(
  1051. {
  1052. "label": "Clone world",
  1053. "onclick": function (e) {
  1054. let fileName = document.querySelector('#fileName')
  1055. let worldOwner = self.helpers.getRoot().user;
  1056. let worldName = _app.worldName;
  1057. if (_LCSDB.user().is) {
  1058. let wn = fileName.value ? fileName.value : genWorldID;
  1059. _app.cloneWorld(worldName, worldOwner, wn, true)
  1060. // if (worldOwner == _LCSDB.user().is.alias) {
  1061. // _app.saveStateAsFile(fileName.value);
  1062. // } else {
  1063. // console.log('clone world with prototype to: ' + fileName);
  1064. // _app.cloneWorldState(fileName.value);
  1065. // }
  1066. }
  1067. //saveStateAsFile.call(self, fileName.value);
  1068. //document.querySelector("#fileName").value = '';
  1069. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  1070. }
  1071. })
  1072. ]
  1073. }
  1074. );
  1075. if (worldOwner == _LCSDB.user().is.alias) {
  1076. userGUI.push(
  1077. {
  1078. $type: "div",
  1079. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1080. $components: [
  1081. {
  1082. $type: "p",
  1083. },
  1084. self.widgets.buttonStroked(
  1085. {
  1086. "label": "Save state",
  1087. "onclick": function (e) {
  1088. // _app.saveWorld();
  1089. let myWorldName = self.helpers.getRoot().root;
  1090. let fileName = document.querySelector('#fileName');
  1091. let wn = fileName.value ? fileName.value : myWorldName;
  1092. _app.saveState(wn);
  1093. //document.querySelector('#fileName')
  1094. //document.querySelector("#fileName").value = '';
  1095. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  1096. }
  1097. })
  1098. ]
  1099. }
  1100. );
  1101. }
  1102. // let saveGUI = document.querySelector('#saveGUI');
  1103. // saveGUI.$components = userGUI.concat(saveGUI.$components);
  1104. //document.querySelector('#fileName').value = 'world' + _app.helpers.randId();
  1105. } else {
  1106. userGUI.push(
  1107. self.widgets.getLoginGUI()
  1108. );
  1109. }
  1110. let saveGUI = document.querySelector('#saveGUI');
  1111. saveGUI.$components = userGUI.concat(saveGUI.$components);
  1112. },
  1113. $update: function () {
  1114. },
  1115. $components:
  1116. [
  1117. {
  1118. $type: "div",
  1119. class: "mdc-layout-grid__inner",
  1120. id: "saveGUI",
  1121. $components: [
  1122. ]
  1123. }
  1124. ]
  1125. }
  1126. let protoPropertiesCell = function (m) {
  1127. return {
  1128. $type: "div",
  1129. class: "mdc-layout-grid__inner",
  1130. _prop: {},
  1131. $init: function () {
  1132. let prop = m[1].prop;
  1133. let property = vwf.getProperty(this._currentNode, prop.name, []);
  1134. if (prop.value == undefined && this._currentNode !== undefined) {
  1135. prop.value = JSON.stringify(LCSEditor.utility.transform(property, LCSEditor.utility.transforms.transit));
  1136. }
  1137. this._prop = prop
  1138. },
  1139. $update: function () {
  1140. this.$components = [
  1141. // {
  1142. // $type: "div",
  1143. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-10",
  1144. // $components: [
  1145. // { $text: this._prop.name }
  1146. // ]
  1147. // },
  1148. // {
  1149. // $type: "div",
  1150. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1151. // },
  1152. {
  1153. $type: "div",
  1154. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1155. $components: [
  1156. // {
  1157. // $type: "span",
  1158. // class: "mdc-typography--body2 mdc-typography--adjust-margin protoPropLabel",
  1159. // $text: this._prop.name + ': '
  1160. // },
  1161. {
  1162. $type: "div",
  1163. $components: [
  1164. self.widgets.inputTextFieldStandart({
  1165. "id": 'proto_' + this._prop.name,
  1166. "label": this._prop.name,
  1167. "value": this._prop.getValue(),
  1168. "change": function (e) {
  1169. //set property
  1170. let value = this.value;
  1171. var propValue = value;
  1172. if (self.helpers.testJSON(value)){
  1173. propValue = JSON.parse(value);
  1174. } else {
  1175. propValue = value;
  1176. }
  1177. self.kernel.setProperty(this._currentNode, this._prop.name, propValue);
  1178. // let propValue = this.value;
  1179. // try {
  1180. // propValue = JSON.parse(propValue);
  1181. // self.kernel.setProperty(this._currentNode, this._prop.name, propValue);
  1182. // } catch (e) {
  1183. // // restore the original value on error
  1184. // this.value = propValue;
  1185. // }
  1186. }
  1187. })
  1188. ]
  1189. }
  1190. ]
  1191. }
  1192. ]
  1193. }
  1194. }
  1195. }
  1196. let propertiesCell = function (m) {
  1197. var editComponents = [{}, {}];
  1198. // fullWidth:
  1199. // fullHeight:
  1200. // xoffset:
  1201. // yoffset:
  1202. // width:
  1203. // height:
  1204. let sliderPropNames = ['width', 'height', 'depth', 'fullWidth', 'fullHeight', 'xoffset', 'yoffset', 'subcamWidth', 'subcamHeight'];
  1205. let sliderProps = {
  1206. 'width': {
  1207. min: 0,
  1208. max: 30
  1209. },
  1210. 'height': {
  1211. min: 0,
  1212. max: 30
  1213. },
  1214. 'depth': {
  1215. min: 0,
  1216. max: 30
  1217. },
  1218. 'fullWidth': {
  1219. min: 0,
  1220. max: 5000,
  1221. step: 10
  1222. },
  1223. 'fullHeight': {
  1224. min: 0,
  1225. max: 5000,
  1226. step: 10
  1227. },
  1228. 'xoffset': {
  1229. min: -10000,
  1230. max: 10000,
  1231. step: 10
  1232. },
  1233. 'yoffset': {
  1234. min: -10000,
  1235. max: 10000,
  1236. step: 10
  1237. },
  1238. 'subcamWidth': {
  1239. min: 0,
  1240. max: 5000,
  1241. step: 10
  1242. },
  1243. 'subcamHeight': {
  1244. min: 0,
  1245. max: 5000,
  1246. step: 10
  1247. }
  1248. }
  1249. if (sliderPropNames.includes(m.name)) {
  1250. let currenValue = JSON.parse(m.getValue());
  1251. var sliderComponent = self.widgets.sliderContinuous({
  1252. 'id': 'prop-slider-' + m.name,
  1253. 'label': 'Slider',
  1254. 'min': sliderProps[m.name].min,
  1255. 'max': sliderProps[m.name].max,
  1256. 'step': sliderProps[m.name].step ? sliderProps[m.name].step : 0.1,
  1257. 'value': currenValue,
  1258. 'init': function () {
  1259. const myEl = this;
  1260. var continuousSlider = new mdc.slider.MDCSlider(myEl);
  1261. this._comp = continuousSlider;
  1262. continuousSlider.listen('MDCSlider:input', function (e) {
  1263. // console.log(continuousSlider.value)
  1264. let myEl = e.currentTarget;
  1265. // let prop = myEl._prop.body;
  1266. //document.querySelector('#propAceEditor').env.editor.setValue(prop);
  1267. self.kernel.setProperty(myEl._currentNode, m.name, continuousSlider.value);
  1268. //continuousValue.textContent = continuousSlider.value;
  1269. });
  1270. continuousSlider.listen('MDCSlider:change', function (e) {
  1271. //console.log(continuousSlider.value);
  1272. let myEl = e.currentTarget;
  1273. // let prop = myEl._prop.body;
  1274. //document.querySelector('#propAceEditor').env.editor.setValue(prop);
  1275. self.kernel.setProperty(myEl._currentNode, m.name, continuousSlider.value);
  1276. //continuousCommittedValue.textContent = continuousSlider.value;
  1277. })
  1278. }
  1279. })
  1280. } else {
  1281. sliderComponent = {}
  1282. }
  1283. if (m.name.indexOf("semantics") > -1) { }
  1284. else if (m.name.indexOf("grammar") > -1) { }
  1285. else if (m.name.indexOf("ohm") > -1) {
  1286. editComponents = [
  1287. {
  1288. $type: "div",
  1289. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  1290. $components: [
  1291. {
  1292. $type: "button",
  1293. class: "mdc-button",
  1294. $text: "Edit", //edit grammar
  1295. onclick: function (e) {
  1296. var currentNode = document.querySelector('#currentNode')._currentNode;
  1297. if (currentNode == '') {
  1298. currentNode = vwf_view.kernel.find("", "/")[0];
  1299. }
  1300. let editor = document.querySelector('#livePropEditor');
  1301. editor._setNode(currentNode);
  1302. editor._propName = m.name;
  1303. editor._prop = { body: m.rawValue, type: 'complex' }
  1304. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  1305. }
  1306. }
  1307. ]
  1308. },
  1309. {
  1310. $type: "div",
  1311. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  1312. $components: []
  1313. }
  1314. ]
  1315. } else {
  1316. editComponents = [
  1317. {
  1318. $type: "div",
  1319. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  1320. $components: [
  1321. sliderComponent,
  1322. {
  1323. class: "mdc-text-field prop-mdc-text-field",
  1324. $type: "div",
  1325. $components: [
  1326. self.widgets.inputTextFieldStandart({
  1327. "id": "prop-" + m.name,
  1328. "label": m.name,
  1329. "value": m.getValue(),
  1330. "change": function (e) {
  1331. //set property
  1332. let value = this.value;
  1333. var propValue = value;
  1334. if (self.helpers.testJSON(value)){
  1335. propValue = JSON.parse(value);
  1336. } else {
  1337. propValue = value;
  1338. //this.value = JSON.parse(JSON.stringify(propValue));
  1339. }
  1340. self.kernel.setProperty(this._currentNode, m.name, propValue);
  1341. //this.value = propValue.toString();
  1342. // let propValue = this.value;
  1343. // try {
  1344. // propValue = JSON.parse(propValue);
  1345. // self.kernel.setProperty(this._currentNode, m.name, propValue);
  1346. // } catch (e) {
  1347. // // restore the original value on error
  1348. // this.value = propValue;
  1349. // }
  1350. }
  1351. })
  1352. ]
  1353. }
  1354. ]
  1355. },
  1356. {
  1357. $type: "div",
  1358. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  1359. $components: [
  1360. {
  1361. $type: "button",
  1362. class: "mdc-button mdc-button--compact",
  1363. $text: "^", //edit grammar
  1364. onclick: function (e) {
  1365. var currentNode = document.querySelector('#currentNode')._currentNode;
  1366. if (currentNode == '') {
  1367. currentNode = vwf_view.kernel.find("", "/")[0];
  1368. }
  1369. let editor = document.querySelector('#livePropEditor');
  1370. editor._setNode(currentNode);
  1371. editor._propName = m.name;
  1372. editor._prop = { body: m.getValue(), type: 'simple' }
  1373. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  1374. }
  1375. }
  1376. ]
  1377. }
  1378. ];
  1379. }
  1380. return {
  1381. $type: "div",
  1382. class: "mdc-layout-grid__inner",
  1383. $components: [
  1384. {
  1385. $type: "div",
  1386. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1387. $components: [
  1388. { $text: m.name }
  1389. ]
  1390. },
  1391. {
  1392. $type: "div",
  1393. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1394. },
  1395. editComponents[0],
  1396. editComponents[1]
  1397. ]
  1398. }
  1399. }
  1400. let nodeLink = function (m) {
  1401. var myClass = "nodeItem";
  1402. let myAvatarName = 'avatar-' + self.kernel.moniker();
  1403. (myAvatarName == m.name) ? (myClass = "avatarName mdc-typography--subheading2") :
  1404. myClass = "nodeItem"
  1405. var nodeName = m.name;
  1406. let displayName = vwf.getProperty(m.ID, 'displayName');
  1407. if (displayName) {
  1408. nodeName = displayName
  1409. }
  1410. return {
  1411. $type: "li",
  1412. class: "mdc-list-item",
  1413. $components: [{
  1414. $type: "a",
  1415. class: "mdc-list-item",
  1416. $href: "#",
  1417. $components: [{
  1418. $type: 'span',
  1419. class: myClass,
  1420. $text: nodeName
  1421. }
  1422. ],
  1423. onclick: function (e) {
  1424. //self.currentNodeID = m.ID;
  1425. document.querySelector('#currentNode')._setNode(m.ID);
  1426. // document.querySelector('#liveCodeEditor')._editorNode = m.ID;
  1427. // createAceEditor(self, m.ID);
  1428. }
  1429. }]
  1430. }
  1431. };
  1432. let listDivider = {
  1433. $type: "hr",
  1434. class: "mdc-list-divider",
  1435. }
  1436. let webrtcGUI = {
  1437. $type: "div",
  1438. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1439. $components: [
  1440. {
  1441. $type: "div",
  1442. class: "mdc-layout-grid__inner",
  1443. $components: [
  1444. {
  1445. $type: "div",
  1446. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1447. $components: [
  1448. {
  1449. $type: "span",
  1450. $text: "Chat"
  1451. }
  1452. ]
  1453. },
  1454. {
  1455. $type: "div",
  1456. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1457. $components: [
  1458. self.widgets.icontoggle({
  1459. 'id': "webrtcswitch",
  1460. 'label': 'visibility',
  1461. 'on': JSON.stringify({ "content": "visibility", "label": "Turn On Mic" }),
  1462. 'off': JSON.stringify({ "content": "visibility_off", "label": "Turn Off Mic" }),
  1463. 'state': false,
  1464. 'init': function () {
  1465. this._driver = vwf.views["/drivers/view/webrtc"];
  1466. if (!this._driver) {
  1467. //this.classList.add('mdc-icon-toggle--disabled');
  1468. this.setAttribute('disabled',"");
  1469. }
  1470. mdc.iconButton.MDCIconButtonToggle.attachTo(this);
  1471. this.addEventListener('MDCIconButtonToggle:change', (e) => {
  1472. let driver = e.target._driver;
  1473. let chkAttr = e.detail.isOn;
  1474. let avatarID = 'avatar-' + self.kernel.moniker();
  1475. let micToggle = document.querySelector('#webrtcaudio');
  1476. let camToggle = document.querySelector('#webrtcvideo');
  1477. if (chkAttr) {
  1478. driver.startWebRTC(avatarID);
  1479. micToggle.removeAttribute('disabled');
  1480. camToggle.removeAttribute('disabled');
  1481. //micToggle.classList.remove('mdc-icon-toggle--disabled');
  1482. //camToggle.classList.remove('mdc-icon-toggle--disabled');
  1483. console.log("on")
  1484. } else {
  1485. driver.stopWebRTC(avatarID);
  1486. micToggle.setAttribute('disabled',"");
  1487. camToggle.setAttribute('disabled',"");
  1488. //micToggle.classList.add('mdc-icon-toggle--disabled');
  1489. //camToggle.classList.add('mdc-icon-toggle--disabled');
  1490. console.log("off")
  1491. }
  1492. //console.log(e, detail)
  1493. //status.textContent = `Icon Toggle is ${detail.isOn ? 'on' : 'off'}`;
  1494. });
  1495. }
  1496. })
  1497. ]
  1498. },
  1499. {
  1500. $type: "div",
  1501. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1502. $components: [
  1503. self.widgets.icontoggle({
  1504. 'id': "webrtcaudio",
  1505. 'label': 'mic',
  1506. 'on': JSON.stringify({ "content": "mic", "label": "Turn On Mic" }),
  1507. 'off': JSON.stringify({ "content": "mic_off", "label": "Turn Off Mic" }),
  1508. 'state': false,
  1509. 'init': function () {
  1510. this._driver = vwf.views["/drivers/view/webrtc"];
  1511. let webrtcswitch = document.querySelector('#webrtcswitch');
  1512. if (!this._driver) {
  1513. //this.classList.add('mdc-icon-toggle--disabled');
  1514. this.setAttribute("disabled", "");
  1515. }
  1516. //this.classList.add('mdc-icon-toggle--disabled');
  1517. this.setAttribute("disabled", "");
  1518. this.addEventListener('MDCIconButtonToggle:change', (e) => {
  1519. let driver = e.target._driver;
  1520. let chkAttr = e.detail.isOn;
  1521. if (chkAttr) {
  1522. driver.muteAudio(chkAttr);
  1523. console.log("on")
  1524. } else {
  1525. driver.muteAudio(chkAttr);
  1526. console.log("off")
  1527. }
  1528. //console.log(e, detail)
  1529. //status.textContent = `Icon Toggle is ${detail.isOn ? 'on' : 'off'}`;
  1530. });
  1531. }
  1532. })
  1533. ]
  1534. },
  1535. {
  1536. $type: "div",
  1537. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1538. $components: [
  1539. self.widgets.icontoggle({
  1540. 'id': "webrtcvideo",
  1541. 'label': 'videocam',
  1542. 'on': JSON.stringify({ "content": "videocam", "label": "Turn On Video" }),
  1543. 'off': JSON.stringify({ "content": "videocam_off", "label": "Turn Off Video" }),
  1544. 'state': false,
  1545. 'init': function () {
  1546. this._driver = vwf.views["/drivers/view/webrtc"];
  1547. if (!this._driver) {
  1548. //this.classList.add('mdc-icon-toggle--disabled');
  1549. this.setAttribute("disabled", "");
  1550. }
  1551. // this.classList.add('mdc-icon-toggle--disabled');
  1552. this.setAttribute("disabled", "");
  1553. this.addEventListener('MDCIconButtonToggle:change', (e) => {
  1554. let driver = e.target._driver;
  1555. let chkAttr = e.detail.isOn;
  1556. if (chkAttr) {
  1557. driver.muteVideo(chkAttr);
  1558. console.log("on")
  1559. } else {
  1560. driver.muteVideo(chkAttr);
  1561. console.log("off")
  1562. }
  1563. //console.log(e, detail)
  1564. //status.textContent = `Icon Toggle is ${detail.isOn ? 'on' : 'off'}`;
  1565. });
  1566. }
  1567. })
  1568. ]
  1569. }
  1570. ]
  1571. }
  1572. ]
  1573. }
  1574. let audioGUI = {
  1575. $type: "div",
  1576. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1577. $components: [
  1578. {
  1579. $type: "div",
  1580. class: "mdc-layout-grid__inner",
  1581. $components: [
  1582. {
  1583. $type: "div",
  1584. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1585. $components: [
  1586. {
  1587. $type: "span",
  1588. $text: "Sound: "
  1589. }
  1590. ]
  1591. },
  1592. {
  1593. $type: "div",
  1594. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1595. $components: [
  1596. self.widgets.icontoggle({
  1597. 'id': "soundStopStartSwitch",
  1598. 'label': 'play',
  1599. 'on': JSON.stringify({ "content": "pause", "label": "stop" }),
  1600. 'off': JSON.stringify({ "content": "play_arrow", "label": "play" }),
  1601. 'state': false,
  1602. 'init': function () {
  1603. var nodeID = this._currentNode;
  1604. this._comp = new mdc.iconButtonToggle.MDCIconButtonToggle(this);
  1605. this.setAttribute('id', "soundStopStartSwitch-" + nodeID);
  1606. let isPlaying = vwf.getProperty(nodeID, 'isPlaying');
  1607. //mdc.iconToggle.MDCIconToggle.attachTo(this);
  1608. this._comp.on = isPlaying;
  1609. this.addEventListener('MDCIconButtonToggle:change', (e) => {
  1610. // let avatarID = 'avatar-'+ vwf.moniker_;
  1611. // let avatarNode = self.nodes['avatar-'+ vwf.moniker_];
  1612. // let mode = JSON.parse(avatarNode.properties.selectMode.getValue());
  1613. var nodeID = document.querySelector('#currentNode')._currentNode;
  1614. let isPlaying = vwf.getProperty(nodeID, 'isPlaying');
  1615. if (isPlaying) {
  1616. console.log("stop");
  1617. vwf_view.kernel.callMethod(nodeID, "pauseSound");
  1618. } else {
  1619. console.log("play")
  1620. vwf_view.kernel.callMethod(nodeID, "playSound");
  1621. }
  1622. });
  1623. }
  1624. })
  1625. ]
  1626. },
  1627. {
  1628. $type: "div",
  1629. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1630. $components: [
  1631. {
  1632. $type: "div",
  1633. style: "padding: 12px",
  1634. $components: [
  1635. self.widgets.iconButton({
  1636. 'label': 'stop',
  1637. onclickfunc: function () {
  1638. var nodeID = this._currentNode;
  1639. vwf_view.kernel.callMethod(nodeID, "stopSound");
  1640. }
  1641. })
  1642. ]
  1643. }
  1644. ]
  1645. }
  1646. // {
  1647. // $type: "div",
  1648. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1649. // $components: [
  1650. // widgets.switch({
  1651. // 'id': 'editnode',
  1652. // 'init': function(){
  1653. // vwf_view.kernel.getProperty(this._currentNode, 'edit');
  1654. // },
  1655. // 'onchange': function(e){
  1656. // var nodeID = document.querySelector('#currentNode')._currentNode;
  1657. // let chkAttr = this.getAttribute('checked');
  1658. // if (chkAttr == "") {
  1659. // self.kernel.setProperty(this._currentNode, 'edit', false);
  1660. // } else {
  1661. // self.kernel.setProperty(this._currentNode, 'edit', true);
  1662. // }
  1663. // vwf_view.kernel.callMethod(nodeID, "showCloseGizmo");
  1664. // }
  1665. // }
  1666. // )
  1667. // ]
  1668. // }
  1669. ]
  1670. }
  1671. ]
  1672. }
  1673. var saveGUI = {};
  1674. if (_LCSDB.user().is) {
  1675. saveGUI = self.widgets.floatActionButton({
  1676. label: "save",
  1677. styleClass: "mdc-fab--mini",
  1678. onclickfunc: function () {
  1679. var nodeID = document.querySelector('#currentNode')._currentNode;
  1680. let node = self.nodes[nodeID];
  1681. let nodeDef = self.helpers.getNodeDef(nodeID);
  1682. console.log(nodeDef);
  1683. //let saveID = this.GUID();
  1684. // _LCSUSER.get('saves').get(node.name).put(JSON.stringify(nodeDef), acc=>{
  1685. // console.log("saved: " + acc + 'to '+ node.name)
  1686. // });
  1687. }
  1688. })
  1689. }
  1690. let gizmoEdit = {
  1691. $type: "div",
  1692. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1693. $components: [
  1694. {
  1695. $type: "div",
  1696. class: "mdc-layout-grid__inner",
  1697. $components: [
  1698. {
  1699. $type: "div",
  1700. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1701. $components: [
  1702. {
  1703. $type: "span",
  1704. $text: "Edit: ",
  1705. }
  1706. ]
  1707. },
  1708. {
  1709. $type: "div",
  1710. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1711. $components: [
  1712. self.widgets.switch({
  1713. 'id': 'editnode',
  1714. 'init': function () {
  1715. vwf_view.kernel.getProperty(this._currentNode, 'edit');
  1716. this._switch = new mdc.switchControl.MDCSwitch(this);
  1717. this._switch.checked = false;
  1718. },
  1719. 'onchange': function (e) {
  1720. var nodeID = document.querySelector('#currentNode')._currentNode;
  1721. if (this._switch) {
  1722. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  1723. if (chkAttr) {
  1724. self.kernel.setProperty(this._currentNode, 'edit', true);
  1725. //this._switch.checked = false;
  1726. } else {
  1727. self.kernel.setProperty(this._currentNode, 'edit', false);
  1728. //this._switch.checked = true;
  1729. }
  1730. //vwf_view.kernel.callMethod(nodeID, "createEditTool");
  1731. vwf_view.kernel.callMethod(nodeID, "showCloseGizmo");
  1732. }
  1733. }
  1734. }
  1735. )
  1736. ]
  1737. },
  1738. {
  1739. $type: "div",
  1740. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1741. $components: [
  1742. self.widgets.imageButton({
  1743. imgSrc: "/drivers/view/editor/images/ui/icons/translate.png",
  1744. styleClass: "editButton",
  1745. onclickfunc: function (e) {
  1746. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['translate'])
  1747. }
  1748. })
  1749. ]
  1750. },
  1751. {
  1752. $type: "div",
  1753. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1754. $components: [
  1755. self.widgets.imageButton({
  1756. imgSrc: "/drivers/view/editor/images/ui/icons/rotate.png",
  1757. styleClass: "editButton",
  1758. onclickfunc: function (e) {
  1759. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['rotate'])
  1760. }
  1761. })
  1762. ]
  1763. },
  1764. {
  1765. $type: "div",
  1766. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1767. $components: [
  1768. self.widgets.imageButton({
  1769. imgSrc: "/drivers/view/editor/images/ui/icons/scale.png",
  1770. styleClass: "editButton",
  1771. onclickfunc: function (e) {
  1772. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['scale'])
  1773. }
  1774. })
  1775. ]
  1776. },
  1777. {
  1778. $type: "div",
  1779. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1780. $components: [
  1781. // self.widgets.floatActionButton({
  1782. // label: "content_copy",
  1783. // styleClass: "mdc-fab--mini"
  1784. // }),
  1785. // {
  1786. // $type: "span",
  1787. // $text: " "
  1788. // },
  1789. self.widgets.floatActionButton({
  1790. label: "delete_forever",
  1791. styleClass: "mdc-fab--mini",
  1792. onclickfunc: function () {
  1793. var nodeID = document.querySelector('#currentNode')._currentNode;
  1794. let node = self.nodes[nodeID];
  1795. //vwf_view.kernel.deleteChild(node.parentID, node.name);
  1796. //vwf_view.kernel.removeChild(node.parentID, nodeID);
  1797. vwf_view.kernel.deleteNode(nodeID);
  1798. //vwf_view.kernel.callMethod(node.parentID, "deleteNode", [node.name])
  1799. }
  1800. }),
  1801. // self.widgets.floatActionButton({
  1802. // label: "person",
  1803. // styleClass: "mdc-fab--mini",
  1804. // onclickfunc: function () {
  1805. // var nodeID = document.querySelector('#currentNode')._currentNode;
  1806. // let node = self.nodes[nodeID];
  1807. // //vwf_view.kernel.deleteChild(node.parentID, node.name);
  1808. // let me = self.kernel.moniker();
  1809. // vwf_view.kernel.setProperty(nodeID, 'ownedBy', me);
  1810. // }
  1811. // }),
  1812. saveGUI
  1813. ]
  1814. },
  1815. ]
  1816. }
  1817. ]
  1818. }
  1819. let nodesCell = {
  1820. $cell: true,
  1821. $type: "div",
  1822. id: "currentNode",
  1823. _childNodes: [],
  1824. _currentNode: '',
  1825. _displayedProperties: {},
  1826. _setNode: function (aNode) {
  1827. this._currentNode = aNode;
  1828. document.querySelector('#sideBar')._sideCurrentNode = this._currentNode
  1829. },
  1830. $init: function () {
  1831. this._currentNode = document.querySelector('#sideBar')._sideCurrentNode
  1832. //this._currentNode = vwf_view.kernel.find("", "/")[0];
  1833. //this._currentNode = '3333';
  1834. },
  1835. _getChildNodes: function () {
  1836. this._childNodes = self.nodes[this._currentNode];
  1837. if (this._childNodes !== undefined) {
  1838. return this._childNodes.children
  1839. } else {
  1840. return []
  1841. }
  1842. //let nodeIDAlpha = he.encode(this._currentNode);
  1843. },
  1844. // _getNodeComplexProperties: function () {
  1845. // let node = self.nodes[this._currentNode];
  1846. // let props = this._getNodeProperties();
  1847. // let filterFunction = function (prop) {
  1848. // return (prop.name == 'ohmLang')
  1849. // };
  1850. // let complexProps = props.filter(filterFunction.bind(this));
  1851. // return complexProps
  1852. // },
  1853. _getNodeProperties: function () {
  1854. let node = self.nodes[this._currentNode];
  1855. this._displayedProperties = {};
  1856. let filterFunction = function (prop) {
  1857. return (!this._displayedProperties[prop.name] && prop.name.indexOf('$') === -1) ? (this._displayedProperties[prop.name] = "instance", true) : (false);
  1858. };
  1859. let props = node.properties.filter(filterFunction.bind(this));
  1860. return props
  1861. },
  1862. _getNodeProtoProperties: function () {
  1863. let node = self.nodes[this._currentNode];
  1864. let filterFunction = function (prop) {
  1865. return (!this._displayedProperties[prop[1].prop.name]) ? (this._displayedProperties[prop[1].prop.name] = prop[1].prototype, true) : (false);
  1866. };
  1867. let props = Object.entries(LCSEditor.getProperties.call(self, self.kernel, node.extendsID)).filter(filterFunction.bind(this));
  1868. return props
  1869. },
  1870. $update: function () {
  1871. //this.$text = this._currentNode;
  1872. let node = self.nodes[this._currentNode];
  1873. let nodeProtos = LCSEditor.getPrototypes.call(self, self.kernel, node.extendsID);
  1874. var viewerProps = {};
  1875. var viewerPropsCell = {};
  1876. var propsActions = {};
  1877. var propsActionsCell = {};
  1878. var gizmoCell = {};
  1879. if (this._currentNode !== self.kernel.application()) {
  1880. if (nodeProtos.includes('proxy/aframe/componentNode.vwf')) {
  1881. //gizmoCell = {};
  1882. if (nodeProtos.includes('proxy/aframe/a-sound-component.vwf')) {
  1883. //console.log("sound gui")
  1884. gizmoCell = audioGUI
  1885. }
  1886. } else {
  1887. gizmoCell = gizmoEdit
  1888. }
  1889. }
  1890. if (node !== undefined) {
  1891. propsActions = {
  1892. $type: "li",
  1893. class: "mdc-list-item",
  1894. $components: [
  1895. {
  1896. $text: "Actions",
  1897. $type: "span",
  1898. class: "mdc-list-item__text mdc-typography--button"
  1899. }
  1900. ]
  1901. }
  1902. let actionsGUI = [];
  1903. if(node.properties.meta) {
  1904. if(node.properties.meta.rawValue == 'avatarCostume'){
  1905. actionsGUI.push(self.widgets.buttonStroked(
  1906. {
  1907. "label": "Use this costume",
  1908. "onclick": function (e) {
  1909. console.log("COSTUME NEW!!!");
  1910. let nodeDef = self.helpers.getNodeDef(this._currentNode);
  1911. console.log(nodeDef);
  1912. let avatarID = 'avatar-' + self.kernel.moniker();
  1913. vwf_view.kernel.callMethod(avatarID, "changeCostume", [nodeDef]);
  1914. //vwf_view.kernel.callMethod(this._currentNode, "setCameraToActive", [vwf.moniker_]);
  1915. }
  1916. }))
  1917. }
  1918. } else if(node.name.includes('xrcontroller')){
  1919. actionsGUI.push(self.widgets.buttonStroked(
  1920. {
  1921. "label": "Set as World default XR controller",
  1922. "onclick": function (e) {
  1923. vwf_view.kernel.callMethod(node.ID, "saveToScene", []);
  1924. }
  1925. }))
  1926. }
  1927. propsActionsCell = {
  1928. $cell: true,
  1929. $type: "div",
  1930. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1931. $components: [
  1932. {
  1933. $type: "div",
  1934. class: "mdc-layout-grid__inner",
  1935. $components: [
  1936. {
  1937. $type: "div",
  1938. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1939. $components: [].concat(actionsGUI)
  1940. }
  1941. ]
  1942. }
  1943. ]
  1944. //$components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1945. }
  1946. if (node.extendsID == "proxy/aframe/acamera.vwf") {
  1947. viewerProps = {
  1948. $type: "li",
  1949. class: "mdc-list-item",
  1950. $components: [
  1951. {
  1952. $text: "Viewer properties",
  1953. $type: "span",
  1954. class: "mdc-list-item__text mdc-typography--button"
  1955. }
  1956. ]
  1957. }
  1958. viewerPropsCell = {
  1959. $cell: true,
  1960. $type: "div",
  1961. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1962. $components: [
  1963. {
  1964. $type: "div",
  1965. class: "mdc-layout-grid__inner",
  1966. $components: [
  1967. {
  1968. $type: "div",
  1969. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1970. $components: [
  1971. self.widgets.buttonStroked(
  1972. {
  1973. "label": "Active",
  1974. "onclick": function (e) {
  1975. //let camera = document.querySelector('#' + this._currentNode);
  1976. vwf_view.kernel.callMethod(this._currentNode, "setCameraToActive", [vwf.moniker_]);
  1977. //camera.setAttribute('camera', 'active', true);
  1978. }
  1979. })
  1980. ]
  1981. }
  1982. ]
  1983. }
  1984. ]
  1985. //$components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1986. }
  1987. } else {
  1988. viewerProps = {};
  1989. viewerPropsCell = {};
  1990. }
  1991. }
  1992. this.$components = [
  1993. {
  1994. $type: "ul",
  1995. class: "mdc-list",
  1996. $components: [
  1997. {
  1998. $type: "li",
  1999. class: "mdc-list-item",
  2000. $components: [
  2001. self.widgets.buttonSimple(
  2002. {
  2003. "label": "<-",
  2004. "onclick": function (e) {
  2005. let node = self.nodes[this._currentNode];
  2006. if (node.parentID !== 0) {
  2007. //self.currentNodeID = node.parentID,
  2008. document.querySelector('#currentNode')._setNode(node.parentID)
  2009. }
  2010. }
  2011. }),
  2012. {
  2013. $text: "name",
  2014. $type: "span",
  2015. $init: function () {
  2016. let node = self.nodes[this._currentNode];
  2017. if (node) {
  2018. let displayName = vwf.getProperty(node.ID, 'displayName');
  2019. if (displayName) {
  2020. this.$text = displayName
  2021. } else {
  2022. this.$text = node.name;
  2023. }
  2024. }
  2025. //console.log(node.properties.displayName)
  2026. },
  2027. class: "mdc-list-item__text mdc-typography--headline6"
  2028. //<h1 class="mdc-typography--display4">Big header</h1>
  2029. },
  2030. self.widgets.icontoggle({
  2031. 'styleClass': "", //mdc-top-app-bar__action-item
  2032. 'id': "selectNodeSwitch",
  2033. 'label': 'select',
  2034. 'on': JSON.stringify({ "content": "radio_button_checked", "label": "Select" }),
  2035. 'off': JSON.stringify({ "content": "radio_button_unchecked", "label": "Unselect" }),
  2036. 'state': false,
  2037. 'init': function () {
  2038. this._comp = mdc.iconButton.MDCIconButtonToggle.attachTo(this);
  2039. this.addEventListener('MDCIconButtonToggle:change', (e) => {
  2040. let avatarID = 'avatar-' + vwf.moniker_;
  2041. let avatarNode = self.nodes['avatar-' + vwf.moniker_];
  2042. let mode = JSON.parse(avatarNode.properties.selectMode.getValue());
  2043. if (mode) {
  2044. console.log("unselect");
  2045. vwf_view.kernel.setProperty(avatarID, "selectMode", false);
  2046. } else {
  2047. console.log("select")
  2048. vwf_view.kernel.setProperty(avatarID, "selectMode", true);
  2049. }
  2050. });
  2051. }
  2052. })
  2053. ]
  2054. }, listDivider,
  2055. {
  2056. // $cell: true,
  2057. // $type: "ul",
  2058. // class: "mdc-list",
  2059. $type: "div",
  2060. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2061. $components: [
  2062. {
  2063. $type: "div",
  2064. class: "mdc-layout-grid__inner",
  2065. $components: [
  2066. {
  2067. $type: "div",
  2068. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2069. $components: [
  2070. self.widgets.buttonStroked(
  2071. {
  2072. "label": "Methods browser",
  2073. "onclick": function (e) {
  2074. var currentNode = document.querySelector('#currentNode')._currentNode;
  2075. if (currentNode == '') {
  2076. currentNode = vwf_view.kernel.find("", "/")[0];
  2077. }
  2078. if (LCSEditor.isAFrameEntity.call(self, currentNode)) {
  2079. vwf.views["/drivers/view/aframe"].nodes[currentNode].liveBindings = {};
  2080. } else if(LCSEditor.isAFrameComponent.call(self, currentNode)) {
  2081. vwf.views["/drivers/view/aframeComponent"].nodes[currentNode].liveBindings = {};
  2082. }
  2083. document.querySelector('#liveCodeEditor')._setNode(currentNode);
  2084. //createAceEditor(self, currentNode);
  2085. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  2086. }
  2087. })
  2088. ]
  2089. }
  2090. ]
  2091. }
  2092. ]
  2093. },
  2094. gizmoCell,
  2095. listDivider,
  2096. {
  2097. $type: "li",
  2098. class: "mdc-list-item",
  2099. $components: [
  2100. {
  2101. $text: "Children",
  2102. $type: "span",
  2103. class: "mdc-list-item__text mdc-typography--button"
  2104. }]
  2105. },
  2106. {
  2107. $type: "ul",
  2108. class: "mdc-list",
  2109. $components: this._getChildNodes().map(nodeLink)
  2110. }, listDivider, {
  2111. $type: "li",
  2112. class: "mdc-list-item",
  2113. $components: [
  2114. {
  2115. $text: "Properties",
  2116. $type: "span",
  2117. class: "mdc-list-item__text mdc-typography--button"
  2118. //<h1 class="mdc-typography--display4">Big header</h1>
  2119. }]
  2120. },
  2121. {
  2122. // $cell: true,
  2123. // $type: "ul",
  2124. // class: "mdc-list",
  2125. $type: "div",
  2126. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2127. $components: this._getNodeProperties().map(propertiesCell)
  2128. },
  2129. listDivider,
  2130. {
  2131. $type: "li",
  2132. class: "mdc-list-item",
  2133. $components: [
  2134. {
  2135. $text: "Proto properties",
  2136. $type: "span",
  2137. class: "mdc-list-item__text mdc-typography--button"
  2138. }]
  2139. },
  2140. {
  2141. $type: "div",
  2142. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2143. $components: this._getNodeProtoProperties().map(protoPropertiesCell)
  2144. }, listDivider,
  2145. propsActions,
  2146. propsActionsCell,
  2147. listDivider,
  2148. viewerProps,
  2149. viewerPropsCell
  2150. ]
  2151. }
  2152. ]
  2153. }
  2154. }
  2155. let numberSliderComponent = {
  2156. $cell: true,
  2157. $type: "div",
  2158. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  2159. $init: function () {
  2160. },
  2161. $components: [
  2162. {
  2163. $type: "div",
  2164. style: "padding: 0 16px;",
  2165. $components: [
  2166. {}
  2167. ]
  2168. }
  2169. ]
  2170. }
  2171. let colorPickerComponent = {
  2172. $cell: true,
  2173. $type: "div",
  2174. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  2175. $init: function () {
  2176. let myEl = this;
  2177. let cp = ColorPicker(
  2178. document.getElementById('slide'),
  2179. document.getElementById('picker'),
  2180. function (hex, hsv, rgb, mousePicker, mouseSlide) {
  2181. ColorPicker.positionIndicators(
  2182. document.getElementById('slide-indicator'),
  2183. document.getElementById('picker-indicator'),
  2184. mouseSlide, mousePicker
  2185. );
  2186. if (myEl._propName.toLowerCase().includes('color')) {
  2187. // console.log(hex);
  2188. document.querySelector('#propAceEditor').env.editor.setValue(JSON.stringify(hex));
  2189. self.kernel.setProperty(myEl._editorNode, myEl._propName, hex);
  2190. }
  2191. });
  2192. if (myEl._propName.toLowerCase().includes('color')) {
  2193. cp.setHex(JSON.parse(myEl._prop.body));
  2194. }
  2195. },
  2196. $components: [
  2197. {
  2198. $type: "div",
  2199. id: "color-picker",
  2200. class: "cp-default",
  2201. $components: [
  2202. {
  2203. $type: "div",
  2204. class: "picker-wrapper",
  2205. $components: [
  2206. {
  2207. $type: "div",
  2208. id: "picker",
  2209. class: "picker",
  2210. style: "width: 130px; height: 130px"
  2211. },
  2212. {
  2213. $type: "div",
  2214. id: "picker-indicator",
  2215. class: "picker-indicator"
  2216. }
  2217. ]
  2218. },
  2219. {
  2220. $type: "div",
  2221. class: "slide-wrapper",
  2222. $components: [
  2223. {
  2224. $type: "div",
  2225. id: "slide",
  2226. class: "slide",
  2227. style: "width: 30px; height: 130px"
  2228. },
  2229. {
  2230. $type: "div",
  2231. id: "slide-indicator",
  2232. class: "slide-indicator"
  2233. }
  2234. ]
  2235. }
  2236. ]
  2237. }
  2238. // {
  2239. // $cell: true,
  2240. // $type: "div",
  2241. // id: "color-picker",
  2242. // $init: function () {
  2243. // }
  2244. // }
  2245. ]
  2246. }
  2247. let propEditorWindow = {
  2248. $cell: true,
  2249. $type: "div",
  2250. _editorNode: '',
  2251. _prop: { body: '', type: 'simple' },
  2252. _propName: '',
  2253. id: "livePropEditor",
  2254. _setNode: function (node) {
  2255. this._editorNode = node;
  2256. this._prop.body = ''
  2257. },
  2258. class: "propEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2259. $update: function () {
  2260. var editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-8"
  2261. var livePropertyComponent = {}
  2262. if (this._prop.type == 'simple') {
  2263. if (this._propName.toLowerCase().includes('color')) {
  2264. livePropertyComponent = colorPickerComponent
  2265. }
  2266. } else {
  2267. editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-12"
  2268. }
  2269. this.$components = [
  2270. {
  2271. $type: "div",
  2272. class: "mdc-layout-grid__inner",
  2273. $components: [
  2274. {
  2275. $type: "div",
  2276. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2277. $components: [
  2278. self.widgets.buttonStroked(
  2279. {
  2280. "label": "Update",
  2281. "onclick": function (e) {
  2282. let editor = document.querySelector("#propAceEditor").env.editor;
  2283. let value = editor.getValue();
  2284. var propValue = value;
  2285. if (this._prop.type == 'simple') {
  2286. if (self.helpers.testJSON(value)){
  2287. propValue = JSON.parse(value);
  2288. }
  2289. } else {
  2290. propValue = value;
  2291. }
  2292. self.kernel.setProperty(this._editorNode, this._propName, propValue);
  2293. // try {
  2294. // let propValue = (this._prop.type == 'simple') ? (JSON.parse(value)) : (value)
  2295. // //propValue = JSON.parse(value);
  2296. // self.kernel.setProperty(this._editorNode, this._propName, propValue);
  2297. // } catch (e) {
  2298. // // restore the original value on error
  2299. // this.value = propValue;
  2300. // }
  2301. }
  2302. }
  2303. )]
  2304. },
  2305. {
  2306. $type: "div",
  2307. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  2308. $components: [
  2309. {
  2310. $type: "h3",
  2311. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  2312. $text: this._editorNode
  2313. }
  2314. ]
  2315. },
  2316. {
  2317. $type: "div",
  2318. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  2319. $components: [
  2320. {
  2321. $type: "h3",
  2322. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  2323. $text: this._propName
  2324. }
  2325. ]
  2326. }
  2327. ]
  2328. },
  2329. {
  2330. $type: "div",
  2331. class: "mdc-layout-grid__inner",
  2332. $components: [
  2333. {
  2334. $type: "div",
  2335. class: editorClass,
  2336. $components: [
  2337. {
  2338. class: "aceEditor",
  2339. id: "propAceEditor",
  2340. $type: "div",
  2341. $text: this._prop.body,
  2342. $init: function () {
  2343. LCSEditor.createAceEditor.call(self, this._editorNode, "propAceEditor");
  2344. this.env.editor.$blockScrolling = Infinity
  2345. }
  2346. }
  2347. ]
  2348. }, livePropertyComponent
  2349. // {
  2350. // $cell: true,
  2351. // $type: "div",
  2352. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2353. // $components: []
  2354. // },
  2355. ]
  2356. }
  2357. ]
  2358. //$components:
  2359. }
  2360. }
  2361. let codeEditorWindow = {
  2362. $cell: true,
  2363. $type: "div",
  2364. _editorNode: '',
  2365. _method: { body: '' },
  2366. _methodName: '',
  2367. _tabIndex: '',
  2368. _getNodeMethods: function () {
  2369. let node = self.nodes[this._editorNode];
  2370. return node.methods
  2371. },
  2372. _getProtoNodeMethods: function () {
  2373. let node = self.nodes[this._editorNode];
  2374. let prototypeMethods = LCSEditor.getMethods.call(self, self.kernel, node.extendsID);
  2375. return prototypeMethods
  2376. },
  2377. id: "liveCodeEditor",
  2378. _setNode: function (node) {
  2379. this._editorNode = node;
  2380. this._method.body = ''
  2381. },
  2382. class: "codeEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left resizable",
  2383. // _getComplexProps: function(){
  2384. // let node = self.nodes[this._editorNode];
  2385. // let currentNode = document.querySelector('#currentNode');
  2386. // var props = {}
  2387. // if (currentNode !== null) {
  2388. // props = currentNode._getNodeComplexProperties();
  2389. // }
  2390. // return props
  2391. // },
  2392. // _listPropertyElement: function (m) {
  2393. // return {
  2394. // $type: "li",
  2395. // class: "mdc-list-item",
  2396. // $components: [{
  2397. // $type: "a",
  2398. // class: "mdc-list-item",
  2399. // $href: "#",
  2400. // $text: m[1].name,
  2401. // onclick: function (e) {
  2402. // this._method = {};
  2403. // this._methodName = m[1].name;
  2404. // this._method.body = m[1].rawValue
  2405. // this._method.type = "complexProperty"
  2406. // }
  2407. // }]
  2408. // }
  2409. // },
  2410. _listElement: function (m) {
  2411. return {
  2412. $type: "li",
  2413. class: "mdc-list-item",
  2414. $components: [{
  2415. $type: "a",
  2416. class: "mdc-list-item",
  2417. $href: "#",
  2418. $text: m[0],
  2419. onclick: function (e) {
  2420. let method = vwf.getMethod(this._editorNode, m[0]);
  2421. //document.querySelector('#aceEditor').
  2422. this._method = method;
  2423. this._methodName = m[0];
  2424. //self.currentNodeID = m.ID;
  2425. //document.querySelector('#currentNode')._setNode(m.ID);
  2426. }
  2427. }]
  2428. }
  2429. },
  2430. $update: function () {
  2431. this.$components = [
  2432. {
  2433. $type: "div",
  2434. class: "mdc-layout-grid__inner",
  2435. $components: [
  2436. {
  2437. $type: "div",
  2438. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2439. $components: [
  2440. {
  2441. $type: "h3",
  2442. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  2443. $text: this._editorNode
  2444. }
  2445. ]
  2446. },
  2447. {
  2448. $type: "div",
  2449. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1 tooltip",
  2450. $components: [
  2451. {
  2452. class: "tooltiptext",
  2453. $type: "span",
  2454. $text: "Update"
  2455. },
  2456. self.widgets.iconButton({
  2457. 'label': 'refresh',
  2458. "styleClass": "mdc-button--outlined",
  2459. // self.widgets.buttonStroked(
  2460. // {
  2461. // "label": "Update",
  2462. "onclick": function (e) {
  2463. let editor = document.querySelector("#aceEditor").env.editor;
  2464. let evalText = editor.getValue();
  2465. // if (this._method.type == 'complexProperty') {
  2466. // let propValue = evalText;
  2467. // try {
  2468. // //propValue = JSON.parse(propValue);
  2469. // self.kernel.setProperty(this._editorNode, this._methodName, propValue);
  2470. // } catch (e) {
  2471. // // restore the original value on error
  2472. // this.value = propValue;
  2473. // }
  2474. // } else {
  2475. // }
  2476. self.kernel.setMethod(this._editorNode, this._methodName,
  2477. { body: evalText, type: "application/javascript", parameters: this._method.parameters });
  2478. }
  2479. }
  2480. )]
  2481. },
  2482. {
  2483. $type: "div",
  2484. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1 tooltip",
  2485. $components: [
  2486. {
  2487. class: "tooltiptext",
  2488. $type: "span",
  2489. $text: "Call It"
  2490. },
  2491. self.widgets.iconButton({
  2492. 'label': 'play_arrow',
  2493. "styleClass": "mdc-button--outlined",
  2494. // self.widgets.buttonStroked(
  2495. // {
  2496. // "label": "Call",
  2497. "onclick": function (e) {
  2498. var params = [];
  2499. if (this._method.parameters) {
  2500. let paramsLength = this._method.parameters.length
  2501. if (paramsLength >= 1) {
  2502. let paramsVal = document.querySelector("#methodParams").value;
  2503. try {
  2504. params = JSON.parse(paramsVal);
  2505. //params.push(prmtr);
  2506. } catch (e) {
  2507. self.logger.error('Invalid Value');
  2508. }
  2509. }
  2510. };
  2511. let editor = document.querySelector("#aceEditor").env.editor;
  2512. let evalText = editor.getValue();
  2513. let allLines = editor.selection.doc.getAllLines();
  2514. let search = this._methodName+'(';
  2515. let findLine = Object.entries(allLines).filter(el=>el[1].includes(search))[0];
  2516. //TODO: temporal fix for recursive future call from the editor
  2517. if(findLine) {
  2518. if(findLine[1].includes(search)) {
  2519. let position = {
  2520. row: findLine[0],
  2521. column: 0
  2522. };
  2523. var Range = ace.require("ace/range").Range;
  2524. let tempString = "//CLICK FOR CALL AGAIN ";
  2525. if(findLine[1].includes(tempString)){
  2526. let newText = findLine[1].replace(tempString, "");
  2527. editor.session.replace(new Range(position.row, 0, position.row, Number.MAX_VALUE), newText);
  2528. self.kernel.setMethod(this._editorNode, this._methodName,
  2529. { body: editor.getValue(), type: "application/javascript", parameters: this._method.parameters });
  2530. } else if(findLine[1].includes("//")) { //startsWith
  2531. } else {
  2532. let newText = tempString + findLine[1];
  2533. editor.session.replace(new Range(position.row, 0, position.row, Number.MAX_VALUE), newText);
  2534. self.kernel.setMethod(this._editorNode, this._methodName,
  2535. { body: editor.getValue(), type: "application/javascript", parameters: this._method.parameters });
  2536. }
  2537. }
  2538. }
  2539. self.kernel.callMethod(this._editorNode, this._methodName, params);
  2540. }
  2541. })
  2542. ]
  2543. },
  2544. {
  2545. $type: "div",
  2546. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1 tooltip",
  2547. $components: [
  2548. {
  2549. class: "tooltiptext",
  2550. $type: "span",
  2551. $text: "Do It"
  2552. },
  2553. self.widgets.iconButton({
  2554. 'label': 'arrow_forward',
  2555. "styleClass": "mdc-button--outlined",
  2556. // self.widgets.buttonStroked(
  2557. // {
  2558. // "label": "Do It",
  2559. "onclick": function (e) {
  2560. let editor = document.querySelector("#aceEditor").env.editor;
  2561. LCSEditor.codeEditorDoit.call(self, editor, this._editorNode);
  2562. }
  2563. })
  2564. ]
  2565. },
  2566. {
  2567. $type: "div",
  2568. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1 tooltip",
  2569. $components: [
  2570. {
  2571. class: "tooltiptext",
  2572. $type: "span",
  2573. $text: "Print It"
  2574. },
  2575. self.widgets.iconButton({
  2576. 'label': 'details',
  2577. "styleClass": "mdc-button--outlined",
  2578. // self.widgets.buttonStroked(
  2579. // {
  2580. // "label": "Print It",
  2581. "onclick": function (e) {
  2582. let editor = document.querySelector("#aceEditor").env.editor;
  2583. LCSEditor.codeEditorPrintit.call(self, editor, this._editorNode);
  2584. }
  2585. })
  2586. ]
  2587. },
  2588. {
  2589. $type: "div",
  2590. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1 tooltip",
  2591. $components: [
  2592. {
  2593. class: "tooltiptext",
  2594. $type: "span",
  2595. $text: "Print It on Console"
  2596. },
  2597. self.widgets.iconButton({
  2598. 'label': 'code',
  2599. "styleClass": "mdc-button--outlined",
  2600. // self.widgets.buttonStroked(
  2601. // {
  2602. // "label": "Print It on Console",
  2603. "onclick": function (e) {
  2604. let editor = document.querySelector("#aceEditor").env.editor;
  2605. LCSEditor.codeEditorPrintitInDebugger.call(self, editor, this._editorNode);
  2606. }
  2607. })
  2608. ]
  2609. }
  2610. ]
  2611. },
  2612. {
  2613. $type: "div",
  2614. class: "mdc-layout-grid__inner",
  2615. $components: [
  2616. {
  2617. $type: "div",
  2618. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2619. style: "overflow-y: scroll; max-height: 400px;",
  2620. $components: [
  2621. {
  2622. $type: "div",
  2623. class: "mdc-list-group",
  2624. $components: [
  2625. {
  2626. $type: "h3",
  2627. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2628. $text: "Node methods"
  2629. },
  2630. {
  2631. $type: "ul",
  2632. class: "mdc-list",
  2633. $components: Object.entries(this._getNodeMethods()).map(this._listElement)
  2634. }, listDivider,
  2635. {
  2636. $type: "h3",
  2637. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2638. $text: "Proto methods"
  2639. },
  2640. {
  2641. $type: "ul",
  2642. class: "mdc-list",
  2643. $components: Object.entries(this._getProtoNodeMethods()).map(this._listElement)
  2644. }, listDivider,
  2645. {
  2646. $type: "h3",
  2647. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2648. $text: "Events"
  2649. }
  2650. // {
  2651. //
  2652. // $type: "ul",
  2653. // class: "mdc-list",
  2654. // $components: Object.entries(this._getComplexProps()).map(this._listPropertyElement)
  2655. // }
  2656. ]
  2657. }
  2658. ]
  2659. },
  2660. {
  2661. $type: "div",
  2662. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-9",
  2663. $components: [
  2664. {
  2665. class: "aceEditor",
  2666. id: "aceEditor",
  2667. $type: "div",
  2668. $text: this._method.body,
  2669. $init: function () {
  2670. LCSEditor.createAceEditor.call(self, this._editorNode, "aceEditor");
  2671. }
  2672. }
  2673. ]
  2674. }
  2675. ]
  2676. },
  2677. {
  2678. $type: "div",
  2679. class: "mdc-layout-grid__inner",
  2680. $components: [
  2681. {
  2682. $type: "div",
  2683. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2684. $components: [
  2685. {
  2686. $type: "span",
  2687. $text: "*"
  2688. }
  2689. ]
  2690. }
  2691. ]
  2692. },
  2693. { //params input
  2694. $type: "div",
  2695. class: "mdc-layout-grid__inner",
  2696. $components: [
  2697. {
  2698. $type: "div",
  2699. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2700. $components: [
  2701. self.widgets.inputTextFieldOutlined({
  2702. "id": 'methodName',
  2703. "label": "Method name",
  2704. "value": "newMethodName",
  2705. "change": function (e) {
  2706. let propValue = this.value;
  2707. try {
  2708. } catch (e) {
  2709. // restore the original value on error
  2710. }
  2711. }
  2712. })
  2713. ]
  2714. },
  2715. {
  2716. $type: "div",
  2717. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  2718. $components: [
  2719. self.widgets.inputTextFieldOutlined({
  2720. "id": 'methodParams',
  2721. "label": "Method parameters",
  2722. "value": JSON.stringify(this._method.parameters),
  2723. "change": function (e) {
  2724. let propValue = this.value;
  2725. try {
  2726. } catch (e) {
  2727. // restore the original value on error
  2728. }
  2729. }
  2730. })
  2731. ]
  2732. },
  2733. {
  2734. $type: "div",
  2735. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2736. $components: [
  2737. self.widgets.buttonStroked(
  2738. {
  2739. "label": "Create",
  2740. "onclick": function (e) {
  2741. let methodName = document.querySelector('#methodName').value;
  2742. //let methodParams = document.querySelector('#methodParams');
  2743. var params = [];
  2744. let body = '';
  2745. let paramsVal = document.querySelector("#methodParams").value;
  2746. if (paramsVal !== '') {
  2747. try {
  2748. params = JSON.parse(paramsVal);
  2749. //params.push(prmtr);
  2750. } catch (e) {
  2751. self.logger.error('Invalid Value');
  2752. }
  2753. }
  2754. self.kernel.createMethod(this._editorNode, methodName, params, body);
  2755. this._setNode(this._editorNode);
  2756. // let editor = document.querySelector("#aceEditor").env.editor;
  2757. // codeEditorDoit.call(self, editor, this._editorNode);
  2758. }
  2759. })
  2760. ]
  2761. }
  2762. ]
  2763. }
  2764. ]
  2765. //$components:
  2766. }
  2767. }
  2768. let propWindow = {
  2769. $cell: true,
  2770. $type: "div",
  2771. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2772. style: "overflow-y: scroll; max-height: 800px;",
  2773. $components: [
  2774. {
  2775. $type: "div",
  2776. class: "mdc-layout-grid__inner",
  2777. $components: [
  2778. {
  2779. $type: "div",
  2780. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2781. $components: [
  2782. nodesCell
  2783. ]
  2784. }
  2785. ]
  2786. }
  2787. // <button class="mdc-button">
  2788. // Flat button
  2789. // </button>
  2790. ]
  2791. }
  2792. let clientListCell = {
  2793. $cell: true,
  2794. $type: "div",
  2795. class: "mdc-list",
  2796. id: "clientsList",
  2797. _watchNodes: [],
  2798. _listElement: function (m) {
  2799. return {
  2800. $type: "a",
  2801. class: "mdc-list-item",
  2802. $href: "#",
  2803. $text: m.name,
  2804. onclick: function (e) {
  2805. //self.currentNodeID = m.ID;
  2806. //document.querySelector('#currentNode')._setNode(m.ID);
  2807. }
  2808. }
  2809. },
  2810. $init: function () {
  2811. var t = this;
  2812. setInterval(function () {
  2813. t._updateMe();
  2814. }, 1000);
  2815. },
  2816. _updateMe: function () {
  2817. let clientNodes = self.nodes["proxy/clients.vwf"];
  2818. if (clientNodes) this._watchNodes = self.nodes["proxy/clients.vwf"].children.slice();
  2819. },
  2820. $update: function () {
  2821. //this._clientNodes
  2822. this.$components = this._watchNodes.map(this._listElement)
  2823. }
  2824. }
  2825. //createCellWindow("clientsWindow", clientListCell, "Clients");
  2826. //createCellWindow("propWindow", propWindow, "Scene");
  2827. _self_.createCellWindow("codeEditorWindow", codeEditorWindow, "Code editor");
  2828. _self_.createCellWindow("propEditorWindow", propEditorWindow, "Prop editor");
  2829. let viewSceneProps = {
  2830. $cell: true,
  2831. $type: "div",
  2832. class: "propGrid mdc-layout-grid mdc-layout-grid--align-left",
  2833. //style: "overflow-y: scroll; max-height: 500px; overflow-x: hidden;",
  2834. $components: [
  2835. {
  2836. $type: "div",
  2837. class: "mdc-layout-grid__inner",
  2838. $components: [
  2839. {
  2840. $type: "div",
  2841. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2842. $components: [
  2843. nodesCell
  2844. ]
  2845. }]
  2846. }
  2847. ]
  2848. }
  2849. let sideBar = {
  2850. $cell: true,
  2851. $type: "div",
  2852. id: 'sideBar',
  2853. class: "sideBar mdc-top-app-bar--fixed-adjust",
  2854. _sideBarComponent: {},
  2855. _sideCurrentNode: '',
  2856. $init: function () {
  2857. this.style.visibility = 'hidden';
  2858. let fileName = 'appui_js';
  2859. let worldName = self.helpers.getRoot().root;//url.split('/')[0];
  2860. let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
  2861. userDB.get('worlds').get(worldName).get(fileName).once(res => {
  2862. this._importScript(res);
  2863. })
  2864. },
  2865. _importScript: function (sSrc, fOnload) {
  2866. var oScript = document.createElement("script");
  2867. oScript.type = "text\/javascript";
  2868. oScript.async = false;
  2869. //oScript.onerror = loadError;
  2870. if (fOnload) { oScript.onload = fOnload; }
  2871. oScript.text = sSrc;
  2872. //let sideBar = document.querySelector('#sideBar');
  2873. this.appendChild(oScript);
  2874. },
  2875. _getAppDef: async function () {
  2876. // let response = await fetch("/" + self.getRoot() + "/appui.js");
  2877. // let data = await response.text();
  2878. // //console.log(data)
  2879. // return data
  2880. },
  2881. $update: function () {
  2882. this.$components = [
  2883. {
  2884. $type: "button",
  2885. class: "mdc-button mdc-button--compact",
  2886. $text: "X",
  2887. onclick: function (e) {
  2888. document.querySelector('#sideBar').style.visibility = 'hidden';
  2889. this._sideBarComponent = Object.assign({}, {});
  2890. }
  2891. },
  2892. {
  2893. $type: "button",
  2894. class: "mdc-button mdc-button--compact",
  2895. $text: " | ",
  2896. onclick: function (e) {
  2897. if (document.querySelector('#currentNode'))
  2898. document.querySelector('#currentNode')._setNode(vwf.application())
  2899. }
  2900. },
  2901. this._sideBarComponent
  2902. ]
  2903. }
  2904. //$components: [this._sideComponents]
  2905. }
  2906. document.querySelector('#' + 'sideBar').$cell(sideBar)
  2907. let defaultApp = function () {
  2908. return {
  2909. $cell: true,
  2910. $type: "div",
  2911. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  2912. $components: [
  2913. {
  2914. $type: "div",
  2915. class: "mdc-layout-grid__inner",
  2916. $components: [
  2917. {
  2918. $type: "div",
  2919. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2920. $components: [
  2921. {
  2922. $type: "h3",
  2923. class: "mdc-typography--headline",
  2924. $text: "Application",
  2925. }
  2926. ]
  2927. }
  2928. ]
  2929. }
  2930. ]
  2931. }
  2932. }
  2933. let drawerCell = {
  2934. $cell: true,
  2935. $type: "div",
  2936. class: "mdc-drawer__content",
  2937. $components: [
  2938. {
  2939. $type: "nav",
  2940. class: "mdc-list",
  2941. $init: function () { },
  2942. $components: [
  2943. {
  2944. $type: "a",
  2945. class: "mdc-list-item mdc-list-item--activated",
  2946. $href: "#",
  2947. tabindex: "-1",
  2948. onclick: function (e) {
  2949. e.preventDefault();
  2950. let sideBar = document.querySelector('#sideBar');
  2951. try {
  2952. sideBar._sideBarComponent = createApp.call(self);
  2953. } catch (e) {
  2954. sideBar._sideBarComponent = defaultApp();
  2955. }
  2956. self.drawer.open = false//!self.drawer.open
  2957. //self.drawer.close();
  2958. document.querySelector('#sideBar').style.visibility = 'visible';
  2959. },
  2960. $components: [{
  2961. $type: "i",
  2962. class: "material-icons mdc-list-item__graphic",
  2963. 'aria-hidden': "true",
  2964. $text: "play_arrow"
  2965. },
  2966. {
  2967. $text: self.lang.t("App")
  2968. }]
  2969. },
  2970. {
  2971. $type: "a",
  2972. class: "mdc-list-item",
  2973. $href: "#",
  2974. tabindex: "-1",
  2975. onclick: function (e) {
  2976. e.preventDefault();
  2977. let sideBar = document.querySelector('#sideBar');
  2978. sideBar._sideBarComponent = viewSceneProps;
  2979. let currentNode = document.querySelector('#sideBar')._sideCurrentNode;
  2980. currentNode == '' ? document.querySelector('#sideBar')._sideCurrentNode = (vwf_view.kernel.find("", "/")[0]) :
  2981. document.querySelector('#sideBar')._sideCurrentNode = currentNode;
  2982. document.querySelector('#sideBar').style.visibility = 'visible';
  2983. self.drawer.open = !self.drawer.open
  2984. // let currentNode = document.querySelector('#currentNode')._currentNode;
  2985. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  2986. // document.querySelector('#currentNode')._setNode(currentNode);
  2987. },
  2988. $components: [{
  2989. $type: "i",
  2990. class: "material-icons mdc-list-item__graphic",
  2991. $text: "description"
  2992. },
  2993. {
  2994. $text: "Scene"
  2995. }
  2996. ]
  2997. },
  2998. {
  2999. $type: "a",
  3000. class: "mdc-list-item",
  3001. $href: "#",
  3002. tabindex: "-1",
  3003. onclick: function (e) {
  3004. e.preventDefault();
  3005. //self.currentNodeID = m.ID;
  3006. // document.querySelector('#clientsList')._setClientNodes(self.nodes["proxy/clients.vwf"]);
  3007. // document.querySelector('#clientsWindow').style.visibility = 'visible';
  3008. let sideBar = document.querySelector('#sideBar');
  3009. sideBar._sideBarComponent = createSettings;
  3010. self.drawer.open = !self.drawer.open
  3011. document.querySelector('#sideBar').style.visibility = 'visible';
  3012. },
  3013. $components: [{
  3014. $type: "i",
  3015. class: "material-icons mdc-list-item__graphic",
  3016. 'aria-hidden': "true",
  3017. $text: "create"
  3018. },
  3019. {
  3020. $text: "Create"
  3021. }]
  3022. },
  3023. {
  3024. $type: "a",
  3025. class: "mdc-list-item",
  3026. $href: "#",
  3027. tabindex: "-1",
  3028. onclick: function (e) {
  3029. e.preventDefault();
  3030. // var currentNode = document.querySelector('#currentNode')._currentNode;
  3031. // if (currentNode == '') {
  3032. // currentNode = vwf_view.kernel.find("", "/")[0];
  3033. // }
  3034. document.querySelector('#liveCodeEditor')._setNode(vwf_view.kernel.find("", "/")[0]);
  3035. //createAceEditor(self, currentNode);
  3036. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  3037. },
  3038. $components: [{
  3039. $type: "i",
  3040. class: "material-icons mdc-list-item__graphic",
  3041. 'aria-hidden': "true",
  3042. $text: "code"
  3043. },
  3044. {
  3045. $text: "Code editor"
  3046. }]
  3047. },
  3048. {
  3049. $type: "a",
  3050. class: "mdc-list-item",
  3051. $href: "#",
  3052. tabindex: "-1",
  3053. onclick: function (e) {
  3054. e.preventDefault();
  3055. //self.currentNodeID = m.ID;
  3056. // document.querySelector('#clientsList')._setClientNodes(self.nodes["proxy/clients.vwf"]);
  3057. // document.querySelector('#clientsWindow').style.visibility = 'visible';
  3058. let sideBar = document.querySelector('#sideBar');
  3059. sideBar._sideBarComponent = avatarSettings;
  3060. self.drawer.open = !self.drawer.open
  3061. document.querySelector('#sideBar').style.visibility = 'visible';
  3062. },
  3063. $components: [{
  3064. $type: "i",
  3065. class: "material-icons mdc-list-item__graphic",
  3066. 'aria-hidden': "true",
  3067. $text: "account_circle"
  3068. },
  3069. {
  3070. $text: "My Avatar"
  3071. }]
  3072. },
  3073. {
  3074. $type: "a",
  3075. class: "mdc-list-item",
  3076. $href: "#",
  3077. tabindex: "-1",
  3078. onclick: function (e) {
  3079. e.preventDefault();
  3080. //self.currentNodeID = m.ID;
  3081. // document.querySelector('#clientsList')._setClientNodes(self.nodes["proxy/clients.vwf"]);
  3082. let sideBar = document.querySelector('#sideBar');
  3083. sideBar._sideBarComponent = viewSettings;
  3084. self.drawer.open = !self.drawer.open
  3085. document.querySelector('#sideBar').style.visibility = 'visible';
  3086. },
  3087. $components: [{
  3088. $type: "i",
  3089. class: "material-icons mdc-list-item__graphic",
  3090. 'aria-hidden': "true",
  3091. $text: "settings"
  3092. },
  3093. {
  3094. $text: "Settings"
  3095. }]
  3096. },
  3097. {
  3098. $type: "a",
  3099. class: "mdc-list-item",
  3100. $href: "#",
  3101. tabindex: "-1",
  3102. onclick: function (e) {
  3103. e.preventDefault();
  3104. //self.currentNodeID = m.ID;
  3105. // document.querySelector('#clientsList')._setClientNodes(self.nodes["proxy/clients.vwf"]);
  3106. let sideBar = document.querySelector('#sideBar');
  3107. sideBar._sideBarComponent = loadSaveSettings;
  3108. if (document.querySelector('#loadSaveSettings')) {
  3109. //document.querySelector('#loadSaveSettings')._refresh();
  3110. //document.querySelector('#loadSaveSettings')._getStates();
  3111. }
  3112. //sideBar._sideBarComponent._getStates();
  3113. self.drawer.open = !self.drawer.open
  3114. document.querySelector('#sideBar').style.visibility = 'visible';
  3115. },
  3116. $components: [{
  3117. $type: "i",
  3118. class: "material-icons mdc-list-item__graphic",
  3119. 'aria-hidden': "true",
  3120. $text: "save"
  3121. },
  3122. {
  3123. $text: "Clone/Save"
  3124. }]
  3125. },
  3126. self.widgets.divider,
  3127. webrtcGUI,
  3128. self.widgets.divider,
  3129. self.widgets.headerH3("h3", "Users online", "userList mdc-list-group__subheader"),
  3130. clientListCell
  3131. //widgets.headerH3("h3", "WebRTC", "userList mdc-list-group__subheader"),
  3132. ]
  3133. }
  3134. // {
  3135. // $cell: true,
  3136. // $type: "div",
  3137. // class: "mdc-persistent-drawer__toolbar-spacer",
  3138. // },
  3139. // {
  3140. // $cell: true,
  3141. // $type: "div",
  3142. // class: "mdc-list-group",
  3143. // $components: [{
  3144. // $cell: true,
  3145. // $type: "nav",
  3146. // class: "mdc-list",
  3147. // $components: [
  3148. // ]
  3149. // }]
  3150. // }
  3151. ]
  3152. };
  3153. // <div class="mdc-form-field">
  3154. // <input type="checkbox" id="input">
  3155. // <label for="input">Input Label</label>
  3156. // </div>
  3157. document.querySelector("#drawer").$cell({
  3158. $cell: true,
  3159. $type: "aside",
  3160. class: "mdc-drawer mdc-drawer--modal",
  3161. $init: function () {
  3162. let elScrim = document.createElement("div");
  3163. elScrim.classList.add("mdc-drawer-scrim");
  3164. this.after(elScrim);
  3165. self.drawer = new mdc.drawer.MDCDrawer(this);
  3166. },
  3167. $components: [
  3168. {
  3169. $type: "div",
  3170. class: "mdc-drawer__header",
  3171. $components: [
  3172. {
  3173. $type: "h3",
  3174. class: "mdc-drawer__title",
  3175. $text: self.lang.t("home")
  3176. },
  3177. {
  3178. $type: "h6",
  3179. class: "mdc-drawer__subtitle",
  3180. $text: "menu"
  3181. }
  3182. ]
  3183. },
  3184. // {
  3185. // $type: "button"
  3186. // },
  3187. drawerCell]
  3188. }
  3189. );
  3190. let toolbar = {
  3191. $cell: true,
  3192. $type: "div",
  3193. class: "mdc-top-app-bar__row",
  3194. $components: [{
  3195. $type: "section",
  3196. class: "mdc-top-app-bar__section mdc-top-app-bar__section--align-start",
  3197. $components: [
  3198. {
  3199. $type: "button",
  3200. type: "button",
  3201. class: "mdc-icon-button material-icons mdc-top-app-bar__navigation-icon",
  3202. $text: "menu"
  3203. },
  3204. {
  3205. $type: "span",
  3206. class: "mdc-top-app-bar__title catalog-title",
  3207. $text: "LiveCoding.space"
  3208. },
  3209. {
  3210. $type: "div",
  3211. class: "mdc-menu-anchor",
  3212. $components: [
  3213. self.widgets.icontoggle({
  3214. 'styleClass': "mdc-top-app-bar__action-item",
  3215. 'id': "qrcodeIcon",
  3216. 'label': 'select',
  3217. 'on': JSON.stringify({ "content": "qr_code_2", "label": "qr" }),
  3218. 'off': JSON.stringify({ "content": "qr_code_2", "label": "qr" }),
  3219. 'state': false,
  3220. 'init': function () {
  3221. this._comp = mdc.iconButton.MDCIconButtonToggle.attachTo(this);
  3222. this.addEventListener('MDCIconButtonToggle:change', (e) => {
  3223. if(self.qrcodedialog){
  3224. self.qrcodedialog.open();
  3225. }
  3226. });
  3227. }
  3228. }),
  3229. // {
  3230. // $type: "a",
  3231. // class: "mdc-icon-button material-icons mdc-top-app-bar__action-item",
  3232. // id: "toggleCreate",
  3233. // $text: "apps",
  3234. // 'aria-label': "More"
  3235. // },
  3236. // {
  3237. // $type: "div",
  3238. // class: "mdc-menu mdc-menu-surface",
  3239. // "tabindex": "-1",
  3240. // id: "create-menu",
  3241. // $init: function () {
  3242. // //var menuEl = document.querySelector('#demo-menu');
  3243. // var menu = new mdc.menu.MDCMenu(this);
  3244. // var toggle = document.querySelector('#toggleCreate');
  3245. // toggle.addEventListener('click', function () {
  3246. // menu.open = !menu.open;
  3247. // });
  3248. // },
  3249. // style: "transform-origin: right top 0px; right: 0px; top: 0px;",
  3250. // $components: [
  3251. // {
  3252. // $type: "ul",
  3253. // class: "mdc-menu__items mdc-list",
  3254. // role: "menu",
  3255. // 'aria-hidden': "true",
  3256. // // style: "transform: scale(1, 1);",
  3257. // $components: [
  3258. // {
  3259. // $type: "li",
  3260. // class: "mdc-list-item",
  3261. // role: "menuitem",
  3262. // tabindex: "0",
  3263. // $text: "Apps"
  3264. // }
  3265. // ]
  3266. // }
  3267. // ]
  3268. // }
  3269. ]
  3270. }
  3271. ]
  3272. },
  3273. {
  3274. $type: "section",
  3275. class: "mdc-top-app-bar__section mdc-top-app-bar__section--align-end",
  3276. $components: [
  3277. {
  3278. $type: "a",
  3279. href: "#",
  3280. class: "mdc-icon-button menuItem mdc-top-app-bar__action-item",
  3281. $text: "EN",
  3282. onclick: function () {
  3283. //self.lang.changeLanguageTo('en')
  3284. localStorage.setItem('krestianstvo_locale', 'en');
  3285. window.location.reload(true);
  3286. }
  3287. },
  3288. {
  3289. $type: "a",
  3290. href: "#",
  3291. class: "mdc-icon-button menuItem mdc-top-app-bar__action-item",
  3292. $text: "RU",
  3293. onclick: function () {
  3294. //self.lang.changeLanguageTo('ru')
  3295. localStorage.setItem('krestianstvo_locale', 'ru');
  3296. window.location.reload(true);
  3297. }
  3298. },
  3299. {
  3300. $type: "a",
  3301. href: "#",
  3302. class: "material-icons mdc-icon-button mdc-top-app-bar__action-item",
  3303. $text: "help",
  3304. 'aria-label': "Help",
  3305. onclick: function (e) {
  3306. e.preventDefault();
  3307. console.log("TODO: help window")
  3308. }
  3309. }
  3310. ]
  3311. }
  3312. ]
  3313. };
  3314. document.querySelector("#toolbar").$cell({
  3315. $cell: true,
  3316. $type: "div",
  3317. class: "drawer-frame-app-content",
  3318. $components: [
  3319. {
  3320. $type: "header",
  3321. class: "mdc-top-app-bar drawer-top-app-bar",
  3322. $init: function () {
  3323. const topAppBar = new mdc.topAppBar.MDCTopAppBar.attachTo(this);
  3324. topAppBar.listen('MDCTopAppBar:nav', () => {
  3325. self.drawer.open = !self.drawer.open;
  3326. });
  3327. },
  3328. $components: [
  3329. toolbar
  3330. ]
  3331. }
  3332. ]
  3333. }
  3334. );
  3335. // var toggleNodes = document.querySelectorAll('.mdc-icon-button');
  3336. // toggleNodes.forEach(el => {
  3337. // mdc.iconButton.MDCIconButtonToggle.attachTo(el);
  3338. // });
  3339. //==============
  3340. },
  3341. createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  3342. childSource, childType, childIndex, childName, callback /* ( ready ) */) {
  3343. // var nodeIDAttribute = $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  3344. // var childIDAttribute = $.encoder.encodeForHTMLAttribute("id", childID, true);
  3345. // var childIDAlpha = $.encoder.encodeForAlphaNumeric(childID);
  3346. let self = this;
  3347. var kernel = this.kernel;
  3348. var parent = this.nodes[nodeID];
  3349. var node = this.nodes[childID] = {
  3350. children: [],
  3351. properties: [],
  3352. events: {},
  3353. methods: {},
  3354. parent: parent,
  3355. parentID: nodeID,
  3356. ID: childID,
  3357. extendsID: childExtendsID,
  3358. implementsIDs: childImplementsIDs,
  3359. source: childSource,
  3360. name: childName,
  3361. };
  3362. if (parent) {
  3363. parent.children.push(node);
  3364. }
  3365. if (childID == vwf_view.kernel.find("", "/")[0] && childExtendsID && this.kernel.test(childExtendsID,
  3366. "self::element(*,'proxy/aframe/ascene.vwf')", childExtendsID)) {
  3367. this.scenes[childID] = node;
  3368. }
  3369. let nodeCell = document.querySelector("#currentNode");
  3370. if (nodeCell !== null) {
  3371. if (nodeCell._currentNode === nodeID) {
  3372. nodeCell._getChildNodes();
  3373. }
  3374. }
  3375. if (nodeID === this.kernel.application()) {
  3376. // document.querySelector('a-scene').classList.add("mdc-toolbar-fixed-adjust");
  3377. //document.querySelector('body').classList.add("editor-body", "mdc-typography");
  3378. }
  3379. },
  3380. createdProperty: function (nodeID, propertyName, propertyValue) {
  3381. return this.initializedProperty(nodeID, propertyName, propertyValue);
  3382. },
  3383. initializedProperty: function (nodeID, propertyName, propertyValue) {
  3384. var node = this.nodes[nodeID];
  3385. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  3386. var property = node.properties[propertyName] = LCSEditor.createProperty.call(this, node, propertyName, propertyValue);
  3387. node.properties.push(property);
  3388. let nodeCell = document.querySelector("#currentNode");
  3389. if (nodeCell !== null) {
  3390. if (nodeCell._currentNode === nodeID) {
  3391. nodeCell._getNodeProperties();
  3392. }
  3393. }
  3394. },
  3395. deletedNode: function (nodeID) {
  3396. var node = this.nodes[nodeID];
  3397. node.parent.children.splice(node.parent.children.indexOf(node), 1);
  3398. delete this.nodes[nodeID];
  3399. let nodeCell = document.querySelector("#currentNode");
  3400. if (nodeCell) {
  3401. if (nodeCell._currentNode !== "") {
  3402. if (nodeCell._currentNode !== nodeID) {
  3403. //&& (this.nodes[nodeID] !== undefined)
  3404. nodeCell._getChildNodes();
  3405. } else {
  3406. nodeCell._setNode(vwf_view.kernel.find("", "/")[0]);
  3407. nodeCell._getChildNodes();
  3408. }
  3409. }
  3410. }
  3411. },
  3412. //addedChild: [ /* nodeID, childID, childName */ ],
  3413. //removedChild: [ /* nodeID, childID */ ],
  3414. satProperty: function (nodeID, propertyName, propertyValue) {
  3415. var node = this.nodes[nodeID];
  3416. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  3417. // It is possible for a property to have satProperty called for it without ever getting an
  3418. // initializedProperty (if that property delegated to itself or another on replication)
  3419. // Catch that case here and create the property
  3420. if (!node.properties[propertyName]) {
  3421. var property = node.properties[propertyName] = LCSEditor.createProperty.call(this, node, propertyName, propertyValue);
  3422. node.properties.push(property);
  3423. }
  3424. try {
  3425. propertyValue = LCSEditor.utility.transform(propertyValue, LCSEditor.utility.transforms.transit);
  3426. node.properties[propertyName].value = JSON.stringify(propertyValue);
  3427. node.properties[propertyName].rawValue = propertyValue;
  3428. } catch (e) {
  3429. this.logger.warnx("satProperty", nodeID, propertyName, propertyValue,
  3430. "stringify error:", e.message);
  3431. node.properties[propertyName].value = propertyValue;
  3432. }
  3433. let nodeCell = document.querySelector('#currentNode');
  3434. if (nodeCell !== null) {
  3435. if (nodeCell._currentNode == nodeID && propertyName == 'isPlaying') {
  3436. console.log('SET PLAY !!!');
  3437. let compID = 'soundStopStartSwitch-' + nodeID;
  3438. let playSwitch = document.querySelector("[id='" + compID + "']");
  3439. if (playSwitch) {
  3440. // const mycomp = new mdc.iconToggle.MDCIconToggle(playSwitch); //new mdc.select.MDCIconToggle
  3441. playSwitch._comp.on = propertyValue;
  3442. }
  3443. }
  3444. }
  3445. if (nodeCell !== null) {
  3446. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  3447. console.log('EDIT !!!')
  3448. }
  3449. }
  3450. let propCell = document.querySelector("#currentNode #prop-" + propertyName);
  3451. let propSlider = document.querySelector("#currentNode #prop-slider-" + propertyName);
  3452. if (propCell !== null) {
  3453. if (propCell._currentNode == nodeID) {
  3454. propCell.value = node.properties[propertyName].getValue();
  3455. }
  3456. }
  3457. if (propSlider !== null) {
  3458. if (propSlider._currentNode == nodeID) {
  3459. //const propSliderComp = new new mdc.slider.MDCSlider(propSlider);
  3460. propSlider._comp.value = node.properties[propertyName].getValue();
  3461. }
  3462. }
  3463. },
  3464. //gotProperty: [ /* nodeID, propertyName, propertyValue */ ],
  3465. gotProperty: function (nodeID, propertyName, propertyValue) {
  3466. var node = this.nodes[nodeID];
  3467. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  3468. let nodeCell = document.querySelector('#currentNode');
  3469. if (nodeCell !== null) {
  3470. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  3471. let gizmoChild = node.children.filter(el=>el.ID.includes('gizmo'));
  3472. if (gizmoChild.length > 0) {
  3473. let editCheckBox = document.querySelector("#currentNode #editnode");
  3474. if (editCheckBox) {
  3475. let mdcSwitch = editCheckBox._switch;
  3476. if (mdcSwitch) {
  3477. mdcSwitch.checked = propertyValue
  3478. }
  3479. }
  3480. console.log('EDIT !!! is ' + propertyValue)
  3481. }
  3482. }
  3483. }
  3484. },
  3485. createdMethod: function (nodeID, methodName, methodParameters, methodBody) {
  3486. var node = this.nodes[nodeID];
  3487. if (node) {
  3488. node.methods[methodName] = methodParameters;
  3489. }
  3490. },
  3491. //calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {
  3492. //},
  3493. createdEvent: function (nodeID, eventName, eventParameters) {
  3494. var node = this.nodes[nodeID];
  3495. if (node) {
  3496. node.events[eventName] = eventParameters;
  3497. }
  3498. },
  3499. firedEvent: function (nodeID, eventName, eventParameters) {
  3500. let self = this;
  3501. var node = this.nodes[nodeID];
  3502. if (node) {
  3503. if (eventName == 'printEvent'){
  3504. var clientThatSatProperty = self.kernel.client();
  3505. var me = self.kernel.moniker();
  3506. // If the transform property was initially updated by this view....
  3507. if ( clientThatSatProperty == me) {
  3508. let editor = document.querySelector("#aceEditor").env.editor;
  3509. if(editor){
  3510. var cursorPosition = editor.getCursorPosition();
  3511. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3512. if (selectedText !== "") {
  3513. cursorPosition = editor.selection.getRange().end;
  3514. }
  3515. let data = eventParameters[0];//JSON.stringify(eventParameters[0]);
  3516. editor.session.insert(cursorPosition, data);
  3517. }
  3518. //console.log(eventParameters);
  3519. }
  3520. }
  3521. if (eventName == "printIt") {
  3522. var clientThatSatProperty = self.kernel.client();
  3523. var me = self.kernel.moniker();
  3524. // If the transform property was initially updated by this view....
  3525. if (clientThatSatProperty == me) {
  3526. let selectedText = eventParameters[0];
  3527. let printText = _app.helpers.replaceSubStringALL(selectedText, 'this', 'me');
  3528. if (!self.nodes[nodeID].liveBindings) {
  3529. self.nodes[nodeID].liveBindings = {}
  3530. }
  3531. //let bindObject = self.nodes[nodeID].liveBindings;
  3532. //let bindString = 'vwf.views["vwf/view/aframe"].nodes["' + nodeID + '"].liveBindings';
  3533. let bindString = 'vwf.views["/drivers/view/editor"].nodes["' + nodeID + '"].liveBindings';
  3534. let sender = JSON.stringify(eventParameters[1]);
  3535. let scriptText = 'let binding = ' + bindString + '; binding.me = this; binding.sender = ' + sender + '; lively.vm.syncEval("var print = ' + printText + '",{topLevelVarRecorder: binding});';
  3536. vwf_view.kernel.execute(nodeID, scriptText);
  3537. }
  3538. }
  3539. }
  3540. },
  3541. executed: function (nodeID, scriptText, scriptType) {
  3542. let self = this;
  3543. let node = this.nodes[nodeID];
  3544. if (!(node)) {
  3545. return;
  3546. }
  3547. if (scriptText.includes('var print')) {
  3548. let print = self.nodes[nodeID].liveBindings.print;
  3549. let me = self.kernel.moniker();
  3550. let sender = self.nodes[nodeID].liveBindings.sender;
  3551. if (me == sender) {
  3552. let data = JSON.stringify(print); //lively.lang.obj.inspect(print);
  3553. self.kernel.fireEvent(nodeID, "printEvent", [data]);
  3554. }
  3555. }
  3556. // var nodeScript = {
  3557. // text: scriptText,
  3558. // type: scriptType,
  3559. // };
  3560. // if ( !this.allScripts[ nodeID ] ) {
  3561. // var nodeScripts = new Array();
  3562. // nodeScripts.push(nodeScript);
  3563. // this.allScripts[ nodeID ] = nodeScripts;
  3564. // }
  3565. // else {
  3566. // this.allScripts[ nodeID ].push(nodeScript);
  3567. // }
  3568. },
  3569. //ticked: [ /* time */ ],
  3570. });
  3571. }
  3572. /////////Functions/////
  3573. createCellWindow(elementID, cellNode, title) {
  3574. document.querySelector('#' + elementID).$cell({
  3575. $cell: true,
  3576. $type: "div",
  3577. id: elementID,
  3578. style: 'position: absolute;',
  3579. class: 'draggable',
  3580. $init: function () {
  3581. // let draggie = new Draggabilly('.draggable', {
  3582. // handle: '.handle',
  3583. // containment: true
  3584. // });
  3585. // get all draggie elements
  3586. var draggableElems = document.querySelectorAll('.draggable');
  3587. // array of Draggabillies
  3588. var draggies = []
  3589. // init Draggabillies
  3590. for (var i = 0, len = draggableElems.length; i < len; i++) {
  3591. var draggableElem = draggableElems[i];
  3592. var draggie = new Draggabilly(draggableElem, {
  3593. handle: '.handle'
  3594. //containment: true
  3595. });
  3596. draggies.push(draggie);
  3597. }
  3598. this.style.visibility = 'hidden';
  3599. },
  3600. $components: [
  3601. {
  3602. $type: "div",
  3603. class: "handle"
  3604. },
  3605. {
  3606. $type: "button",
  3607. class: "mdc-button mdc-button--compact",
  3608. $text: "X",
  3609. onclick: function (e) {
  3610. //self.currentNodeID = m.ID;
  3611. if( elementID == 'codeEditorWindow'){
  3612. //self.nodes[currentNode].liveBindings = {};
  3613. }
  3614. document.querySelector('#' + elementID).style.visibility = 'hidden';
  3615. }
  3616. },
  3617. {
  3618. $type: "span",
  3619. class: "mdc-typography--button",
  3620. $text: title
  3621. },
  3622. cellNode,
  3623. {
  3624. $type: "div",
  3625. class: "handle",
  3626. style: "height: 10px; width: inherit;",
  3627. //$text: "sdfsdf"
  3628. }
  3629. // { $text: "23423"}
  3630. ]
  3631. }
  3632. )
  3633. }
  3634. // -- getChildByName --------------------------------------------------------------------
  3635. static getChildByName(node, childName) {
  3636. var childNode = undefined;
  3637. for (var i = 0; i < node.children.length && childNode === undefined; i++) {
  3638. if (node.children[i].name == childName) {
  3639. childNode = node.children[i];
  3640. }
  3641. }
  3642. return childNode;
  3643. }
  3644. // -- viewScript ------------------------------------------------------------------------
  3645. static createAceEditor(nodeID, elID) {
  3646. let self = this;
  3647. var editor = self.ace.edit(elID);
  3648. editor.setTheme("ace/theme/monokai");
  3649. editor.setFontSize(20);
  3650. editor.getSession().setMode("ace/mode/javascript");
  3651. editor.commands.addCommand({
  3652. name: "doit",
  3653. bindKey: { win: "Ctrl-e", mac: "Command-e" },
  3654. exec: function () {
  3655. LCSEditor.codeEditorDoit.call(self, editor, nodeID);
  3656. }
  3657. });
  3658. editor.commands.addCommand({
  3659. name: "printit",
  3660. bindKey: { win: "Ctrl-b", mac: "Command-b" },
  3661. exec: function () {
  3662. LCSEditor.codeEditorPrintit.call(self, editor, nodeID);
  3663. }
  3664. });
  3665. return editor;
  3666. }
  3667. static isAFrameComponent(nodeID) {
  3668. let self = this;
  3669. let node = self.nodes[nodeID];
  3670. let nodeProtos = LCSEditor.getPrototypes(self.kernel, node.extendsID);
  3671. if (nodeProtos.includes('proxy/aframe/componentNode.vwf')) {
  3672. return true
  3673. }
  3674. return false
  3675. }
  3676. static isAFrameEntity(nodeID) {
  3677. let self = this;
  3678. let node = self.nodes[nodeID];
  3679. let nodeProtos = LCSEditor.getPrototypes(self.kernel, node.extendsID);
  3680. if (nodeProtos.includes('proxy/aframe/node.vwf')) {
  3681. return true
  3682. }
  3683. return false
  3684. }
  3685. static getPrototypes(kernel, extendsID) {
  3686. var prototypes = [];
  3687. var id = extendsID;
  3688. while (id !== undefined) {
  3689. prototypes.push(id);
  3690. id = kernel.prototype(id);
  3691. }
  3692. return prototypes;
  3693. }
  3694. static createProperty(node, propertyName, propertyValue) {
  3695. var property = {
  3696. name: propertyName,
  3697. rawValue: propertyValue,
  3698. value: undefined,
  3699. getValue: function () {
  3700. var propertyVal;
  3701. if (this.value == undefined) {
  3702. try {
  3703. propertyVal = LCSEditor.utility.transform(this.rawValue, LCSEditor.utility.transforms.transit);
  3704. this.value = JSON.stringify(propertyVal);
  3705. } catch (e) {
  3706. this.logger.warnx("createdProperty", nodeID, this.propertyName, this.rawValue,
  3707. "stringify error:", e.message);
  3708. this.value = this.rawValue;
  3709. }
  3710. }
  3711. return this.value;
  3712. }
  3713. };
  3714. return property;
  3715. }
  3716. static getProperties(kernel, extendsID) {
  3717. var pTypes = LCSEditor.getPrototypes(kernel, extendsID);
  3718. var pProperties = {};
  3719. if (pTypes) {
  3720. for (var i = 0; i < pTypes.length; i++) {
  3721. var nd = this.nodes[pTypes[i]];
  3722. if (nd && nd.properties) {
  3723. for (var key in nd.properties) {
  3724. pProperties[key] = { "prop": nd.properties[key], "prototype": pTypes[i] };
  3725. }
  3726. }
  3727. }
  3728. }
  3729. return pProperties;
  3730. }
  3731. static getChildren(kernel, extendsID) {
  3732. var pTypes = LCSEditor.getPrototypes(kernel, extendsID);
  3733. var pChildren = {};
  3734. if (pTypes) {
  3735. for (var i = 0; i < pTypes.length; i++) {
  3736. var nd = this.nodes[pTypes[i]];
  3737. if (nd && nd.children) {
  3738. for (var key in nd.children) {
  3739. pChildren[key] = nd.children[key];
  3740. }
  3741. }
  3742. }
  3743. }
  3744. return pChildren;
  3745. }
  3746. static getEvents(kernel, extendsID) {
  3747. var pTypes = LCSEditor.getPrototypes(kernel, extendsID);
  3748. var events = {};
  3749. if (pTypes) {
  3750. for (var i = 0; i < pTypes.length; i++) {
  3751. var nd = this.nodes[pTypes[i]];
  3752. if (nd && nd.events) {
  3753. for (var key in nd.events) {
  3754. events[key] = nd.events[key];
  3755. }
  3756. }
  3757. }
  3758. }
  3759. return events;
  3760. }
  3761. static getMethods(kernel, extendsID) {
  3762. var pTypes = LCSEditor.getPrototypes(kernel, extendsID);
  3763. var methods = {};
  3764. if (pTypes) {
  3765. for (var i = 0; i < pTypes.length; i++) {
  3766. var nd = this.nodes[pTypes[i]];
  3767. if (nd && nd.methods) {
  3768. for (var key in nd.methods) {
  3769. methods[key] = nd.methods[key];
  3770. }
  3771. }
  3772. }
  3773. }
  3774. return methods;
  3775. }
  3776. // -- Show Code Editor tab
  3777. static codeEditorDoit(editor, nodeID) {
  3778. let self = this;
  3779. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3780. if (selectedText == "") {
  3781. var currline = editor.getSelectionRange().start.row;
  3782. var selectedText = editor.session.getLine(currline);
  3783. }
  3784. //console.log(selectedText);
  3785. //var sceneID = self.kernel.application();
  3786. vwf_view.kernel.execute(nodeID, selectedText);
  3787. }
  3788. static codeEditorPrintitInDebugger(editor, nodeID) {
  3789. let self = this;
  3790. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3791. if (selectedText == "") {
  3792. var currline = editor.getSelectionRange().start.row;
  3793. var selectedText = editor.session.getLine(currline);
  3794. }
  3795. let scriptText = 'console.log(' + selectedText + ');'
  3796. self.kernel.execute(nodeID, scriptText);
  3797. }
  3798. static codeEditorPrintit(editor, nodeID) {
  3799. let self = this;
  3800. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3801. if (selectedText == "") {
  3802. var currline = editor.getSelectionRange().start.row;
  3803. var selectedText = editor.session.getLine(currline);
  3804. }
  3805. let me = self.kernel.moniker();
  3806. vwf_view.kernel.fireEvent(nodeID, 'printIt', [selectedText, me]);
  3807. }
  3808. static codeEditorPrintitConsole (editor, nodeID) {
  3809. let self = this;
  3810. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3811. if (selectedText == "") {
  3812. var currline = editor.getSelectionRange().start.row;
  3813. var selectedText = editor.session.getLine(currline);
  3814. }
  3815. let scriptText = 'console.log(' + selectedText + ');'
  3816. self.kernel.execute(nodeID, scriptText);
  3817. }
  3818. }
  3819. LCSEditor.utility = new Utility();
  3820. export { LCSEditor as default}