editor.js 225 KB

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