editor-new.js 194 KB

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