editor-new.js 190 KB

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