editor-new.js 183 KB

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