editor-new.js 159 KB

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