editor-new.js 196 KB

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