editor-new.js 194 KB

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