editor.js 225 KB

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