editor.js 244 KB

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