editor-new.js 196 KB

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