editor-new.js 152 KB

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