editor-new.js 197 KB

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