editor-new.js 192 KB

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