editor-new.js 157 KB

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