editor-new.js 195 KB

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