editor-new.js 177 KB

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