editor-new.js 168 KB

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