editor-new.js 188 KB

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