editor-new.js 174 KB

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