editor.js 256 KB

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