editor-new.js 150 KB

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