editor-new.js 189 KB

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