editor-new.js 181 KB

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