editor-new.js 193 KB

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