editor-new.js 183 KB

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