editor-new.js 183 KB

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