editor-new.js 194 KB

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