editor-new.js 197 KB

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