editor-new.js 194 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365
  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. let propValue = this.value;
  1020. try {
  1021. propValue = JSON.parse(propValue);
  1022. self.kernel.setProperty(this._currentNode, this._prop.name, propValue);
  1023. } catch (e) {
  1024. // restore the original value on error
  1025. this.value = propValue;
  1026. }
  1027. }
  1028. })
  1029. ]
  1030. }
  1031. ]
  1032. }
  1033. ]
  1034. }
  1035. }
  1036. }
  1037. let propertiesCell = function (m) {
  1038. var editComponents = [{}, {}];
  1039. // fullWidth:
  1040. // fullHeight:
  1041. // xoffset:
  1042. // yoffset:
  1043. // width:
  1044. // height:
  1045. let sliderPropNames = ['width', 'height', 'depth', 'fullWidth', 'fullHeight', 'xoffset', 'yoffset', 'subcamWidth', 'subcamHeight'];
  1046. let sliderProps = {
  1047. 'width': {
  1048. min: 0,
  1049. max: 30
  1050. },
  1051. 'height': {
  1052. min: 0,
  1053. max: 30
  1054. },
  1055. 'depth': {
  1056. min: 0,
  1057. max: 30
  1058. },
  1059. 'fullWidth': {
  1060. min: 0,
  1061. max: 5000,
  1062. step: 10
  1063. },
  1064. 'fullHeight': {
  1065. min: 0,
  1066. max: 5000,
  1067. step: 10
  1068. },
  1069. 'xoffset': {
  1070. min: -10000,
  1071. max: 10000,
  1072. step: 10
  1073. },
  1074. 'yoffset': {
  1075. min: -10000,
  1076. max: 10000,
  1077. step: 10
  1078. },
  1079. 'subcamWidth': {
  1080. min: 0,
  1081. max: 5000,
  1082. step: 10
  1083. },
  1084. 'subcamHeight': {
  1085. min: 0,
  1086. max: 5000,
  1087. step: 10
  1088. }
  1089. }
  1090. if (sliderPropNames.includes(m.name)) {
  1091. let currenValue = JSON.parse(m.getValue());
  1092. var sliderComponent = self.widgets.sliderContinuous({
  1093. 'id': 'prop-slider-' + m.name,
  1094. 'label': 'Slider',
  1095. 'min': sliderProps[m.name].min,
  1096. 'max': sliderProps[m.name].max,
  1097. 'step': sliderProps[m.name].step ? sliderProps[m.name].step : 0.1,
  1098. 'value': currenValue,
  1099. 'init': function () {
  1100. const myEl = this;
  1101. var continuousSlider = new mdc.slider.MDCSlider(myEl);
  1102. this._comp = continuousSlider;
  1103. continuousSlider.listen('MDCSlider:input', function (e) {
  1104. // console.log(continuousSlider.value)
  1105. let myEl = e.currentTarget;
  1106. // let prop = myEl._prop.body;
  1107. //document.querySelector('#propAceEditor').env.editor.setValue(prop);
  1108. self.kernel.setProperty(myEl._currentNode, m.name, continuousSlider.value);
  1109. //continuousValue.textContent = continuousSlider.value;
  1110. });
  1111. continuousSlider.listen('MDCSlider:change', function (e) {
  1112. //console.log(continuousSlider.value);
  1113. let myEl = e.currentTarget;
  1114. // let prop = myEl._prop.body;
  1115. //document.querySelector('#propAceEditor').env.editor.setValue(prop);
  1116. self.kernel.setProperty(myEl._currentNode, m.name, continuousSlider.value);
  1117. //continuousCommittedValue.textContent = continuousSlider.value;
  1118. })
  1119. }
  1120. })
  1121. } else {
  1122. sliderComponent = {}
  1123. }
  1124. if (m.name.indexOf("semantics") > -1) { }
  1125. else if (m.name.indexOf("grammar") > -1) { }
  1126. else if (m.name.indexOf("ohm") > -1) {
  1127. editComponents = [
  1128. {
  1129. $type: "div",
  1130. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  1131. $components: [
  1132. {
  1133. $type: "button",
  1134. class: "mdc-button",
  1135. $text: "Edit", //edit grammar
  1136. onclick: function (e) {
  1137. var currentNode = document.querySelector('#currentNode')._currentNode;
  1138. if (currentNode == '') {
  1139. currentNode = vwf_view.kernel.find("", "/")[0];
  1140. }
  1141. let editor = document.querySelector('#livePropEditor');
  1142. editor._setNode(currentNode);
  1143. editor._propName = m.name;
  1144. editor._prop = { body: m.rawValue, type: 'complex' }
  1145. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  1146. }
  1147. }
  1148. ]
  1149. },
  1150. {
  1151. $type: "div",
  1152. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  1153. $components: []
  1154. }
  1155. ]
  1156. } else {
  1157. editComponents = [
  1158. {
  1159. $type: "div",
  1160. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  1161. $components: [
  1162. sliderComponent,
  1163. {
  1164. class: "mdc-text-field prop-mdc-text-field",
  1165. $type: "div",
  1166. $components: [
  1167. self.widgets.inputTextFieldStandart({
  1168. "id": "prop-" + m.name,
  1169. "label": m.name,
  1170. "value": m.getValue(),
  1171. "change": function (e) {
  1172. let propValue = this.value;
  1173. try {
  1174. propValue = JSON.parse(propValue);
  1175. self.kernel.setProperty(this._currentNode, m.name, propValue);
  1176. } catch (e) {
  1177. // restore the original value on error
  1178. this.value = propValue;
  1179. }
  1180. }
  1181. })
  1182. ]
  1183. }
  1184. ]
  1185. },
  1186. {
  1187. $type: "div",
  1188. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  1189. $components: [
  1190. {
  1191. $type: "button",
  1192. class: "mdc-button mdc-button--compact",
  1193. $text: "^", //edit grammar
  1194. onclick: function (e) {
  1195. var currentNode = document.querySelector('#currentNode')._currentNode;
  1196. if (currentNode == '') {
  1197. currentNode = vwf_view.kernel.find("", "/")[0];
  1198. }
  1199. let editor = document.querySelector('#livePropEditor');
  1200. editor._setNode(currentNode);
  1201. editor._propName = m.name;
  1202. editor._prop = { body: m.getValue(), type: 'simple' }
  1203. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  1204. }
  1205. }
  1206. ]
  1207. }
  1208. ];
  1209. }
  1210. return {
  1211. $type: "div",
  1212. class: "mdc-layout-grid__inner",
  1213. $components: [
  1214. {
  1215. $type: "div",
  1216. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1217. $components: [
  1218. { $text: m.name }
  1219. ]
  1220. },
  1221. {
  1222. $type: "div",
  1223. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1224. },
  1225. editComponents[0],
  1226. editComponents[1]
  1227. ]
  1228. }
  1229. }
  1230. let nodeLink = function (m) {
  1231. var myClass = "nodeItem";
  1232. let myAvatarName = 'avatar-' + self.kernel.moniker();
  1233. (myAvatarName == m.name) ? (myClass = "avatarName mdc-typography--subheading2") :
  1234. myClass = "nodeItem"
  1235. var nodeName = m.name;
  1236. let displayName = vwf.getProperty(m.ID, 'displayName');
  1237. if (displayName) {
  1238. nodeName = displayName
  1239. }
  1240. return {
  1241. $type: "li",
  1242. class: "mdc-list-item",
  1243. $components: [{
  1244. $type: "a",
  1245. class: "mdc-list-item",
  1246. $href: "#",
  1247. $components: [{
  1248. $type: 'span',
  1249. class: myClass,
  1250. $text: nodeName
  1251. }
  1252. ],
  1253. onclick: function (e) {
  1254. //self.currentNodeID = m.ID;
  1255. document.querySelector('#currentNode')._setNode(m.ID);
  1256. // document.querySelector('#liveCodeEditor')._editorNode = m.ID;
  1257. // createAceEditor(self, m.ID);
  1258. }
  1259. }]
  1260. }
  1261. };
  1262. let listDivider = {
  1263. $type: "hr",
  1264. class: "mdc-list-divider",
  1265. }
  1266. let webrtcGUI = {
  1267. $type: "div",
  1268. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1269. $components: [
  1270. {
  1271. $type: "div",
  1272. class: "mdc-layout-grid__inner",
  1273. $components: [
  1274. {
  1275. $type: "div",
  1276. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1277. $components: [
  1278. {
  1279. $type: "span",
  1280. $text: "Chat"
  1281. }
  1282. ]
  1283. },
  1284. {
  1285. $type: "div",
  1286. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1287. $components: [
  1288. self.widgets.icontoggle({
  1289. 'id': "webrtcswitch",
  1290. 'label': 'visibility',
  1291. 'on': JSON.stringify({ "content": "visibility", "label": "Turn On Mic" }),
  1292. 'off': JSON.stringify({ "content": "visibility_off", "label": "Turn Off Mic" }),
  1293. 'state': false,
  1294. 'init': function () {
  1295. this._driver = vwf.views["vwf/view/webrtc"];
  1296. if (!this._driver) {
  1297. //this.classList.add('mdc-icon-toggle--disabled');
  1298. this.setAttribute('disabled',"");
  1299. }
  1300. mdc.iconButton.MDCIconButtonToggle.attachTo(this);
  1301. this.addEventListener('MDCIconButtonToggle:change', (e) => {
  1302. let driver = e.target._driver;
  1303. let chkAttr = e.detail.isOn;
  1304. let avatarID = 'avatar-' + self.kernel.moniker();
  1305. let micToggle = document.querySelector('#webrtcaudio');
  1306. let camToggle = document.querySelector('#webrtcvideo');
  1307. if (chkAttr) {
  1308. driver.startWebRTC(avatarID);
  1309. micToggle.removeAttribute('disabled');
  1310. camToggle.removeAttribute('disabled');
  1311. //micToggle.classList.remove('mdc-icon-toggle--disabled');
  1312. //camToggle.classList.remove('mdc-icon-toggle--disabled');
  1313. console.log("on")
  1314. } else {
  1315. driver.stopWebRTC(avatarID);
  1316. micToggle.setAttribute('disabled',"");
  1317. camToggle.setAttribute('disabled',"");
  1318. //micToggle.classList.add('mdc-icon-toggle--disabled');
  1319. //camToggle.classList.add('mdc-icon-toggle--disabled');
  1320. console.log("off")
  1321. }
  1322. //console.log(e, detail)
  1323. //status.textContent = `Icon Toggle is ${detail.isOn ? 'on' : 'off'}`;
  1324. });
  1325. }
  1326. })
  1327. ]
  1328. },
  1329. {
  1330. $type: "div",
  1331. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1332. $components: [
  1333. self.widgets.icontoggle({
  1334. 'id': "webrtcaudio",
  1335. 'label': 'mic',
  1336. 'on': JSON.stringify({ "content": "mic", "label": "Turn On Mic" }),
  1337. 'off': JSON.stringify({ "content": "mic_off", "label": "Turn Off Mic" }),
  1338. 'state': false,
  1339. 'init': function () {
  1340. this._driver = vwf.views["vwf/view/webrtc"];
  1341. let webrtcswitch = document.querySelector('#webrtcswitch');
  1342. if (!this._driver) {
  1343. //this.classList.add('mdc-icon-toggle--disabled');
  1344. this.setAttribute("disabled", "");
  1345. }
  1346. //this.classList.add('mdc-icon-toggle--disabled');
  1347. this.setAttribute("disabled", "");
  1348. this.addEventListener('MDCIconButtonToggle:change', (e) => {
  1349. let driver = e.target._driver;
  1350. let chkAttr = e.detail.isOn;
  1351. if (chkAttr) {
  1352. driver.muteAudio(chkAttr);
  1353. console.log("on")
  1354. } else {
  1355. driver.muteAudio(chkAttr);
  1356. console.log("off")
  1357. }
  1358. //console.log(e, detail)
  1359. //status.textContent = `Icon Toggle is ${detail.isOn ? 'on' : 'off'}`;
  1360. });
  1361. }
  1362. })
  1363. ]
  1364. },
  1365. {
  1366. $type: "div",
  1367. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1368. $components: [
  1369. self.widgets.icontoggle({
  1370. 'id': "webrtcvideo",
  1371. 'label': 'videocam',
  1372. 'on': JSON.stringify({ "content": "videocam", "label": "Turn On Video" }),
  1373. 'off': JSON.stringify({ "content": "videocam_off", "label": "Turn Off Video" }),
  1374. 'state': false,
  1375. 'init': function () {
  1376. this._driver = vwf.views["vwf/view/webrtc"];
  1377. if (!this._driver) {
  1378. //this.classList.add('mdc-icon-toggle--disabled');
  1379. this.setAttribute("disabled", "");
  1380. }
  1381. // this.classList.add('mdc-icon-toggle--disabled');
  1382. this.setAttribute("disabled", "");
  1383. this.addEventListener('MDCIconButtonToggle:change', (e) => {
  1384. let driver = e.target._driver;
  1385. let chkAttr = e.detail.isOn;
  1386. if (chkAttr) {
  1387. driver.muteVideo(chkAttr);
  1388. console.log("on")
  1389. } else {
  1390. driver.muteVideo(chkAttr);
  1391. console.log("off")
  1392. }
  1393. //console.log(e, detail)
  1394. //status.textContent = `Icon Toggle is ${detail.isOn ? 'on' : 'off'}`;
  1395. });
  1396. }
  1397. })
  1398. ]
  1399. }
  1400. ]
  1401. }
  1402. ]
  1403. }
  1404. let audioGUI = {
  1405. $type: "div",
  1406. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1407. $components: [
  1408. {
  1409. $type: "div",
  1410. class: "mdc-layout-grid__inner",
  1411. $components: [
  1412. {
  1413. $type: "div",
  1414. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1415. $components: [
  1416. {
  1417. $type: "span",
  1418. $text: "Sound: "
  1419. }
  1420. ]
  1421. },
  1422. {
  1423. $type: "div",
  1424. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1425. $components: [
  1426. self.widgets.icontoggle({
  1427. 'id': "soundStopStartSwitch",
  1428. 'label': 'play',
  1429. 'on': JSON.stringify({ "content": "pause", "label": "stop" }),
  1430. 'off': JSON.stringify({ "content": "play_arrow", "label": "play" }),
  1431. 'state': false,
  1432. 'init': function () {
  1433. var nodeID = this._currentNode;
  1434. this._comp = new mdc.iconButtonToggle.MDCIconButtonToggle(this);
  1435. this.setAttribute('id', "soundStopStartSwitch-" + nodeID);
  1436. let isPlaying = vwf.getProperty(nodeID, 'isPlaying');
  1437. //mdc.iconToggle.MDCIconToggle.attachTo(this);
  1438. this._comp.on = isPlaying;
  1439. this.addEventListener('MDCIconButtonToggle:change', (e) => {
  1440. // let avatarID = 'avatar-'+ vwf.moniker_;
  1441. // let avatarNode = self.nodes['avatar-'+ vwf.moniker_];
  1442. // let mode = JSON.parse(avatarNode.properties.selectMode.getValue());
  1443. var nodeID = document.querySelector('#currentNode')._currentNode;
  1444. let isPlaying = vwf.getProperty(nodeID, 'isPlaying');
  1445. if (isPlaying) {
  1446. console.log("stop");
  1447. vwf_view.kernel.callMethod(nodeID, "pauseSound");
  1448. } else {
  1449. console.log("play")
  1450. vwf_view.kernel.callMethod(nodeID, "playSound");
  1451. }
  1452. });
  1453. }
  1454. })
  1455. ]
  1456. },
  1457. {
  1458. $type: "div",
  1459. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1460. $components: [
  1461. {
  1462. $type: "div",
  1463. style: "padding: 12px",
  1464. $components: [
  1465. self.widgets.iconButton({
  1466. 'label': 'stop',
  1467. onclickfunc: function () {
  1468. var nodeID = this._currentNode;
  1469. vwf_view.kernel.callMethod(nodeID, "stopSound");
  1470. }
  1471. })
  1472. ]
  1473. }
  1474. ]
  1475. }
  1476. // {
  1477. // $type: "div",
  1478. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1479. // $components: [
  1480. // widgets.switch({
  1481. // 'id': 'editnode',
  1482. // 'init': function(){
  1483. // vwf_view.kernel.getProperty(this._currentNode, 'edit');
  1484. // },
  1485. // 'onchange': function(e){
  1486. // var nodeID = document.querySelector('#currentNode')._currentNode;
  1487. // let chkAttr = this.getAttribute('checked');
  1488. // if (chkAttr == "") {
  1489. // self.kernel.setProperty(this._currentNode, 'edit', false);
  1490. // } else {
  1491. // self.kernel.setProperty(this._currentNode, 'edit', true);
  1492. // }
  1493. // vwf_view.kernel.callMethod(nodeID, "showCloseGizmo");
  1494. // }
  1495. // }
  1496. // )
  1497. // ]
  1498. // }
  1499. ]
  1500. }
  1501. ]
  1502. }
  1503. var saveGUI = {};
  1504. if (_LCSUSER.is) {
  1505. saveGUI = self.widgets.floatActionButton({
  1506. label: "save",
  1507. styleClass: "mdc-fab--mini",
  1508. onclickfunc: function () {
  1509. var nodeID = document.querySelector('#currentNode')._currentNode;
  1510. let node = self.nodes[nodeID];
  1511. let nodeDef = self.helpers.getNodeDef(nodeID);
  1512. console.log(nodeDef);
  1513. //let saveID = this.GUID();
  1514. // _LCSUSER.get('saves').get(node.name).put(JSON.stringify(nodeDef), acc=>{
  1515. // console.log("saved: " + acc + 'to '+ node.name)
  1516. // });
  1517. }
  1518. })
  1519. }
  1520. let gizmoEdit = {
  1521. $type: "div",
  1522. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1523. $components: [
  1524. {
  1525. $type: "div",
  1526. class: "mdc-layout-grid__inner",
  1527. $components: [
  1528. {
  1529. $type: "div",
  1530. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1531. $components: [
  1532. {
  1533. $type: "span",
  1534. $text: "Edit: ",
  1535. }
  1536. ]
  1537. },
  1538. {
  1539. $type: "div",
  1540. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1541. $components: [
  1542. self.widgets.switch({
  1543. 'id': 'editnode',
  1544. 'init': function () {
  1545. vwf_view.kernel.getProperty(this._currentNode, 'edit');
  1546. this._switch = new mdc.switchControl.MDCSwitch(this);
  1547. this._switch.checked = false;
  1548. },
  1549. 'onchange': function (e) {
  1550. var nodeID = document.querySelector('#currentNode')._currentNode;
  1551. if (this._switch) {
  1552. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  1553. if (chkAttr) {
  1554. self.kernel.setProperty(this._currentNode, 'edit', true);
  1555. //this._switch.checked = false;
  1556. } else {
  1557. self.kernel.setProperty(this._currentNode, 'edit', false);
  1558. //this._switch.checked = true;
  1559. }
  1560. vwf_view.kernel.callMethod(nodeID, "showCloseGizmo");
  1561. }
  1562. }
  1563. }
  1564. )
  1565. ]
  1566. },
  1567. {
  1568. $type: "div",
  1569. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1570. $components: [
  1571. self.widgets.imageButton({
  1572. imgSrc: "/vwf/view/lib/images/ui/icons/translate.png",
  1573. styleClass: "editButton",
  1574. onclickfunc: function (e) {
  1575. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['translate'])
  1576. }
  1577. })
  1578. ]
  1579. },
  1580. {
  1581. $type: "div",
  1582. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1583. $components: [
  1584. self.widgets.imageButton({
  1585. imgSrc: "/vwf/view/lib/images/ui/icons/rotate.png",
  1586. styleClass: "editButton",
  1587. onclickfunc: function (e) {
  1588. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['rotate'])
  1589. }
  1590. })
  1591. ]
  1592. },
  1593. {
  1594. $type: "div",
  1595. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1596. $components: [
  1597. self.widgets.imageButton({
  1598. imgSrc: "/vwf/view/lib/images/ui/icons/scale.png",
  1599. styleClass: "editButton",
  1600. onclickfunc: function (e) {
  1601. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['scale'])
  1602. }
  1603. })
  1604. ]
  1605. },
  1606. {
  1607. $type: "div",
  1608. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1609. $components: [
  1610. // self.widgets.floatActionButton({
  1611. // label: "content_copy",
  1612. // styleClass: "mdc-fab--mini"
  1613. // }),
  1614. // {
  1615. // $type: "span",
  1616. // $text: " "
  1617. // },
  1618. self.widgets.floatActionButton({
  1619. label: "delete_forever",
  1620. styleClass: "mdc-fab--mini",
  1621. onclickfunc: function () {
  1622. var nodeID = document.querySelector('#currentNode')._currentNode;
  1623. let node = self.nodes[nodeID];
  1624. //vwf_view.kernel.deleteChild(node.parentID, node.name);
  1625. vwf_view.kernel.deleteNode(nodeID);
  1626. //vwf_view.kernel.callMethod(node.parentID, "deleteNode", [node.name])
  1627. }
  1628. }),
  1629. // self.widgets.floatActionButton({
  1630. // label: "person",
  1631. // styleClass: "mdc-fab--mini",
  1632. // onclickfunc: function () {
  1633. // var nodeID = document.querySelector('#currentNode')._currentNode;
  1634. // let node = self.nodes[nodeID];
  1635. // //vwf_view.kernel.deleteChild(node.parentID, node.name);
  1636. // let me = self.kernel.moniker();
  1637. // vwf_view.kernel.setProperty(nodeID, 'ownedBy', me);
  1638. // }
  1639. // }),
  1640. saveGUI
  1641. ]
  1642. },
  1643. ]
  1644. }
  1645. ]
  1646. }
  1647. let nodesCell = {
  1648. $cell: true,
  1649. $type: "div",
  1650. id: "currentNode",
  1651. _childNodes: [],
  1652. _currentNode: '',
  1653. _displayedProperties: {},
  1654. _setNode: function (aNode) {
  1655. this._currentNode = aNode;
  1656. document.querySelector('#sideBar')._sideCurrentNode = this._currentNode
  1657. },
  1658. $init: function () {
  1659. this._currentNode = document.querySelector('#sideBar')._sideCurrentNode
  1660. //this._currentNode = vwf_view.kernel.find("", "/")[0];
  1661. //this._currentNode = '3333';
  1662. },
  1663. _getChildNodes: function () {
  1664. this._childNodes = self.nodes[this._currentNode];
  1665. if (this._childNodes !== undefined) {
  1666. return this._childNodes.children
  1667. } else {
  1668. return []
  1669. }
  1670. //let nodeIDAlpha = he.encode(this._currentNode);
  1671. },
  1672. // _getNodeComplexProperties: function () {
  1673. // let node = self.nodes[this._currentNode];
  1674. // let props = this._getNodeProperties();
  1675. // let filterFunction = function (prop) {
  1676. // return (prop.name == 'ohmLang')
  1677. // };
  1678. // let complexProps = props.filter(filterFunction.bind(this));
  1679. // return complexProps
  1680. // },
  1681. _getNodeProperties: function () {
  1682. let node = self.nodes[this._currentNode];
  1683. this._displayedProperties = {};
  1684. let filterFunction = function (prop) {
  1685. return (!this._displayedProperties[prop.name] && prop.name.indexOf('$') === -1) ? (this._displayedProperties[prop.name] = "instance", true) : (false);
  1686. };
  1687. let props = node.properties.filter(filterFunction.bind(this));
  1688. return props
  1689. },
  1690. _getNodeProtoProperties: function () {
  1691. let node = self.nodes[this._currentNode];
  1692. let filterFunction = function (prop) {
  1693. return (!this._displayedProperties[prop[1].prop.name]) ? (this._displayedProperties[prop[1].prop.name] = prop[1].prototype, true) : (false);
  1694. };
  1695. let props = Object.entries(getProperties.call(self, self.kernel, node.extendsID)).filter(filterFunction.bind(this));
  1696. return props
  1697. },
  1698. $update: function () {
  1699. //this.$text = this._currentNode;
  1700. let node = self.nodes[this._currentNode];
  1701. let nodeProtos = getPrototypes(self.kernel, node.extendsID);
  1702. var viewerProps = {};
  1703. var viewerPropsCell = {};
  1704. var propsActions = {};
  1705. var propsActionsCell = {};
  1706. var gizmoCell = {};
  1707. if (this._currentNode !== self.kernel.application()) {
  1708. if (nodeProtos.includes('http://vwf.example.com/aframe/componentNode.vwf')) {
  1709. //gizmoCell = {};
  1710. if (nodeProtos.includes('http://vwf.example.com/aframe/a-sound-component.vwf')) {
  1711. //console.log("sound gui")
  1712. gizmoCell = audioGUI
  1713. }
  1714. } else {
  1715. gizmoCell = gizmoEdit
  1716. }
  1717. }
  1718. if (node !== undefined) {
  1719. propsActions = {
  1720. $type: "li",
  1721. class: "mdc-list-item",
  1722. $components: [
  1723. {
  1724. $text: "Actions",
  1725. $type: "span",
  1726. class: "mdc-list-item__text mdc-typography--button"
  1727. }
  1728. ]
  1729. }
  1730. let actionsGUI = [];
  1731. if(node.properties.meta) {
  1732. if(node.properties.meta.rawValue == 'avatarCostume'){
  1733. actionsGUI.push(self.widgets.buttonStroked(
  1734. {
  1735. "label": "Use this costume",
  1736. "onclick": function (e) {
  1737. console.log("COSTUME NEW!!!");
  1738. let nodeDef = self.helpers.getNodeDef(this._currentNode);
  1739. console.log(nodeDef);
  1740. let avatarID = 'avatar-' + self.kernel.moniker();
  1741. vwf_view.kernel.callMethod(avatarID, "changeCostume", [nodeDef]);
  1742. //vwf_view.kernel.callMethod(this._currentNode, "setCameraToActive", [vwf.moniker_]);
  1743. }
  1744. }))
  1745. }
  1746. }
  1747. propsActionsCell = {
  1748. $cell: true,
  1749. $type: "div",
  1750. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1751. $components: [
  1752. {
  1753. $type: "div",
  1754. class: "mdc-layout-grid__inner",
  1755. $components: [
  1756. {
  1757. $type: "div",
  1758. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1759. $components: [].concat(actionsGUI)
  1760. }
  1761. ]
  1762. }
  1763. ]
  1764. //$components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1765. }
  1766. if (node.extendsID == "http://vwf.example.com/aframe/acamera.vwf") {
  1767. viewerProps = {
  1768. $type: "li",
  1769. class: "mdc-list-item",
  1770. $components: [
  1771. {
  1772. $text: "Viewer properties",
  1773. $type: "span",
  1774. class: "mdc-list-item__text mdc-typography--button"
  1775. }
  1776. ]
  1777. }
  1778. viewerPropsCell = {
  1779. $cell: true,
  1780. $type: "div",
  1781. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1782. $components: [
  1783. {
  1784. $type: "div",
  1785. class: "mdc-layout-grid__inner",
  1786. $components: [
  1787. {
  1788. $type: "div",
  1789. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1790. $components: [
  1791. self.widgets.buttonStroked(
  1792. {
  1793. "label": "Active",
  1794. "onclick": function (e) {
  1795. //let camera = document.querySelector('#' + this._currentNode);
  1796. vwf_view.kernel.callMethod(this._currentNode, "setCameraToActive", [vwf.moniker_]);
  1797. //camera.setAttribute('camera', 'active', true);
  1798. }
  1799. })
  1800. ]
  1801. }
  1802. ]
  1803. }
  1804. ]
  1805. //$components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1806. }
  1807. } else {
  1808. viewerProps = {};
  1809. viewerPropsCell = {};
  1810. }
  1811. }
  1812. this.$components = [
  1813. {
  1814. $type: "ul",
  1815. class: "mdc-list",
  1816. $components: [
  1817. self.widgets.buttonStroked(
  1818. {
  1819. "label": "<--",
  1820. "onclick": function (e) {
  1821. let node = self.nodes[this._currentNode];
  1822. if (node.parentID !== 0) {
  1823. //self.currentNodeID = node.parentID,
  1824. document.querySelector('#currentNode')._setNode(node.parentID)
  1825. }
  1826. }
  1827. }),
  1828. {
  1829. $type: "li",
  1830. class: "mdc-list-item",
  1831. $components: [
  1832. {
  1833. $text: "name",
  1834. $type: "span",
  1835. $init: function () {
  1836. let node = self.nodes[this._currentNode];
  1837. if (node) {
  1838. let displayName = vwf.getProperty(node.ID, 'displayName');
  1839. if (displayName) {
  1840. this.$text = displayName
  1841. } else {
  1842. this.$text = node.name;
  1843. }
  1844. }
  1845. //console.log(node.properties.displayName)
  1846. },
  1847. class: "mdc-list-item__text mdc-typography--headline"
  1848. //<h1 class="mdc-typography--display4">Big header</h1>
  1849. }]
  1850. }, listDivider,
  1851. {
  1852. // $cell: true,
  1853. // $type: "ul",
  1854. // class: "mdc-list",
  1855. $type: "div",
  1856. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1857. $components: [
  1858. {
  1859. $type: "div",
  1860. class: "mdc-layout-grid__inner",
  1861. $components: [
  1862. {
  1863. $type: "div",
  1864. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1865. $components: [
  1866. self.widgets.buttonStroked(
  1867. {
  1868. "label": "Methods browser",
  1869. "onclick": function (e) {
  1870. var currentNode = document.querySelector('#currentNode')._currentNode;
  1871. if (currentNode == '') {
  1872. currentNode = vwf_view.kernel.find("", "/")[0];
  1873. }
  1874. if (isAFrameEntity(currentNode)) {
  1875. vwf.views["vwf/view/aframe"].nodes[currentNode].liveBindings = {};
  1876. } else if(isAFrameComponent(currentNode)) {
  1877. vwf.views["vwf/view/aframeComponent"].nodes[currentNode].liveBindings = {};
  1878. }
  1879. document.querySelector('#liveCodeEditor')._setNode(currentNode);
  1880. //createAceEditor(self, currentNode);
  1881. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  1882. }
  1883. })
  1884. ]
  1885. }
  1886. ]
  1887. }
  1888. ]
  1889. },
  1890. gizmoCell,
  1891. listDivider,
  1892. {
  1893. $type: "li",
  1894. class: "mdc-list-item",
  1895. $components: [
  1896. {
  1897. $text: "Children",
  1898. $type: "span",
  1899. class: "mdc-list-item__text mdc-typography--button"
  1900. }]
  1901. },
  1902. {
  1903. $type: "ul",
  1904. class: "mdc-list",
  1905. $components: this._getChildNodes().map(nodeLink)
  1906. }, listDivider, {
  1907. $type: "li",
  1908. class: "mdc-list-item",
  1909. $components: [
  1910. {
  1911. $text: "Properties",
  1912. $type: "span",
  1913. class: "mdc-list-item__text mdc-typography--button"
  1914. //<h1 class="mdc-typography--display4">Big header</h1>
  1915. }]
  1916. },
  1917. {
  1918. // $cell: true,
  1919. // $type: "ul",
  1920. // class: "mdc-list",
  1921. $type: "div",
  1922. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1923. $components: this._getNodeProperties().map(propertiesCell)
  1924. },
  1925. listDivider,
  1926. {
  1927. $type: "li",
  1928. class: "mdc-list-item",
  1929. $components: [
  1930. {
  1931. $text: "Proto properties",
  1932. $type: "span",
  1933. class: "mdc-list-item__text mdc-typography--button"
  1934. }]
  1935. },
  1936. {
  1937. $type: "div",
  1938. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1939. $components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1940. }, listDivider,
  1941. propsActions,
  1942. propsActionsCell,
  1943. listDivider,
  1944. viewerProps,
  1945. viewerPropsCell
  1946. ]
  1947. }
  1948. ]
  1949. }
  1950. }
  1951. let numberSliderComponent = {
  1952. $cell: true,
  1953. $type: "div",
  1954. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  1955. $init: function () {
  1956. },
  1957. $components: [
  1958. {
  1959. $type: "div",
  1960. style: "padding: 0 16px;",
  1961. $components: [
  1962. {}
  1963. ]
  1964. }
  1965. ]
  1966. }
  1967. let colorPickerComponent = {
  1968. $cell: true,
  1969. $type: "div",
  1970. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  1971. $init: function () {
  1972. let myEl = this;
  1973. let cp = ColorPicker(
  1974. document.getElementById('slide'),
  1975. document.getElementById('picker'),
  1976. function (hex, hsv, rgb, mousePicker, mouseSlide) {
  1977. ColorPicker.positionIndicators(
  1978. document.getElementById('slide-indicator'),
  1979. document.getElementById('picker-indicator'),
  1980. mouseSlide, mousePicker
  1981. );
  1982. if (myEl._propName.toLowerCase().includes('color')) {
  1983. // console.log(hex);
  1984. document.querySelector('#propAceEditor').env.editor.setValue(JSON.stringify(hex));
  1985. self.kernel.setProperty(myEl._editorNode, myEl._propName, hex);
  1986. }
  1987. });
  1988. if (myEl._propName.toLowerCase().includes('color')) {
  1989. cp.setHex(JSON.parse(myEl._prop.body));
  1990. }
  1991. },
  1992. $components: [
  1993. {
  1994. $type: "div",
  1995. id: "color-picker",
  1996. class: "cp-default",
  1997. $components: [
  1998. {
  1999. $type: "div",
  2000. class: "picker-wrapper",
  2001. $components: [
  2002. {
  2003. $type: "div",
  2004. id: "picker",
  2005. class: "picker",
  2006. style: "width: 130px; height: 130px"
  2007. },
  2008. {
  2009. $type: "div",
  2010. id: "picker-indicator",
  2011. class: "picker-indicator"
  2012. }
  2013. ]
  2014. },
  2015. {
  2016. $type: "div",
  2017. class: "slide-wrapper",
  2018. $components: [
  2019. {
  2020. $type: "div",
  2021. id: "slide",
  2022. class: "slide",
  2023. style: "width: 30px; height: 130px"
  2024. },
  2025. {
  2026. $type: "div",
  2027. id: "slide-indicator",
  2028. class: "slide-indicator"
  2029. }
  2030. ]
  2031. }
  2032. ]
  2033. }
  2034. // {
  2035. // $cell: true,
  2036. // $type: "div",
  2037. // id: "color-picker",
  2038. // $init: function () {
  2039. // }
  2040. // }
  2041. ]
  2042. }
  2043. let propEditorWindow = {
  2044. $cell: true,
  2045. $type: "div",
  2046. _editorNode: '',
  2047. _prop: { body: '', type: 'simple' },
  2048. _propName: '',
  2049. id: "livePropEditor",
  2050. _setNode: function (node) {
  2051. this._editorNode = node;
  2052. this._prop.body = ''
  2053. },
  2054. class: "propEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2055. $update: function () {
  2056. var editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-8"
  2057. var livePropertyComponent = {}
  2058. if (this._prop.type == 'simple') {
  2059. if (this._propName.toLowerCase().includes('color')) {
  2060. livePropertyComponent = colorPickerComponent
  2061. }
  2062. } else {
  2063. editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-12"
  2064. }
  2065. this.$components = [
  2066. {
  2067. $type: "div",
  2068. class: "mdc-layout-grid__inner",
  2069. $components: [
  2070. {
  2071. $type: "div",
  2072. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2073. $components: [
  2074. self.widgets.buttonStroked(
  2075. {
  2076. "label": "Update",
  2077. "onclick": function (e) {
  2078. let editor = document.querySelector("#propAceEditor").env.editor;
  2079. let value = editor.getValue();
  2080. try {
  2081. let propValue = (this._prop.type == 'simple') ? (JSON.parse(value)) : (value)
  2082. //propValue = JSON.parse(value);
  2083. self.kernel.setProperty(this._editorNode, this._propName, propValue);
  2084. } catch (e) {
  2085. // restore the original value on error
  2086. this.value = propValue;
  2087. }
  2088. }
  2089. }
  2090. )]
  2091. },
  2092. {
  2093. $type: "div",
  2094. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  2095. $components: [
  2096. {
  2097. $type: "h3",
  2098. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  2099. $text: this._editorNode
  2100. }
  2101. ]
  2102. },
  2103. {
  2104. $type: "div",
  2105. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  2106. $components: [
  2107. {
  2108. $type: "h3",
  2109. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  2110. $text: this._propName
  2111. }
  2112. ]
  2113. }
  2114. ]
  2115. },
  2116. {
  2117. $type: "div",
  2118. class: "mdc-layout-grid__inner",
  2119. $components: [
  2120. {
  2121. $type: "div",
  2122. class: editorClass,
  2123. $components: [
  2124. {
  2125. class: "aceEditor",
  2126. id: "propAceEditor",
  2127. $type: "div",
  2128. $text: this._prop.body,
  2129. $init: function () {
  2130. createAceEditor(self, this._editorNode, "propAceEditor");
  2131. this.env.editor.$blockScrolling = Infinity
  2132. }
  2133. }
  2134. ]
  2135. }, livePropertyComponent
  2136. // {
  2137. // $cell: true,
  2138. // $type: "div",
  2139. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2140. // $components: []
  2141. // },
  2142. ]
  2143. }
  2144. ]
  2145. //$components:
  2146. }
  2147. }
  2148. let codeEditorWindow = {
  2149. $cell: true,
  2150. $type: "div",
  2151. _editorNode: '',
  2152. _method: { body: '' },
  2153. _methodName: '',
  2154. _getNodeMethods: function () {
  2155. let node = self.nodes[this._editorNode];
  2156. return node.methods
  2157. },
  2158. _getProtoNodeMethods: function () {
  2159. let node = self.nodes[this._editorNode];
  2160. let prototypeMethods = getMethods.call(self, self.kernel, node.extendsID);
  2161. return prototypeMethods
  2162. },
  2163. id: "liveCodeEditor",
  2164. _setNode: function (node) {
  2165. this._editorNode = node;
  2166. this._method.body = ''
  2167. },
  2168. class: "codeEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2169. // _getComplexProps: function(){
  2170. // let node = self.nodes[this._editorNode];
  2171. // let currentNode = document.querySelector('#currentNode');
  2172. // var props = {}
  2173. // if (currentNode !== null) {
  2174. // props = currentNode._getNodeComplexProperties();
  2175. // }
  2176. // return props
  2177. // },
  2178. // _listPropertyElement: function (m) {
  2179. // return {
  2180. // $type: "li",
  2181. // class: "mdc-list-item",
  2182. // $components: [{
  2183. // $type: "a",
  2184. // class: "mdc-list-item",
  2185. // $href: "#",
  2186. // $text: m[1].name,
  2187. // onclick: function (e) {
  2188. // this._method = {};
  2189. // this._methodName = m[1].name;
  2190. // this._method.body = m[1].rawValue
  2191. // this._method.type = "complexProperty"
  2192. // }
  2193. // }]
  2194. // }
  2195. // },
  2196. _listElement: function (m) {
  2197. return {
  2198. $type: "li",
  2199. class: "mdc-list-item",
  2200. $components: [{
  2201. $type: "a",
  2202. class: "mdc-list-item",
  2203. $href: "#",
  2204. $text: m[0],
  2205. onclick: function (e) {
  2206. let method = vwf.getMethod(this._editorNode, m[0]);
  2207. //document.querySelector('#aceEditor').
  2208. this._method = method;
  2209. this._methodName = m[0];
  2210. //self.currentNodeID = m.ID;
  2211. //document.querySelector('#currentNode')._setNode(m.ID);
  2212. }
  2213. }]
  2214. }
  2215. },
  2216. $update: function () {
  2217. this.$components = [
  2218. {
  2219. $type: "div",
  2220. class: "mdc-layout-grid__inner",
  2221. $components: [
  2222. {
  2223. $type: "div",
  2224. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2225. $components: [
  2226. {
  2227. $type: "h3",
  2228. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  2229. $text: this._editorNode
  2230. }
  2231. ]
  2232. },
  2233. {
  2234. $type: "div",
  2235. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1 tooltip",
  2236. $components: [
  2237. {
  2238. class: "tooltiptext",
  2239. $type: "span",
  2240. $text: "Update"
  2241. },
  2242. self.widgets.iconButton({
  2243. 'label': 'refresh',
  2244. "styleClass": "mdc-button--outlined",
  2245. // self.widgets.buttonStroked(
  2246. // {
  2247. // "label": "Update",
  2248. "onclick": function (e) {
  2249. let editor = document.querySelector("#aceEditor").env.editor;
  2250. let evalText = editor.getValue();
  2251. // if (this._method.type == 'complexProperty') {
  2252. // let propValue = evalText;
  2253. // try {
  2254. // //propValue = JSON.parse(propValue);
  2255. // self.kernel.setProperty(this._editorNode, this._methodName, propValue);
  2256. // } catch (e) {
  2257. // // restore the original value on error
  2258. // this.value = propValue;
  2259. // }
  2260. // } else {
  2261. // }
  2262. self.kernel.setMethod(this._editorNode, this._methodName,
  2263. { body: evalText, type: "application/javascript", parameters: this._method.parameters });
  2264. }
  2265. }
  2266. )]
  2267. },
  2268. {
  2269. $type: "div",
  2270. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1 tooltip",
  2271. $components: [
  2272. {
  2273. class: "tooltiptext",
  2274. $type: "span",
  2275. $text: "Call It"
  2276. },
  2277. self.widgets.iconButton({
  2278. 'label': 'play_arrow',
  2279. "styleClass": "mdc-button--outlined",
  2280. // self.widgets.buttonStroked(
  2281. // {
  2282. // "label": "Call",
  2283. "onclick": function (e) {
  2284. var params = [];
  2285. if (this._method.parameters) {
  2286. let paramsLength = this._method.parameters.length
  2287. if (paramsLength >= 1) {
  2288. let paramsVal = document.querySelector("#methodParams").value;
  2289. try {
  2290. params = JSON.parse(paramsVal);
  2291. //params.push(prmtr);
  2292. } catch (e) {
  2293. self.logger.error('Invalid Value');
  2294. }
  2295. }
  2296. };
  2297. let editor = document.querySelector("#aceEditor").env.editor;
  2298. let evalText = editor.getValue();
  2299. let allLines = editor.selection.doc.getAllLines();
  2300. let search = this._methodName+'(';
  2301. let findLine = Object.entries(allLines).filter(el=>el[1].includes(search))[0];
  2302. //TODO: temporal fix for recursive future call from the editor
  2303. if(findLine) {
  2304. if(findLine[1].includes(search)) {
  2305. let position = {
  2306. row: findLine[0],
  2307. column: 0
  2308. };
  2309. var Range = ace.require("ace/range").Range;
  2310. let tempString = "//CLICK FOR CALL AGAIN ";
  2311. if(findLine[1].includes(tempString)){
  2312. let newText = findLine[1].replace(tempString, "");
  2313. editor.session.replace(new Range(position.row, 0, position.row, Number.MAX_VALUE), newText);
  2314. self.kernel.setMethod(this._editorNode, this._methodName,
  2315. { body: editor.getValue(), type: "application/javascript", parameters: this._method.parameters });
  2316. } else if(findLine[1].includes("//")) { //startsWith
  2317. } else {
  2318. let newText = tempString + findLine[1];
  2319. editor.session.replace(new Range(position.row, 0, position.row, Number.MAX_VALUE), newText);
  2320. self.kernel.setMethod(this._editorNode, this._methodName,
  2321. { body: editor.getValue(), type: "application/javascript", parameters: this._method.parameters });
  2322. }
  2323. }
  2324. }
  2325. self.kernel.callMethod(this._editorNode, this._methodName, params);
  2326. }
  2327. })
  2328. ]
  2329. },
  2330. {
  2331. $type: "div",
  2332. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1 tooltip",
  2333. $components: [
  2334. {
  2335. class: "tooltiptext",
  2336. $type: "span",
  2337. $text: "Do It"
  2338. },
  2339. self.widgets.iconButton({
  2340. 'label': 'arrow_forward',
  2341. "styleClass": "mdc-button--outlined",
  2342. // self.widgets.buttonStroked(
  2343. // {
  2344. // "label": "Do It",
  2345. "onclick": function (e) {
  2346. let editor = document.querySelector("#aceEditor").env.editor;
  2347. codeEditorDoit.call(self, editor, this._editorNode);
  2348. }
  2349. })
  2350. ]
  2351. },
  2352. {
  2353. $type: "div",
  2354. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1 tooltip",
  2355. $components: [
  2356. {
  2357. class: "tooltiptext",
  2358. $type: "span",
  2359. $text: "Print It"
  2360. },
  2361. self.widgets.iconButton({
  2362. 'label': 'details',
  2363. "styleClass": "mdc-button--outlined",
  2364. // self.widgets.buttonStroked(
  2365. // {
  2366. // "label": "Print It",
  2367. "onclick": function (e) {
  2368. let editor = document.querySelector("#aceEditor").env.editor;
  2369. codeEditorPrintit.call(self, editor, this._editorNode);
  2370. }
  2371. })
  2372. ]
  2373. },
  2374. {
  2375. $type: "div",
  2376. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1 tooltip",
  2377. $components: [
  2378. {
  2379. class: "tooltiptext",
  2380. $type: "span",
  2381. $text: "Print It on Console"
  2382. },
  2383. self.widgets.iconButton({
  2384. 'label': 'code',
  2385. "styleClass": "mdc-button--outlined",
  2386. // self.widgets.buttonStroked(
  2387. // {
  2388. // "label": "Print It on Console",
  2389. "onclick": function (e) {
  2390. let editor = document.querySelector("#aceEditor").env.editor;
  2391. codeEditorPrintitInDebugger.call(self, editor, this._editorNode);
  2392. }
  2393. })
  2394. ]
  2395. }
  2396. ]
  2397. },
  2398. {
  2399. $type: "div",
  2400. class: "mdc-layout-grid__inner",
  2401. $components: [
  2402. {
  2403. $type: "div",
  2404. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2405. style: "overflow-y: scroll; max-height: 400px;",
  2406. $components: [
  2407. {
  2408. $type: "div",
  2409. class: "mdc-list-group",
  2410. $components: [
  2411. {
  2412. $type: "h3",
  2413. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2414. $text: "Node methods"
  2415. },
  2416. {
  2417. $type: "ul",
  2418. class: "mdc-list",
  2419. $components: Object.entries(this._getNodeMethods()).map(this._listElement)
  2420. }, listDivider,
  2421. {
  2422. $type: "h3",
  2423. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2424. $text: "Proto methods"
  2425. },
  2426. {
  2427. $type: "ul",
  2428. class: "mdc-list",
  2429. $components: Object.entries(this._getProtoNodeMethods()).map(this._listElement)
  2430. }, listDivider,
  2431. {
  2432. $type: "h3",
  2433. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2434. $text: "Events"
  2435. }
  2436. // {
  2437. //
  2438. // $type: "ul",
  2439. // class: "mdc-list",
  2440. // $components: Object.entries(this._getComplexProps()).map(this._listPropertyElement)
  2441. // }
  2442. ]
  2443. }
  2444. ]
  2445. },
  2446. {
  2447. $type: "div",
  2448. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-9",
  2449. $components: [
  2450. {
  2451. class: "aceEditor",
  2452. id: "aceEditor",
  2453. $type: "div",
  2454. $text: this._method.body,
  2455. $init: function () {
  2456. createAceEditor(self, this._editorNode, "aceEditor");
  2457. }
  2458. }
  2459. ]
  2460. }
  2461. ]
  2462. },
  2463. {
  2464. $type: "div",
  2465. class: "mdc-layout-grid__inner",
  2466. $components: [
  2467. {
  2468. $type: "div",
  2469. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2470. $components: [
  2471. {
  2472. $type: "span",
  2473. $text: "*"
  2474. }
  2475. ]
  2476. }
  2477. ]
  2478. },
  2479. { //params input
  2480. $type: "div",
  2481. class: "mdc-layout-grid__inner",
  2482. $components: [
  2483. {
  2484. $type: "div",
  2485. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2486. $components: [
  2487. self.widgets.inputTextFieldOutlined({
  2488. "id": 'methodName',
  2489. "label": "Method name",
  2490. "value": "newMethodName",
  2491. "change": function (e) {
  2492. let propValue = this.value;
  2493. try {
  2494. } catch (e) {
  2495. // restore the original value on error
  2496. }
  2497. }
  2498. })
  2499. ]
  2500. },
  2501. {
  2502. $type: "div",
  2503. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  2504. $components: [
  2505. self.widgets.inputTextFieldOutlined({
  2506. "id": 'methodParams',
  2507. "label": "Method parameters",
  2508. "value": JSON.stringify(this._method.parameters),
  2509. "change": function (e) {
  2510. let propValue = this.value;
  2511. try {
  2512. } catch (e) {
  2513. // restore the original value on error
  2514. }
  2515. }
  2516. })
  2517. ]
  2518. },
  2519. {
  2520. $type: "div",
  2521. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2522. $components: [
  2523. self.widgets.buttonStroked(
  2524. {
  2525. "label": "Create",
  2526. "onclick": function (e) {
  2527. let methodName = document.querySelector('#methodName').value;
  2528. //let methodParams = document.querySelector('#methodParams');
  2529. var params = [];
  2530. let body = '';
  2531. let paramsVal = document.querySelector("#methodParams").value;
  2532. if (paramsVal !== '') {
  2533. try {
  2534. params = JSON.parse(paramsVal);
  2535. //params.push(prmtr);
  2536. } catch (e) {
  2537. self.logger.error('Invalid Value');
  2538. }
  2539. }
  2540. self.kernel.createMethod(this._editorNode, methodName, params, body);
  2541. this._setNode(this._editorNode);
  2542. // let editor = document.querySelector("#aceEditor").env.editor;
  2543. // codeEditorDoit.call(self, editor, this._editorNode);
  2544. }
  2545. })
  2546. ]
  2547. }
  2548. ]
  2549. }
  2550. ]
  2551. //$components:
  2552. }
  2553. }
  2554. let propWindow = {
  2555. $cell: true,
  2556. $type: "div",
  2557. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2558. style: "overflow-y: scroll; max-height: 800px;",
  2559. $components: [
  2560. {
  2561. $type: "div",
  2562. class: "mdc-layout-grid__inner",
  2563. $components: [
  2564. {
  2565. $type: "div",
  2566. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2567. $components: [
  2568. nodesCell
  2569. ]
  2570. }
  2571. ]
  2572. }
  2573. // <button class="mdc-button">
  2574. // Flat button
  2575. // </button>
  2576. ]
  2577. }
  2578. let clientListCell = {
  2579. $cell: true,
  2580. $type: "div",
  2581. class: "mdc-list",
  2582. id: "clientsList",
  2583. _watchNodes: [],
  2584. _listElement: function (m) {
  2585. return {
  2586. $type: "a",
  2587. class: "mdc-list-item",
  2588. $href: "#",
  2589. $text: m.name,
  2590. onclick: function (e) {
  2591. //self.currentNodeID = m.ID;
  2592. //document.querySelector('#currentNode')._setNode(m.ID);
  2593. }
  2594. }
  2595. },
  2596. $init: function () {
  2597. var t = this;
  2598. setInterval(function () {
  2599. t._updateMe();
  2600. }, 1000);
  2601. },
  2602. _updateMe: function () {
  2603. let clientNodes = self.nodes["http://vwf.example.com/clients.vwf"];
  2604. if (clientNodes) this._watchNodes = self.nodes["http://vwf.example.com/clients.vwf"].children.slice();
  2605. },
  2606. $update: function () {
  2607. //this._clientNodes
  2608. this.$components = this._watchNodes.map(this._listElement)
  2609. }
  2610. }
  2611. //createCellWindow("clientsWindow", clientListCell, "Clients");
  2612. //createCellWindow("propWindow", propWindow, "Scene");
  2613. createCellWindow("codeEditorWindow", codeEditorWindow, "Code editor");
  2614. createCellWindow("propEditorWindow", propEditorWindow, "Prop editor");
  2615. let viewSceneProps = {
  2616. $cell: true,
  2617. $type: "div",
  2618. class: "propGrid mdc-layout-grid mdc-layout-grid--align-left",
  2619. //style: "overflow-y: scroll; max-height: 500px; overflow-x: hidden;",
  2620. $components: [
  2621. {
  2622. $type: "div",
  2623. class: "mdc-layout-grid__inner",
  2624. $components: [
  2625. {
  2626. $type: "div",
  2627. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2628. $components: [
  2629. nodesCell
  2630. ]
  2631. }
  2632. ]
  2633. }
  2634. ]
  2635. }
  2636. let sideBar = {
  2637. $cell: true,
  2638. $type: "div",
  2639. id: 'sideBar',
  2640. class: "sideBar mdc-top-app-bar--fixed-adjust",
  2641. _sideBarComponent: {},
  2642. _sideCurrentNode: '',
  2643. $init: function () {
  2644. this.style.visibility = 'hidden';
  2645. let fileName = 'appui_js';
  2646. let worldName = self.helpers.getRoot(true).root;//url.split('/')[0];
  2647. let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
  2648. userDB.get('worlds').get(worldName).get(fileName).get('file').once(res => {
  2649. this._importScript(res);
  2650. })
  2651. },
  2652. _importScript: function (sSrc, fOnload) {
  2653. var oScript = document.createElement("script");
  2654. oScript.type = "text\/javascript";
  2655. oScript.async = false;
  2656. //oScript.onerror = loadError;
  2657. if (fOnload) { oScript.onload = fOnload; }
  2658. oScript.text = sSrc;
  2659. //let sideBar = document.querySelector('#sideBar');
  2660. this.appendChild(oScript);
  2661. },
  2662. _getAppDef: async function () {
  2663. // let response = await fetch("/" + self.getRoot() + "/appui.js");
  2664. // let data = await response.text();
  2665. // //console.log(data)
  2666. // return data
  2667. },
  2668. $update: function () {
  2669. this.$components = [
  2670. {
  2671. $type: "button",
  2672. class: "mdc-button mdc-button--compact",
  2673. $text: "X",
  2674. onclick: function (e) {
  2675. document.querySelector('#sideBar').style.visibility = 'hidden';
  2676. this._sideBarComponent = Object.assign({}, {});
  2677. }
  2678. },
  2679. this._sideBarComponent
  2680. ]
  2681. }
  2682. //$components: [this._sideComponents]
  2683. }
  2684. document.querySelector('#' + 'sideBar').$cell(sideBar)
  2685. let defaultApp = function () {
  2686. return {
  2687. $cell: true,
  2688. $type: "div",
  2689. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  2690. $components: [
  2691. {
  2692. $type: "div",
  2693. class: "mdc-layout-grid__inner",
  2694. $components: [
  2695. {
  2696. $type: "div",
  2697. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2698. $components: [
  2699. {
  2700. $type: "h3",
  2701. class: "mdc-typography--headline",
  2702. $text: "Application",
  2703. }
  2704. ]
  2705. }
  2706. ]
  2707. }
  2708. ]
  2709. }
  2710. }
  2711. let drawerCell = {
  2712. $cell: true,
  2713. $type: "div",
  2714. class: "mdc-drawer__content",
  2715. $components: [
  2716. {
  2717. $type: "nav",
  2718. class: "mdc-list",
  2719. $init: function () { },
  2720. $components: [
  2721. {
  2722. $type: "a",
  2723. class: "mdc-list-item mdc-list-item--activated",
  2724. $href: "#",
  2725. tabindex: "-1",
  2726. onclick: function (e) {
  2727. e.preventDefault();
  2728. let sideBar = document.querySelector('#sideBar');
  2729. try {
  2730. sideBar._sideBarComponent = createApp.call(self);
  2731. } catch (e) {
  2732. sideBar._sideBarComponent = defaultApp();
  2733. }
  2734. self.drawer.open = false//!self.drawer.open
  2735. //self.drawer.close();
  2736. document.querySelector('#sideBar').style.visibility = 'visible';
  2737. },
  2738. $components: [{
  2739. $type: "i",
  2740. class: "material-icons mdc-list-item__graphic",
  2741. 'aria-hidden': "true",
  2742. $text: "play_arrow"
  2743. },
  2744. {
  2745. $text: self.lang.t("App")
  2746. }]
  2747. },
  2748. {
  2749. $type: "a",
  2750. class: "mdc-list-item",
  2751. $href: "#",
  2752. tabindex: "-1",
  2753. onclick: function (e) {
  2754. e.preventDefault();
  2755. let sideBar = document.querySelector('#sideBar');
  2756. sideBar._sideBarComponent = viewSceneProps;
  2757. let currentNode = document.querySelector('#sideBar')._sideCurrentNode;
  2758. currentNode == '' ? document.querySelector('#sideBar')._sideCurrentNode = (vwf_view.kernel.find("", "/")[0]) :
  2759. document.querySelector('#sideBar')._sideCurrentNode = currentNode;
  2760. document.querySelector('#sideBar').style.visibility = 'visible';
  2761. self.drawer.open = !self.drawer.open
  2762. // let currentNode = document.querySelector('#currentNode')._currentNode;
  2763. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  2764. // document.querySelector('#currentNode')._setNode(currentNode);
  2765. },
  2766. $components: [{
  2767. $type: "i",
  2768. class: "material-icons mdc-list-item__graphic",
  2769. $text: "description"
  2770. },
  2771. {
  2772. $text: "Scene"
  2773. }
  2774. ]
  2775. },
  2776. {
  2777. $type: "a",
  2778. class: "mdc-list-item",
  2779. $href: "#",
  2780. tabindex: "-1",
  2781. onclick: function (e) {
  2782. e.preventDefault();
  2783. //self.currentNodeID = m.ID;
  2784. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2785. // document.querySelector('#clientsWindow').style.visibility = 'visible';
  2786. let sideBar = document.querySelector('#sideBar');
  2787. sideBar._sideBarComponent = createSettings;
  2788. self.drawer.open = !self.drawer.open
  2789. document.querySelector('#sideBar').style.visibility = 'visible';
  2790. },
  2791. $components: [{
  2792. $type: "i",
  2793. class: "material-icons mdc-list-item__graphic",
  2794. 'aria-hidden': "true",
  2795. $text: "create"
  2796. },
  2797. {
  2798. $text: "Create"
  2799. }]
  2800. },
  2801. {
  2802. $type: "a",
  2803. class: "mdc-list-item",
  2804. $href: "#",
  2805. tabindex: "-1",
  2806. onclick: function (e) {
  2807. e.preventDefault();
  2808. // var currentNode = document.querySelector('#currentNode')._currentNode;
  2809. // if (currentNode == '') {
  2810. // currentNode = vwf_view.kernel.find("", "/")[0];
  2811. // }
  2812. document.querySelector('#liveCodeEditor')._setNode(vwf_view.kernel.find("", "/")[0]);
  2813. //createAceEditor(self, currentNode);
  2814. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  2815. },
  2816. $components: [{
  2817. $type: "i",
  2818. class: "material-icons mdc-list-item__graphic",
  2819. 'aria-hidden': "true",
  2820. $text: "code"
  2821. },
  2822. {
  2823. $text: "Code editor"
  2824. }]
  2825. },
  2826. {
  2827. $type: "a",
  2828. class: "mdc-list-item",
  2829. $href: "#",
  2830. tabindex: "-1",
  2831. onclick: function (e) {
  2832. e.preventDefault();
  2833. //self.currentNodeID = m.ID;
  2834. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2835. // document.querySelector('#clientsWindow').style.visibility = 'visible';
  2836. let sideBar = document.querySelector('#sideBar');
  2837. sideBar._sideBarComponent = avatarSettings;
  2838. self.drawer.open = !self.drawer.open
  2839. document.querySelector('#sideBar').style.visibility = 'visible';
  2840. },
  2841. $components: [{
  2842. $type: "i",
  2843. class: "material-icons mdc-list-item__graphic",
  2844. 'aria-hidden': "true",
  2845. $text: "account_circle"
  2846. },
  2847. {
  2848. $text: "My Avatar"
  2849. }]
  2850. },
  2851. {
  2852. $type: "a",
  2853. class: "mdc-list-item",
  2854. $href: "#",
  2855. tabindex: "-1",
  2856. onclick: function (e) {
  2857. e.preventDefault();
  2858. //self.currentNodeID = m.ID;
  2859. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2860. let sideBar = document.querySelector('#sideBar');
  2861. sideBar._sideBarComponent = viewSettings;
  2862. self.drawer.open = !self.drawer.open
  2863. document.querySelector('#sideBar').style.visibility = 'visible';
  2864. },
  2865. $components: [{
  2866. $type: "i",
  2867. class: "material-icons mdc-list-item__graphic",
  2868. 'aria-hidden': "true",
  2869. $text: "settings"
  2870. },
  2871. {
  2872. $text: "Settings"
  2873. }]
  2874. },
  2875. {
  2876. $type: "a",
  2877. class: "mdc-list-item",
  2878. $href: "#",
  2879. tabindex: "-1",
  2880. onclick: function (e) {
  2881. e.preventDefault();
  2882. //self.currentNodeID = m.ID;
  2883. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2884. let sideBar = document.querySelector('#sideBar');
  2885. sideBar._sideBarComponent = loadSaveSettings;
  2886. if (document.querySelector('#loadSaveSettings')) {
  2887. //document.querySelector('#loadSaveSettings')._refresh();
  2888. //document.querySelector('#loadSaveSettings')._getStates();
  2889. }
  2890. //sideBar._sideBarComponent._getStates();
  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: "save"
  2899. },
  2900. {
  2901. $text: "Clone/Save"
  2902. }]
  2903. },
  2904. self.widgets.divider,
  2905. webrtcGUI,
  2906. self.widgets.divider,
  2907. self.widgets.headerH3("h3", "Users online", "userList mdc-list-group__subheader"),
  2908. clientListCell
  2909. //widgets.headerH3("h3", "WebRTC", "userList mdc-list-group__subheader"),
  2910. ]
  2911. }
  2912. // {
  2913. // $cell: true,
  2914. // $type: "div",
  2915. // class: "mdc-persistent-drawer__toolbar-spacer",
  2916. // },
  2917. // {
  2918. // $cell: true,
  2919. // $type: "div",
  2920. // class: "mdc-list-group",
  2921. // $components: [{
  2922. // $cell: true,
  2923. // $type: "nav",
  2924. // class: "mdc-list",
  2925. // $components: [
  2926. // ]
  2927. // }]
  2928. // }
  2929. ]
  2930. };
  2931. // <div class="mdc-form-field">
  2932. // <input type="checkbox" id="input">
  2933. // <label for="input">Input Label</label>
  2934. // </div>
  2935. document.querySelector("#drawer").$cell({
  2936. $cell: true,
  2937. $type: "aside",
  2938. class: "mdc-drawer mdc-drawer--modal",
  2939. $init: function () {
  2940. let elScrim = document.createElement("div");
  2941. elScrim.classList.add("mdc-drawer-scrim");
  2942. this.after(elScrim);
  2943. self.drawer = new mdc.drawer.MDCDrawer(this);
  2944. },
  2945. $components: [
  2946. {
  2947. $type: "div",
  2948. class: "mdc-drawer__header",
  2949. $components: [
  2950. {
  2951. $type: "h3",
  2952. class: "mdc-drawer__title",
  2953. $text: self.lang.t("home")
  2954. },
  2955. {
  2956. $type: "h6",
  2957. class: "mdc-drawer__subtitle",
  2958. $text: "menu"
  2959. }
  2960. ]
  2961. },
  2962. // {
  2963. // $type: "button"
  2964. // },
  2965. drawerCell]
  2966. }
  2967. );
  2968. let toolbar = {
  2969. $cell: true,
  2970. $type: "div",
  2971. class: "mdc-top-app-bar__row",
  2972. $components: [{
  2973. $type: "section",
  2974. class: "mdc-top-app-bar__section mdc-top-app-bar__section--align-start",
  2975. $components: [
  2976. {
  2977. $type: "button",
  2978. type: "button",
  2979. class: "mdc-icon-button material-icons mdc-top-app-bar__navigation-icon",
  2980. $text: "menu"
  2981. },
  2982. {
  2983. $type: "span",
  2984. class: "mdc-top-app-bar__title catalog-title",
  2985. $text: "LiveCoding.space"
  2986. },
  2987. {
  2988. $type: "div",
  2989. class: "mdc-menu-anchor",
  2990. $components: [
  2991. {
  2992. $type: "a",
  2993. class: "mdc-icon-button material-icons mdc-top-app-bar__action-item",
  2994. id: "toggleCreate",
  2995. $text: "apps",
  2996. 'aria-label': "More"
  2997. },
  2998. {
  2999. $type: "div",
  3000. class: "mdc-menu mdc-menu-surface",
  3001. "tabindex": "-1",
  3002. id: "create-menu",
  3003. $init: function () {
  3004. //var menuEl = document.querySelector('#demo-menu');
  3005. var menu = new mdc.menu.MDCMenu(this);
  3006. var toggle = document.querySelector('#toggleCreate');
  3007. toggle.addEventListener('click', function () {
  3008. menu.open = !menu.open;
  3009. });
  3010. },
  3011. style: "transform-origin: right top 0px; right: 0px; top: 0px;",
  3012. $components: [
  3013. {
  3014. $type: "ul",
  3015. class: "mdc-menu__items mdc-list",
  3016. role: "menu",
  3017. 'aria-hidden': "true",
  3018. // style: "transform: scale(1, 1);",
  3019. $components: [
  3020. {
  3021. $type: "li",
  3022. class: "mdc-list-item",
  3023. role: "menuitem",
  3024. tabindex: "0",
  3025. $text: "Apps"
  3026. }
  3027. ]
  3028. }
  3029. ]
  3030. }
  3031. ]
  3032. },
  3033. self.widgets.icontoggle({
  3034. 'styleClass': "mdc-top-app-bar__action-item",
  3035. 'id': "selectNodeSwitch",
  3036. 'label': 'select',
  3037. 'on': JSON.stringify({ "content": "radio_button_checked", "label": "Select" }),
  3038. 'off': JSON.stringify({ "content": "radio_button_unchecked", "label": "Unselect" }),
  3039. 'state': false,
  3040. 'init': function () {
  3041. this._comp = mdc.iconButton.MDCIconButtonToggle.attachTo(this);
  3042. this.addEventListener('MDCIconButtonToggle:change', (e) => {
  3043. let avatarID = 'avatar-' + vwf.moniker_;
  3044. let avatarNode = self.nodes['avatar-' + vwf.moniker_];
  3045. let mode = JSON.parse(avatarNode.properties.selectMode.getValue());
  3046. if (mode) {
  3047. console.log("unselect");
  3048. vwf_view.kernel.setProperty(avatarID, "selectMode", false);
  3049. } else {
  3050. console.log("select")
  3051. vwf_view.kernel.setProperty(avatarID, "selectMode", true);
  3052. }
  3053. });
  3054. }
  3055. })
  3056. ]
  3057. },
  3058. {
  3059. $type: "section",
  3060. class: "mdc-top-app-bar__section mdc-top-app-bar__section--align-end",
  3061. $components: [
  3062. {
  3063. $type: "a",
  3064. href: "#",
  3065. class: "mdc-icon-button menuItem mdc-top-app-bar__action-item",
  3066. $text: "EN",
  3067. onclick: function () {
  3068. //self.lang.changeLanguageTo('en')
  3069. localStorage.setItem('krestianstvo_locale', 'en');
  3070. window.location.reload(true);
  3071. }
  3072. },
  3073. {
  3074. $type: "a",
  3075. href: "#",
  3076. class: "mdc-icon-button menuItem mdc-top-app-bar__action-item",
  3077. $text: "RU",
  3078. onclick: function () {
  3079. //self.lang.changeLanguageTo('ru')
  3080. localStorage.setItem('krestianstvo_locale', 'ru');
  3081. window.location.reload(true);
  3082. }
  3083. },
  3084. {
  3085. $type: "a",
  3086. href: "#",
  3087. class: "material-icons mdc-icon-button mdc-top-app-bar__action-item",
  3088. $text: "help",
  3089. 'aria-label': "Help",
  3090. onclick: function (e) {
  3091. e.preventDefault();
  3092. console.log("TODO: help window")
  3093. }
  3094. }
  3095. ]
  3096. }
  3097. ]
  3098. };
  3099. document.querySelector("#toolbar").$cell({
  3100. $cell: true,
  3101. $type: "div",
  3102. class: "drawer-frame-app-content",
  3103. $components: [
  3104. {
  3105. $type: "header",
  3106. class: "mdc-top-app-bar drawer-top-app-bar",
  3107. $init: function () {
  3108. const topAppBar = new mdc.topAppBar.MDCTopAppBar.attachTo(this);
  3109. topAppBar.listen('MDCTopAppBar:nav', () => {
  3110. self.drawer.open = !self.drawer.open;
  3111. });
  3112. },
  3113. $components: [
  3114. toolbar
  3115. ]
  3116. }
  3117. ]
  3118. }
  3119. );
  3120. // var toggleNodes = document.querySelectorAll('.mdc-icon-button');
  3121. // toggleNodes.forEach(el => {
  3122. // mdc.iconButton.MDCIconButtonToggle.attachTo(el);
  3123. // });
  3124. //==============
  3125. },
  3126. createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  3127. childSource, childType, childIndex, childName, callback /* ( ready ) */) {
  3128. // var nodeIDAttribute = $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  3129. // var childIDAttribute = $.encoder.encodeForHTMLAttribute("id", childID, true);
  3130. // var childIDAlpha = $.encoder.encodeForAlphaNumeric(childID);
  3131. var kernel = this.kernel;
  3132. var self = this;
  3133. var parent = this.nodes[nodeID];
  3134. var node = this.nodes[childID] = {
  3135. children: [],
  3136. properties: [],
  3137. events: {},
  3138. methods: {},
  3139. parent: parent,
  3140. parentID: nodeID,
  3141. ID: childID,
  3142. extendsID: childExtendsID,
  3143. implementsIDs: childImplementsIDs,
  3144. source: childSource,
  3145. name: childName,
  3146. };
  3147. if (parent) {
  3148. parent.children.push(node);
  3149. }
  3150. if (childID == vwf_view.kernel.find("", "/")[0] && childExtendsID && this.kernel.test(childExtendsID,
  3151. "self::element(*,'http://vwf.example.com/aframe/ascene.vwf')", childExtendsID)) {
  3152. this.scenes[childID] = node;
  3153. }
  3154. let nodeCell = document.querySelector("#currentNode");
  3155. if (nodeCell !== null) {
  3156. if (nodeCell._currentNode === nodeID) {
  3157. nodeCell._getChildNodes();
  3158. }
  3159. }
  3160. if (nodeID === this.kernel.application()) {
  3161. // document.querySelector('a-scene').classList.add("mdc-toolbar-fixed-adjust");
  3162. document.querySelector('body').classList.add("editor-body");
  3163. }
  3164. },
  3165. createdProperty: function (nodeID, propertyName, propertyValue) {
  3166. return this.initializedProperty(nodeID, propertyName, propertyValue);
  3167. },
  3168. initializedProperty: function (nodeID, propertyName, propertyValue) {
  3169. var node = this.nodes[nodeID];
  3170. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  3171. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  3172. node.properties.push(property);
  3173. let nodeCell = document.querySelector("#currentNode");
  3174. if (nodeCell !== null) {
  3175. if (nodeCell._currentNode === nodeID) {
  3176. nodeCell._getNodeProperties();
  3177. }
  3178. }
  3179. },
  3180. deletedNode: function (nodeID) {
  3181. var node = this.nodes[nodeID];
  3182. node.parent.children.splice(node.parent.children.indexOf(node), 1);
  3183. delete this.nodes[nodeID];
  3184. let nodeCell = document.querySelector("#currentNode");
  3185. if (nodeCell) {
  3186. if (nodeCell._currentNode !== "") {
  3187. if (nodeCell._currentNode !== nodeID) {
  3188. //&& (this.nodes[nodeID] !== undefined)
  3189. nodeCell._getChildNodes();
  3190. } else {
  3191. nodeCell._setNode(vwf_view.kernel.find("", "/")[0]);
  3192. nodeCell._getChildNodes();
  3193. }
  3194. }
  3195. }
  3196. },
  3197. //addedChild: [ /* nodeID, childID, childName */ ],
  3198. //removedChild: [ /* nodeID, childID */ ],
  3199. satProperty: function (nodeID, propertyName, propertyValue) {
  3200. var node = this.nodes[nodeID];
  3201. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  3202. // It is possible for a property to have satProperty called for it without ever getting an
  3203. // initializedProperty (if that property delegated to itself or another on replication)
  3204. // Catch that case here and create the property
  3205. if (!node.properties[propertyName]) {
  3206. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  3207. node.properties.push(property);
  3208. }
  3209. try {
  3210. propertyValue = utility.transform(propertyValue, utility.transforms.transit);
  3211. node.properties[propertyName].value = JSON.stringify(propertyValue);
  3212. node.properties[propertyName].rawValue = propertyValue;
  3213. } catch (e) {
  3214. this.logger.warnx("satProperty", nodeID, propertyName, propertyValue,
  3215. "stringify error:", e.message);
  3216. node.properties[propertyName].value = propertyValue;
  3217. }
  3218. let nodeCell = document.querySelector('#currentNode');
  3219. if (nodeCell !== null) {
  3220. if (nodeCell._currentNode == nodeID && propertyName == 'isPlaying') {
  3221. console.log('SET PLAY !!!');
  3222. let compID = 'soundStopStartSwitch-' + nodeID;
  3223. let playSwitch = document.querySelector("[id='" + compID + "']");
  3224. if (playSwitch) {
  3225. // const mycomp = new mdc.iconToggle.MDCIconToggle(playSwitch); //new mdc.select.MDCIconToggle
  3226. playSwitch._comp.on = propertyValue;
  3227. }
  3228. }
  3229. }
  3230. if (nodeCell !== null) {
  3231. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  3232. console.log('EDIT !!!')
  3233. }
  3234. }
  3235. let propCell = document.querySelector("#currentNode #prop-" + propertyName);
  3236. let propSlider = document.querySelector("#currentNode #prop-slider-" + propertyName);
  3237. if (propCell !== null) {
  3238. if (propCell._currentNode == nodeID) {
  3239. propCell.value = node.properties[propertyName].getValue();
  3240. }
  3241. }
  3242. if (propSlider !== null) {
  3243. if (propSlider._currentNode == nodeID) {
  3244. //const propSliderComp = new new mdc.slider.MDCSlider(propSlider);
  3245. propSlider._comp.value = node.properties[propertyName].getValue();
  3246. }
  3247. }
  3248. },
  3249. //gotProperty: [ /* nodeID, propertyName, propertyValue */ ],
  3250. gotProperty: function (nodeID, propertyName, propertyValue) {
  3251. var node = this.nodes[nodeID];
  3252. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  3253. let nodeCell = document.querySelector('#currentNode');
  3254. if (nodeCell !== null) {
  3255. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  3256. let gizmoChild = node.children.filter(el=>el.ID.includes('gizmo'));
  3257. if (gizmoChild.length > 0) {
  3258. let editCheckBox = document.querySelector("#currentNode #editnode");
  3259. if (editCheckBox) {
  3260. let mdcSwitch = editCheckBox._switch;
  3261. if (mdcSwitch) {
  3262. mdcSwitch.checked = propertyValue
  3263. }
  3264. }
  3265. console.log('EDIT !!! is ' + propertyValue)
  3266. }
  3267. }
  3268. }
  3269. },
  3270. createdMethod: function (nodeID, methodName, methodParameters, methodBody) {
  3271. var node = this.nodes[nodeID];
  3272. if (node) {
  3273. node.methods[methodName] = methodParameters;
  3274. }
  3275. },
  3276. //calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {
  3277. //},
  3278. createdEvent: function (nodeID, eventName, eventParameters) {
  3279. var node = this.nodes[nodeID];
  3280. if (node) {
  3281. node.events[eventName] = eventParameters;
  3282. }
  3283. },
  3284. firedEvent: function (nodeID, eventName, eventParameters) {
  3285. var node = this.nodes[nodeID];
  3286. if (node) {
  3287. if (eventName == 'printEvent'){
  3288. var clientThatSatProperty = self.kernel.client();
  3289. var me = self.kernel.moniker();
  3290. // If the transform property was initially updated by this view....
  3291. if ( clientThatSatProperty == me) {
  3292. let editor = document.querySelector("#aceEditor").env.editor;
  3293. if(editor){
  3294. var cursorPosition = editor.getCursorPosition();
  3295. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3296. if (selectedText !== "") {
  3297. cursorPosition = editor.selection.getRange().end;
  3298. }
  3299. let data = eventParameters[0];//JSON.stringify(eventParameters[0]);
  3300. editor.session.insert(cursorPosition, data);
  3301. }
  3302. //console.log(eventParameters);
  3303. }
  3304. }
  3305. }
  3306. },
  3307. executed: function (nodeID, scriptText, scriptType) {
  3308. // var nodeScript = {
  3309. // text: scriptText,
  3310. // type: scriptType,
  3311. // };
  3312. // if ( !this.allScripts[ nodeID ] ) {
  3313. // var nodeScripts = new Array();
  3314. // nodeScripts.push(nodeScript);
  3315. // this.allScripts[ nodeID ] = nodeScripts;
  3316. // }
  3317. // else {
  3318. // this.allScripts[ nodeID ].push(nodeScript);
  3319. // }
  3320. },
  3321. //ticked: [ /* time */ ],
  3322. });
  3323. function createCellWindow(elementID, cellNode, title) {
  3324. document.querySelector('#' + elementID).$cell({
  3325. $cell: true,
  3326. $type: "div",
  3327. id: elementID,
  3328. style: 'position: absolute;',
  3329. class: 'draggable',
  3330. $init: function () {
  3331. // let draggie = new Draggabilly('.draggable', {
  3332. // handle: '.handle',
  3333. // containment: true
  3334. // });
  3335. // get all draggie elements
  3336. var draggableElems = document.querySelectorAll('.draggable');
  3337. // array of Draggabillies
  3338. var draggies = []
  3339. // init Draggabillies
  3340. for (var i = 0, len = draggableElems.length; i < len; i++) {
  3341. var draggableElem = draggableElems[i];
  3342. var draggie = new Draggabilly(draggableElem, {
  3343. handle: '.handle'
  3344. //containment: true
  3345. });
  3346. draggies.push(draggie);
  3347. }
  3348. this.style.visibility = 'hidden';
  3349. },
  3350. $components: [
  3351. {
  3352. $type: "div",
  3353. class: "handle"
  3354. },
  3355. {
  3356. $type: "button",
  3357. class: "mdc-button mdc-button--compact",
  3358. $text: "X",
  3359. onclick: function (e) {
  3360. //self.currentNodeID = m.ID;
  3361. if( elementID == 'codeEditorWindow'){
  3362. //self.nodes[currentNode].liveBindings = {};
  3363. }
  3364. document.querySelector('#' + elementID).style.visibility = 'hidden';
  3365. }
  3366. },
  3367. {
  3368. $type: "span",
  3369. class: "mdc-typography--button",
  3370. $text: title
  3371. },
  3372. cellNode,
  3373. {
  3374. $type: "div",
  3375. class: "handle",
  3376. style: "height: 10px; width: inherit;",
  3377. //$text: "sdfsdf"
  3378. }
  3379. // { $text: "23423"}
  3380. ]
  3381. }
  3382. );
  3383. }
  3384. // -- getChildByName --------------------------------------------------------------------
  3385. function getChildByName(node, childName) {
  3386. var childNode = undefined;
  3387. for (var i = 0; i < node.children.length && childNode === undefined; i++) {
  3388. if (node.children[i].name == childName) {
  3389. childNode = node.children[i];
  3390. }
  3391. }
  3392. return childNode;
  3393. };
  3394. // -- viewScript ------------------------------------------------------------------------
  3395. function createAceEditor(view, nodeID, elID) {
  3396. var editor = view.ace.edit(elID);
  3397. editor.setTheme("ace/theme/monokai");
  3398. editor.setFontSize(20);
  3399. editor.getSession().setMode("ace/mode/javascript");
  3400. editor.commands.addCommand({
  3401. name: "doit",
  3402. bindKey: { win: "Ctrl-e", mac: "Command-e" },
  3403. exec: function () {
  3404. codeEditorDoit(editor, nodeID);
  3405. }
  3406. });
  3407. editor.commands.addCommand({
  3408. name: "printit",
  3409. bindKey: { win: "Ctrl-b", mac: "Command-b" },
  3410. exec: function () {
  3411. codeEditorPrintit(editor, nodeID);
  3412. }
  3413. });
  3414. return editor;
  3415. }
  3416. function isAFrameComponent(nodeID) {
  3417. let node = self.nodes[nodeID];
  3418. let nodeProtos = getPrototypes(self.kernel, node.extendsID);
  3419. if (nodeProtos.includes('http://vwf.example.com/aframe/componentNode.vwf')) {
  3420. return true
  3421. }
  3422. return false
  3423. }
  3424. function isAFrameEntity(nodeID) {
  3425. let node = self.nodes[nodeID];
  3426. let nodeProtos = getPrototypes(self.kernel, node.extendsID);
  3427. if (nodeProtos.includes('http://vwf.example.com/aframe/node.vwf')) {
  3428. return true
  3429. }
  3430. return false
  3431. }
  3432. function getPrototypes(kernel, extendsID) {
  3433. var prototypes = [];
  3434. var id = extendsID;
  3435. while (id !== undefined) {
  3436. prototypes.push(id);
  3437. id = kernel.prototype(id);
  3438. }
  3439. return prototypes;
  3440. }
  3441. function getPrototypes(kernel, extendsID) {
  3442. var prototypes = [];
  3443. var id = extendsID;
  3444. while (id !== undefined) {
  3445. prototypes.push(id);
  3446. id = kernel.prototype(id);
  3447. }
  3448. return prototypes;
  3449. }
  3450. function createProperty(node, propertyName, propertyValue) {
  3451. var property = {
  3452. name: propertyName,
  3453. rawValue: propertyValue,
  3454. value: undefined,
  3455. getValue: function () {
  3456. var propertyValue;
  3457. if (this.value == undefined) {
  3458. try {
  3459. propertyValue = utility.transform(this.rawValue, utility.transforms.transit);
  3460. this.value = JSON.stringify(propertyValue);
  3461. } catch (e) {
  3462. this.logger.warnx("createdProperty", nodeID, this.propertyName, this.rawValue,
  3463. "stringify error:", e.message);
  3464. this.value = this.rawValue;
  3465. }
  3466. }
  3467. return this.value;
  3468. }
  3469. };
  3470. return property;
  3471. }
  3472. function getProperties(kernel, extendsID) {
  3473. var pTypes = getPrototypes(kernel, extendsID);
  3474. var pProperties = {};
  3475. if (pTypes) {
  3476. for (var i = 0; i < pTypes.length; i++) {
  3477. var nd = this.nodes[pTypes[i]];
  3478. if (nd && nd.properties) {
  3479. for (var key in nd.properties) {
  3480. pProperties[key] = { "prop": nd.properties[key], "prototype": pTypes[i] };
  3481. }
  3482. }
  3483. }
  3484. }
  3485. return pProperties;
  3486. }
  3487. function getChildren(kernel, extendsID) {
  3488. var pTypes = getPrototypes(kernel, extendsID);
  3489. var pChildren = {};
  3490. if (pTypes) {
  3491. for (var i = 0; i < pTypes.length; i++) {
  3492. var nd = this.nodes[pTypes[i]];
  3493. if (nd && nd.children) {
  3494. for (var key in nd.children) {
  3495. pChildren[key] = nd.children[key];
  3496. }
  3497. }
  3498. }
  3499. }
  3500. return pChildren;
  3501. }
  3502. function getEvents(kernel, extendsID) {
  3503. var pTypes = getPrototypes(kernel, extendsID);
  3504. var events = {};
  3505. if (pTypes) {
  3506. for (var i = 0; i < pTypes.length; i++) {
  3507. var nd = this.nodes[pTypes[i]];
  3508. if (nd && nd.events) {
  3509. for (var key in nd.events) {
  3510. events[key] = nd.events[key];
  3511. }
  3512. }
  3513. }
  3514. }
  3515. return events;
  3516. }
  3517. function getMethods(kernel, extendsID) {
  3518. var pTypes = getPrototypes(kernel, extendsID);
  3519. var methods = {};
  3520. if (pTypes) {
  3521. for (var i = 0; i < pTypes.length; i++) {
  3522. var nd = this.nodes[pTypes[i]];
  3523. if (nd && nd.methods) {
  3524. for (var key in nd.methods) {
  3525. methods[key] = nd.methods[key];
  3526. }
  3527. }
  3528. }
  3529. }
  3530. return methods;
  3531. }
  3532. // -- Show Code Editor tab
  3533. function codeEditorDoit(editor, nodeID) {
  3534. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3535. if (selectedText == "") {
  3536. var currline = editor.getSelectionRange().start.row;
  3537. var selectedText = editor.session.getLine(currline);
  3538. }
  3539. //console.log(selectedText);
  3540. //var sceneID = self.kernel.application();
  3541. vwf_view.kernel.execute(nodeID, selectedText);
  3542. }
  3543. function codeEditorPrintitInDebugger(editor, nodeID) {
  3544. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3545. if (selectedText == "") {
  3546. var currline = editor.getSelectionRange().start.row;
  3547. var selectedText = editor.session.getLine(currline);
  3548. }
  3549. let scriptText = 'console.log(' + selectedText + ');'
  3550. self.kernel.execute(nodeID, scriptText);
  3551. }
  3552. function codeEditorPrintit(editor, nodeID) {
  3553. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3554. if (selectedText == "") {
  3555. var currline = editor.getSelectionRange().start.row;
  3556. var selectedText = editor.session.getLine(currline);
  3557. }
  3558. //console.log(selectedText);
  3559. //var sceneID = self.kernel.application();
  3560. //vwf.views["vwf/view/editor-new"].nodes[this.id].liveBindings
  3561. //let node = self.nodes[nodeID];
  3562. let me = self.kernel.moniker();
  3563. vwf_view.kernel.fireEvent(nodeID, 'printIt', [selectedText, me]);
  3564. // let printText = _app.helpers.replaceSubStringALL(selectedText,'this','me');
  3565. // let bindString = 'vwf.views["vwf/view/aframe"].nodes["'+ nodeID + '"].liveBindings';
  3566. // let scriptText = 'let binding = '+ bindString +'; binding.me = this; lively.vm.syncEval("var print = ' + printText + '",{topLevelVarRecorder: binding});';
  3567. // vwf_view.kernel.execute(nodeID, scriptText);
  3568. // let scriptText = 'console.log(' + selectedText + ');'
  3569. // self.kernel.execute(nodeID, scriptText);
  3570. }
  3571. function codeEditorPrintitConsole (editor, nodeID) {
  3572. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3573. if (selectedText == "") {
  3574. var currline = editor.getSelectionRange().start.row;
  3575. var selectedText = editor.session.getLine(currline);
  3576. }
  3577. let scriptText = 'console.log(' + selectedText + ');'
  3578. self.kernel.execute(nodeID, scriptText);
  3579. }
  3580. // -- SupportAjax -----------------------------------------------------------------------------
  3581. // function supportAjaxUploadWithProgress() {
  3582. // return supportAjaxUploadProgressEvents();
  3583. // function supportAjaxUploadProgressEvents() {
  3584. // var xhr = new XMLHttpRequest();
  3585. // return !!(xhr && ('upload' in xhr) && ('onprogress' in xhr.upload));
  3586. // }
  3587. // }
  3588. });