editor.js 220 KB

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