editor-new.js 193 KB

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