editor-new.js 186 KB

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