editor-new.js 196 KB

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