editor-new.js 175 KB

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