editor.js 220 KB

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