editor-new.js 176 KB

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