editor-new.js 195 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256
  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 audioGUI = {
  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: "Sound: "
  1481. }
  1482. ]
  1483. },
  1484. {
  1485. $type: "div",
  1486. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1487. $components: [
  1488. widgets.icontoggle({
  1489. 'id': "soundStopStartSwitch",
  1490. 'label': 'play',
  1491. 'on': JSON.stringify({"content": "pause", "label": "stop"}),
  1492. 'off': JSON.stringify({"content": "play_arrow", "label": "play"}),
  1493. 'state': false,
  1494. 'init': function(){
  1495. var nodeID = this._currentNode;
  1496. this._comp = new mdc.iconToggle.MDCIconToggle(this);
  1497. this.setAttribute('id', "soundStopStartSwitch-" + nodeID );
  1498. let isPlaying = vwf.getProperty(nodeID, 'isPlaying');
  1499. mdc.iconToggle.MDCIconToggle.attachTo(this);
  1500. this._comp.on = isPlaying;
  1501. this.addEventListener('MDCIconToggle:change', (e) => {
  1502. // let avatarID = 'avatar-'+ vwf.moniker_;
  1503. // let avatarNode = self.nodes['avatar-'+ vwf.moniker_];
  1504. // let mode = JSON.parse(avatarNode.properties.selectMode.getValue());
  1505. var nodeID = document.querySelector('#currentNode')._currentNode;
  1506. let isPlaying = vwf.getProperty(nodeID, 'isPlaying');
  1507. if (isPlaying) {
  1508. console.log("stop");
  1509. vwf_view.kernel.callMethod(nodeID, "pauseSound");
  1510. } else {
  1511. console.log("play")
  1512. vwf_view.kernel.callMethod(nodeID, "playSound");
  1513. }
  1514. });
  1515. }
  1516. })
  1517. ]
  1518. },
  1519. {
  1520. $type: "div",
  1521. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1522. $components: [
  1523. {
  1524. $type: "div",
  1525. style: "padding: 12px",
  1526. $components: [
  1527. widgets.iconButton({
  1528. 'label': 'stop',
  1529. onclickfunc: function () {
  1530. var nodeID = this._currentNode;
  1531. vwf_view.kernel.callMethod(nodeID, "stopSound");
  1532. }
  1533. })
  1534. ]
  1535. }
  1536. ]
  1537. }
  1538. // {
  1539. // $type: "div",
  1540. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1541. // $components: [
  1542. // widgets.switch({
  1543. // 'id': 'editnode',
  1544. // 'init': function(){
  1545. // vwf_view.kernel.getProperty(this._currentNode, 'edit');
  1546. // },
  1547. // 'onchange': function(e){
  1548. // var nodeID = document.querySelector('#currentNode')._currentNode;
  1549. // let chkAttr = this.getAttribute('checked');
  1550. // if (chkAttr == "") {
  1551. // self.kernel.setProperty(this._currentNode, 'edit', false);
  1552. // } else {
  1553. // self.kernel.setProperty(this._currentNode, 'edit', true);
  1554. // }
  1555. // vwf_view.kernel.callMethod(nodeID, "showCloseGizmo");
  1556. // }
  1557. // }
  1558. // )
  1559. // ]
  1560. // }
  1561. ]
  1562. }
  1563. ]
  1564. }
  1565. let gizmoEdit = {
  1566. $type: "div",
  1567. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1568. $components: [
  1569. {
  1570. $type: "div",
  1571. class: "mdc-layout-grid__inner",
  1572. $components: [
  1573. {
  1574. $type: "div",
  1575. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1576. $components: [
  1577. {
  1578. $cell: true,
  1579. $type: "span",
  1580. $text: "Edit: ",
  1581. }
  1582. ]
  1583. },
  1584. {
  1585. $type: "div",
  1586. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1587. $components: [
  1588. widgets.switch({
  1589. 'id': 'editnode',
  1590. 'init': function(){
  1591. vwf_view.kernel.getProperty(this._currentNode, 'edit');
  1592. },
  1593. 'onchange': function(e){
  1594. var nodeID = document.querySelector('#currentNode')._currentNode;
  1595. let chkAttr = this.getAttribute('checked');
  1596. if (chkAttr == "") {
  1597. self.kernel.setProperty(this._currentNode, 'edit', false);
  1598. } else {
  1599. self.kernel.setProperty(this._currentNode, 'edit', true);
  1600. }
  1601. vwf_view.kernel.callMethod(nodeID, "showCloseGizmo");
  1602. }
  1603. }
  1604. )
  1605. ]
  1606. },
  1607. {
  1608. $type: "div",
  1609. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1610. $components: [
  1611. self.widgets.imageButton({
  1612. imgSrc: "vwf/view/lib/images/ui/icons/translate.png",
  1613. styleClass: "editButton",
  1614. onclickfunc: function (e) {
  1615. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['translate'])
  1616. }
  1617. })
  1618. ]
  1619. },
  1620. {
  1621. $type: "div",
  1622. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1623. $components: [
  1624. self.widgets.imageButton({
  1625. imgSrc: "vwf/view/lib/images/ui/icons/rotate.png",
  1626. styleClass: "editButton",
  1627. onclickfunc: function (e) {
  1628. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['rotate'])
  1629. }
  1630. })
  1631. ]
  1632. },
  1633. {
  1634. $type: "div",
  1635. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1636. $components: [
  1637. self.widgets.imageButton({
  1638. imgSrc: "vwf/view/lib/images/ui/icons/scale.png",
  1639. styleClass: "editButton",
  1640. onclickfunc: function (e) {
  1641. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['scale'])
  1642. }
  1643. })
  1644. ]
  1645. },
  1646. {
  1647. $type: "div",
  1648. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1649. $components: [
  1650. // self.widgets.floatActionButton({
  1651. // label: "content_copy",
  1652. // styleClass: "mdc-fab--mini"
  1653. // }),
  1654. // {
  1655. // $type: "span",
  1656. // $text: " "
  1657. // },
  1658. self.widgets.floatActionButton({
  1659. label: "delete_forever",
  1660. styleClass: "mdc-fab--mini",
  1661. onclickfunc: function(){
  1662. var nodeID = document.querySelector('#currentNode')._currentNode;
  1663. let node = self.nodes[nodeID];
  1664. //vwf_view.kernel.deleteChild(node.parentID, node.name);
  1665. vwf_view.kernel.deleteNode(nodeID);
  1666. //vwf_view.kernel.callMethod(node.parentID, "deleteNode", [node.name])
  1667. }
  1668. })
  1669. ]
  1670. },
  1671. ]
  1672. }
  1673. ]
  1674. }
  1675. let nodesCell = {
  1676. $cell: true,
  1677. $type: "div",
  1678. id: "currentNode",
  1679. _childNodes: [],
  1680. _currentNode: '',
  1681. _displayedProperties: {},
  1682. _setNode: function (aNode) {
  1683. this._currentNode = aNode;
  1684. document.querySelector('#sideBar')._sideCurrentNode = this._currentNode
  1685. },
  1686. $init: function () {
  1687. this._currentNode = document.querySelector('#sideBar')._sideCurrentNode
  1688. //this._currentNode = vwf_view.kernel.find("", "/")[0];
  1689. //this._currentNode = '3333';
  1690. },
  1691. _getChildNodes: function () {
  1692. this._childNodes = self.nodes[this._currentNode];
  1693. if (this._childNodes !== undefined) {
  1694. return this._childNodes.children
  1695. } else {
  1696. return []
  1697. }
  1698. //let nodeIDAlpha = he.encode(this._currentNode);
  1699. },
  1700. // _getNodeComplexProperties: function () {
  1701. // let node = self.nodes[this._currentNode];
  1702. // let props = this._getNodeProperties();
  1703. // let filterFunction = function (prop) {
  1704. // return (prop.name == 'ohmLang')
  1705. // };
  1706. // let complexProps = props.filter(filterFunction.bind(this));
  1707. // return complexProps
  1708. // },
  1709. _getNodeProperties: function () {
  1710. let node = self.nodes[this._currentNode];
  1711. this._displayedProperties = {};
  1712. let filterFunction = function (prop) {
  1713. return (!this._displayedProperties[prop.name] && prop.name.indexOf('$') === -1) ? (this._displayedProperties[prop.name] = "instance", true) : (false);
  1714. };
  1715. let props = node.properties.filter(filterFunction.bind(this));
  1716. return props
  1717. },
  1718. _getNodeProtoProperties: function () {
  1719. let node = self.nodes[this._currentNode];
  1720. let filterFunction = function (prop) {
  1721. return (!this._displayedProperties[prop[1].prop.name]) ? (this._displayedProperties[prop[1].prop.name] = prop[1].prototype, true) : (false);
  1722. };
  1723. let props = Object.entries(getProperties.call(self, self.kernel, node.extendsID)).filter(filterFunction.bind(this));
  1724. return props
  1725. },
  1726. $update: function () {
  1727. //this.$text = this._currentNode;
  1728. let node = self.nodes[this._currentNode];
  1729. let nodeProtos = getPrototypes(self.kernel, node.extendsID);
  1730. var viewerProps = {};
  1731. var viewerPropsCell = {};
  1732. var gizmoCell = {};
  1733. if (this._currentNode !== self.kernel.application()) {
  1734. if (nodeProtos.includes('http://vwf.example.com/aframe/componentNode.vwf')) {
  1735. //gizmoCell = {};
  1736. if (nodeProtos.includes('http://vwf.example.com/aframe/a-sound-component.vwf'))
  1737. {
  1738. //console.log("sound gui")
  1739. gizmoCell = audioGUI
  1740. }
  1741. } else {
  1742. gizmoCell = gizmoEdit
  1743. }
  1744. }
  1745. if (node !== undefined) {
  1746. if (node.extendsID == "http://vwf.example.com/aframe/acamera.vwf") {
  1747. viewerProps = {
  1748. $type: "li",
  1749. class: "mdc-list-item",
  1750. $components: [
  1751. {
  1752. $text: "Viewer properties",
  1753. $type: "span",
  1754. class: "mdc-list-item__text mdc-typography--button"
  1755. }
  1756. ]
  1757. }
  1758. viewerPropsCell = {
  1759. $cell: true,
  1760. $type: "div",
  1761. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1762. $components: [
  1763. {
  1764. $cell: true,
  1765. $type: "div",
  1766. class: "mdc-layout-grid__inner",
  1767. $components: [
  1768. {
  1769. $cell: true,
  1770. $type: "div",
  1771. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1772. $components: [
  1773. widgets.buttonStroked(
  1774. {
  1775. "label": "Active",
  1776. "onclick": function (e) {
  1777. //let camera = document.querySelector('#' + this._currentNode);
  1778. vwf_view.kernel.callMethod(this._currentNode, "setCameraToActive", [vwf.moniker_]);
  1779. //camera.setAttribute('camera', 'active', true);
  1780. }
  1781. })
  1782. ]
  1783. }
  1784. ]
  1785. }
  1786. ]
  1787. //$components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1788. }
  1789. } else {
  1790. viewerProps = {};
  1791. viewerPropsCell = {};
  1792. }
  1793. }
  1794. this.$components = [
  1795. {
  1796. $cell: true,
  1797. $type: "ul",
  1798. class: "mdc-list",
  1799. $components: [
  1800. widgets.buttonStroked(
  1801. {
  1802. "label": "<--",
  1803. "onclick": function (e) {
  1804. let node = self.nodes[this._currentNode];
  1805. if (node.parentID !== 0) {
  1806. //self.currentNodeID = node.parentID,
  1807. document.querySelector('#currentNode')._setNode(node.parentID)
  1808. }
  1809. }
  1810. }),
  1811. {
  1812. $type: "li",
  1813. class: "mdc-list-item",
  1814. $components: [
  1815. {
  1816. $text: "name",
  1817. $type: "span",
  1818. $init: function () {
  1819. let node = self.nodes[this._currentNode];
  1820. if (node) {
  1821. let displayName = vwf.getProperty(node.ID, 'displayName');
  1822. if (displayName)
  1823. {
  1824. this.$text = displayName
  1825. } else {
  1826. this.$text = node.name;
  1827. }
  1828. }
  1829. //console.log(node.properties.displayName)
  1830. },
  1831. class: "mdc-list-item__text mdc-typography--headline"
  1832. //<h1 class="mdc-typography--display4">Big header</h1>
  1833. }]
  1834. }, listDivider,
  1835. {
  1836. // $cell: true,
  1837. // $type: "ul",
  1838. // class: "mdc-list",
  1839. $type: "div",
  1840. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1841. $components: [
  1842. {
  1843. $type: "div",
  1844. class: "mdc-layout-grid__inner",
  1845. $components: [
  1846. {
  1847. $type: "div",
  1848. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1849. $components: [
  1850. widgets.buttonStroked(
  1851. {
  1852. "label": "Methods browser",
  1853. "onclick": function (e) {
  1854. var currentNode = document.querySelector('#currentNode')._currentNode;
  1855. if (currentNode == '') {
  1856. currentNode = vwf_view.kernel.find("", "/")[0];
  1857. }
  1858. document.querySelector('#liveCodeEditor')._setNode(currentNode);
  1859. //createAceEditor(self, currentNode);
  1860. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  1861. }
  1862. })
  1863. ]
  1864. }
  1865. ]
  1866. }
  1867. ]
  1868. },
  1869. gizmoCell,
  1870. listDivider,
  1871. {
  1872. $type: "li",
  1873. class: "mdc-list-item",
  1874. $components: [
  1875. {
  1876. $text: "Children",
  1877. $type: "span",
  1878. class: "mdc-list-item__text mdc-typography--button"
  1879. }]
  1880. },
  1881. {
  1882. $cell: true,
  1883. $type: "ul",
  1884. class: "mdc-list",
  1885. $components: this._getChildNodes().map(nodeLink)
  1886. }, listDivider, {
  1887. $type: "li",
  1888. class: "mdc-list-item",
  1889. $components: [
  1890. {
  1891. $text: "Properties",
  1892. $type: "span",
  1893. class: "mdc-list-item__text mdc-typography--button"
  1894. //<h1 class="mdc-typography--display4">Big header</h1>
  1895. }]
  1896. },
  1897. {
  1898. // $cell: true,
  1899. // $type: "ul",
  1900. // class: "mdc-list",
  1901. $type: "div",
  1902. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1903. $components: this._getNodeProperties().map(propertiesCell)
  1904. },
  1905. listDivider,
  1906. {
  1907. $type: "li",
  1908. class: "mdc-list-item",
  1909. $components: [
  1910. {
  1911. $text: "Proto properties",
  1912. $type: "span",
  1913. class: "mdc-list-item__text mdc-typography--button"
  1914. }]
  1915. },
  1916. {
  1917. $cell: true,
  1918. $type: "div",
  1919. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1920. $components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1921. }, listDivider,
  1922. viewerProps,
  1923. viewerPropsCell
  1924. ]
  1925. }
  1926. ]
  1927. }
  1928. }
  1929. let numberSliderComponent = {
  1930. $cell: true,
  1931. $type: "div",
  1932. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  1933. $init: function () {
  1934. },
  1935. $components: [
  1936. {
  1937. $cell: true,
  1938. $type: "div",
  1939. style: "padding: 0 16px;",
  1940. $components:[
  1941. {}
  1942. ]
  1943. }
  1944. ]
  1945. }
  1946. let colorPickerComponent = {
  1947. $cell: true,
  1948. $type: "div",
  1949. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  1950. $init: function () {
  1951. let myEl = this;
  1952. let cp = ColorPicker(
  1953. document.getElementById('slide'),
  1954. document.getElementById('picker'),
  1955. function (hex, hsv, rgb, mousePicker, mouseSlide) {
  1956. ColorPicker.positionIndicators(
  1957. document.getElementById('slide-indicator'),
  1958. document.getElementById('picker-indicator'),
  1959. mouseSlide, mousePicker
  1960. );
  1961. if (myEl._propName.toLowerCase().includes('color')) {
  1962. // console.log(hex);
  1963. document.querySelector('#propAceEditor').env.editor.setValue(JSON.stringify(hex));
  1964. self.kernel.setProperty(myEl._editorNode, myEl._propName, hex);
  1965. }
  1966. });
  1967. if (myEl._propName.toLowerCase().includes('color')) {
  1968. cp.setHex(JSON.parse(myEl._prop.body));
  1969. }
  1970. },
  1971. $components: [
  1972. {
  1973. $cell: true,
  1974. $type: "div",
  1975. id: "color-picker",
  1976. class: "cp-default",
  1977. $components: [
  1978. {
  1979. $cell: true,
  1980. $type: "div",
  1981. class: "picker-wrapper",
  1982. $components: [
  1983. {
  1984. $cell: true,
  1985. $type: "div",
  1986. id: "picker",
  1987. class: "picker",
  1988. style: "width: 130px; height: 130px"
  1989. },
  1990. {
  1991. $cell: true,
  1992. $type: "div",
  1993. id: "picker-indicator",
  1994. class: "picker-indicator"
  1995. }
  1996. ]
  1997. },
  1998. {
  1999. $cell: true,
  2000. $type: "div",
  2001. class: "slide-wrapper",
  2002. $components: [
  2003. {
  2004. $cell: true,
  2005. $type: "div",
  2006. id: "slide",
  2007. class: "slide",
  2008. style: "width: 30px; height: 130px"
  2009. },
  2010. {
  2011. $cell: true,
  2012. $type: "div",
  2013. id: "slide-indicator",
  2014. class: "slide-indicator"
  2015. }
  2016. ]
  2017. }
  2018. ]
  2019. }
  2020. // {
  2021. // $cell: true,
  2022. // $type: "div",
  2023. // id: "color-picker",
  2024. // $init: function () {
  2025. // }
  2026. // }
  2027. ]
  2028. }
  2029. let propEditorWindow = {
  2030. $cell: true,
  2031. $type: "div",
  2032. _editorNode: '',
  2033. _prop: { body: '', type: 'simple' },
  2034. _propName: '',
  2035. id: "livePropEditor",
  2036. _setNode: function (node) {
  2037. this._editorNode = node;
  2038. this._prop.body = ''
  2039. },
  2040. class: "propEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2041. $update: function () {
  2042. var editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-8"
  2043. var livePropertyComponent = {}
  2044. if (this._prop.type == 'simple') {
  2045. if (this._propName.toLowerCase().includes('color')) {
  2046. livePropertyComponent = colorPickerComponent
  2047. }
  2048. } else {
  2049. editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-12"
  2050. }
  2051. this.$components = [
  2052. {
  2053. $cell: true,
  2054. $type: "div",
  2055. class: "mdc-layout-grid__inner",
  2056. $components: [
  2057. {
  2058. $cell: true,
  2059. $type: "div",
  2060. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2061. $components: [
  2062. widgets.buttonStroked(
  2063. {
  2064. "label": "Update",
  2065. "onclick": function (e) {
  2066. let editor = document.querySelector("#propAceEditor").env.editor;
  2067. let value = editor.getValue();
  2068. try {
  2069. let propValue = (this._prop.type == 'simple') ? (JSON.parse(value)) : (value)
  2070. //propValue = JSON.parse(value);
  2071. self.kernel.setProperty(this._editorNode, this._propName, propValue);
  2072. } catch (e) {
  2073. // restore the original value on error
  2074. this.value = propValue;
  2075. }
  2076. }
  2077. }
  2078. )]
  2079. },
  2080. {
  2081. $cell: true,
  2082. $type: "div",
  2083. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  2084. $components: [
  2085. {
  2086. $type: "h3",
  2087. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  2088. $text: this._editorNode
  2089. }
  2090. ]
  2091. },
  2092. {
  2093. $cell: true,
  2094. $type: "div",
  2095. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  2096. $components: [
  2097. {
  2098. $type: "h3",
  2099. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  2100. $text: this._propName
  2101. }
  2102. ]
  2103. }
  2104. ]
  2105. },
  2106. {
  2107. $cell: true,
  2108. $type: "div",
  2109. class: "mdc-layout-grid__inner",
  2110. $components: [
  2111. {
  2112. $cell: true,
  2113. $type: "div",
  2114. class: editorClass,
  2115. $components: [
  2116. {
  2117. $cell: true,
  2118. class: "aceEditor",
  2119. id: "propAceEditor",
  2120. $type: "div",
  2121. $text: this._prop.body,
  2122. $init: function () {
  2123. createAceEditor(self, this._editorNode, "propAceEditor");
  2124. this.env.editor.$blockScrolling = Infinity
  2125. }
  2126. }
  2127. ]
  2128. }, livePropertyComponent
  2129. // {
  2130. // $cell: true,
  2131. // $type: "div",
  2132. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2133. // $components: []
  2134. // },
  2135. ]
  2136. }
  2137. ]
  2138. //$components:
  2139. }
  2140. }
  2141. let codeEditorWindow = {
  2142. $cell: true,
  2143. $type: "div",
  2144. _editorNode: '',
  2145. _method: { body: '' },
  2146. _methodName: '',
  2147. _getNodeMethods: function () {
  2148. let node = self.nodes[this._editorNode];
  2149. return node.methods
  2150. },
  2151. _getProtoNodeMethods: function () {
  2152. let node = self.nodes[this._editorNode];
  2153. let prototypeMethods = getMethods.call(self, self.kernel, node.extendsID);
  2154. return prototypeMethods
  2155. },
  2156. id: "liveCodeEditor",
  2157. _setNode: function (node) {
  2158. this._editorNode = node;
  2159. this._method.body = ''
  2160. },
  2161. class: "codeEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2162. // _getComplexProps: function(){
  2163. // let node = self.nodes[this._editorNode];
  2164. // let currentNode = document.querySelector('#currentNode');
  2165. // var props = {}
  2166. // if (currentNode !== null) {
  2167. // props = currentNode._getNodeComplexProperties();
  2168. // }
  2169. // return props
  2170. // },
  2171. // _listPropertyElement: function (m) {
  2172. // return {
  2173. // $type: "li",
  2174. // class: "mdc-list-item",
  2175. // $components: [{
  2176. // $type: "a",
  2177. // class: "mdc-list-item",
  2178. // $href: "#",
  2179. // $text: m[1].name,
  2180. // onclick: function (e) {
  2181. // this._method = {};
  2182. // this._methodName = m[1].name;
  2183. // this._method.body = m[1].rawValue
  2184. // this._method.type = "complexProperty"
  2185. // }
  2186. // }]
  2187. // }
  2188. // },
  2189. _listElement: function (m) {
  2190. return {
  2191. $type: "li",
  2192. class: "mdc-list-item",
  2193. $components: [{
  2194. $type: "a",
  2195. class: "mdc-list-item",
  2196. $href: "#",
  2197. $text: m[0],
  2198. onclick: function (e) {
  2199. let method = vwf.getMethod(this._editorNode, m[0]);
  2200. //document.querySelector('#aceEditor').
  2201. this._method = method;
  2202. this._methodName = m[0];
  2203. //self.currentNodeID = m.ID;
  2204. //document.querySelector('#currentNode')._setNode(m.ID);
  2205. }
  2206. }]
  2207. }
  2208. },
  2209. $update: function () {
  2210. this.$components = [
  2211. {
  2212. $cell: true,
  2213. $type: "div",
  2214. class: "mdc-layout-grid__inner",
  2215. $components: [
  2216. {
  2217. $cell: true,
  2218. $type: "div",
  2219. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2220. $components: [
  2221. {
  2222. $type: "h3",
  2223. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  2224. $text: this._editorNode
  2225. }
  2226. ]
  2227. },
  2228. {
  2229. $cell: true,
  2230. $type: "div",
  2231. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2232. $components: [
  2233. widgets.buttonStroked(
  2234. {
  2235. "label": "Update",
  2236. "onclick": function (e) {
  2237. let editor = document.querySelector("#aceEditor").env.editor;
  2238. let evalText = editor.getValue();
  2239. // if (this._method.type == 'complexProperty') {
  2240. // let propValue = evalText;
  2241. // try {
  2242. // //propValue = JSON.parse(propValue);
  2243. // self.kernel.setProperty(this._editorNode, this._methodName, propValue);
  2244. // } catch (e) {
  2245. // // restore the original value on error
  2246. // this.value = propValue;
  2247. // }
  2248. // } else {
  2249. // }
  2250. self.kernel.setMethod(this._editorNode, this._methodName,
  2251. { body: evalText, type: "application/javascript", parameters: this._method.parameters });
  2252. }
  2253. }
  2254. )]
  2255. },
  2256. {
  2257. $cell: true,
  2258. $type: "div",
  2259. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2260. $components: [
  2261. widgets.buttonStroked(
  2262. {
  2263. "label": "Call",
  2264. "onclick": function (e) {
  2265. var params = [];
  2266. if (this._method.parameters) {
  2267. let paramsLength = this._method.parameters.length
  2268. if (paramsLength >= 1) {
  2269. let paramsVal = document.querySelector("#methodParams").value;
  2270. try {
  2271. params = JSON.parse(paramsVal);
  2272. //params.push(prmtr);
  2273. } catch (e) {
  2274. self.logger.error('Invalid Value');
  2275. }
  2276. }
  2277. };
  2278. self.kernel.callMethod(this._editorNode, this._methodName, params);
  2279. }
  2280. })
  2281. ]
  2282. },
  2283. {
  2284. $cell: true,
  2285. $type: "div",
  2286. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2287. $components: [
  2288. widgets.buttonStroked(
  2289. {
  2290. "label": "Do It",
  2291. "onclick": function (e) {
  2292. let editor = document.querySelector("#aceEditor").env.editor;
  2293. codeEditorDoit.call(self, editor, this._editorNode);
  2294. }
  2295. })
  2296. ]
  2297. },
  2298. {
  2299. $cell: true,
  2300. $type: "div",
  2301. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2302. $components: [
  2303. widgets.buttonStroked(
  2304. {
  2305. "label": "Print It",
  2306. "onclick": function (e) {
  2307. let editor = document.querySelector("#aceEditor").env.editor;
  2308. codeEditorPrintit.call(self, editor, this._editorNode);
  2309. }
  2310. })
  2311. ]
  2312. }
  2313. ]
  2314. },
  2315. {
  2316. $cell: true,
  2317. $type: "div",
  2318. class: "mdc-layout-grid__inner",
  2319. $components: [
  2320. {
  2321. $cell: true,
  2322. $type: "div",
  2323. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2324. style: "overflow-y: scroll; max-height: 400px;",
  2325. $components: [
  2326. {
  2327. $cell: true,
  2328. $type: "div",
  2329. class: "mdc-list-group",
  2330. $components: [
  2331. {
  2332. $type: "h3",
  2333. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2334. $text: "Node methods"
  2335. },
  2336. {
  2337. $cell: true,
  2338. $type: "ul",
  2339. class: "mdc-list",
  2340. $components: Object.entries(this._getNodeMethods()).map(this._listElement)
  2341. }, listDivider,
  2342. {
  2343. $type: "h3",
  2344. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2345. $text: "Proto methods"
  2346. },
  2347. {
  2348. $cell: true,
  2349. $type: "ul",
  2350. class: "mdc-list",
  2351. $components: Object.entries(this._getProtoNodeMethods()).map(this._listElement)
  2352. }, listDivider,
  2353. {
  2354. $type: "h3",
  2355. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2356. $text: "Events"
  2357. }
  2358. // {
  2359. // $cell: true,
  2360. // $type: "ul",
  2361. // class: "mdc-list",
  2362. // $components: Object.entries(this._getComplexProps()).map(this._listPropertyElement)
  2363. // }
  2364. ]
  2365. }
  2366. ]
  2367. },
  2368. {
  2369. $cell: true,
  2370. $type: "div",
  2371. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-9",
  2372. $components: [
  2373. {
  2374. $cell: true,
  2375. class: "aceEditor",
  2376. id: "aceEditor",
  2377. $type: "div",
  2378. $text: this._method.body,
  2379. $init: function () {
  2380. createAceEditor(self, this._editorNode, "aceEditor");
  2381. }
  2382. }
  2383. ]
  2384. }
  2385. ]
  2386. },
  2387. {
  2388. $cell: true,
  2389. $type: "div",
  2390. class: "mdc-layout-grid__inner",
  2391. $components: [
  2392. {
  2393. $cell: true,
  2394. $type: "div",
  2395. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2396. $components: [
  2397. {
  2398. $type: "span",
  2399. $text: "*"
  2400. }
  2401. ]
  2402. }
  2403. ]
  2404. },
  2405. { //params input
  2406. $cell: true,
  2407. $type: "div",
  2408. class: "mdc-layout-grid__inner",
  2409. $components: [
  2410. {
  2411. $cell: true,
  2412. $type: "div",
  2413. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2414. $components: [
  2415. {
  2416. class: "mdc-text-field",
  2417. $cell: true,
  2418. $type: "div",
  2419. $components: [{
  2420. class: "mdc-text-field__input prop-text-field-input",
  2421. id: "methodName",
  2422. $cell: true,
  2423. $type: "input",
  2424. type: "text",
  2425. value: "newMethodName",
  2426. onchange: function (e) {
  2427. let propValue = this.value;
  2428. try {
  2429. } catch (e) {
  2430. // restore the original value on error
  2431. }
  2432. }
  2433. }]
  2434. }
  2435. ]
  2436. },
  2437. {
  2438. $cell: true,
  2439. $type: "div",
  2440. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  2441. $components: [
  2442. {
  2443. class: "mdc-text-field params-text-field-input",
  2444. $cell: true,
  2445. $type: "div",
  2446. $components: [{
  2447. class: "mdc-text-field__input prop-text-field-input",
  2448. id: "methodParams",
  2449. $cell: true,
  2450. $type: "input",
  2451. type: "text",
  2452. value: JSON.stringify(this._method.parameters),
  2453. onchange: function (e) {
  2454. let propValue = this.value;
  2455. try {
  2456. } catch (e) {
  2457. // restore the original value on error
  2458. }
  2459. }
  2460. }]
  2461. }
  2462. ]
  2463. },
  2464. {
  2465. $cell: true,
  2466. $type: "div",
  2467. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2468. $components: [
  2469. widgets.buttonStroked(
  2470. {
  2471. "label": "Create",
  2472. "onclick": function (e) {
  2473. let methodName = document.querySelector('#methodName').value;
  2474. //let methodParams = document.querySelector('#methodParams');
  2475. var params = [];
  2476. let body = '';
  2477. let paramsVal = document.querySelector("#methodParams").value;
  2478. if (paramsVal !== '') {
  2479. try {
  2480. params = JSON.parse(paramsVal);
  2481. //params.push(prmtr);
  2482. } catch (e) {
  2483. self.logger.error('Invalid Value');
  2484. }
  2485. }
  2486. self.kernel.createMethod(this._editorNode, methodName, params, body);
  2487. this._setNode(this._editorNode);
  2488. // let editor = document.querySelector("#aceEditor").env.editor;
  2489. // codeEditorDoit.call(self, editor, this._editorNode);
  2490. }
  2491. })
  2492. ]
  2493. }
  2494. ]
  2495. }
  2496. ]
  2497. //$components:
  2498. }
  2499. }
  2500. let propWindow = {
  2501. $cell: true,
  2502. $type: "div",
  2503. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2504. style: "overflow-y: scroll; max-height: 800px;",
  2505. $components: [
  2506. {
  2507. $type: "div",
  2508. class: "mdc-layout-grid__inner",
  2509. $components: [
  2510. {
  2511. $cell: true,
  2512. $type: "div",
  2513. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2514. $components: [
  2515. nodesCell
  2516. ]
  2517. }
  2518. ]
  2519. }
  2520. // <button class="mdc-button">
  2521. // Flat button
  2522. // </button>
  2523. ]
  2524. }
  2525. let clientListCell = {
  2526. $cell: true,
  2527. $type: "div",
  2528. class: "mdc-list",
  2529. id: "clientsList",
  2530. _watchNodes: [],
  2531. _listElement: function (m) {
  2532. return {
  2533. $type: "a",
  2534. class: "mdc-list-item",
  2535. $href: "#",
  2536. $text: m.name,
  2537. onclick: function (e) {
  2538. //self.currentNodeID = m.ID;
  2539. //document.querySelector('#currentNode')._setNode(m.ID);
  2540. }
  2541. }
  2542. },
  2543. $init: function () {
  2544. var t = this;
  2545. setInterval(function () {
  2546. t._updateMe();
  2547. }, 1000);
  2548. },
  2549. _updateMe: function () {
  2550. this._watchNodes = self.nodes["http://vwf.example.com/clients.vwf"].children.slice()
  2551. },
  2552. $update: function () {
  2553. //this._clientNodes
  2554. this.$components = this._watchNodes.map(this._listElement)
  2555. }
  2556. }
  2557. //createCellWindow("clientsWindow", clientListCell, "Clients");
  2558. //createCellWindow("propWindow", propWindow, "Scene");
  2559. createCellWindow("codeEditorWindow", codeEditorWindow, "Code editor");
  2560. createCellWindow("propEditorWindow", propEditorWindow, "Prop editor");
  2561. let viewSceneProps = {
  2562. $cell: true,
  2563. $type: "div",
  2564. class: "propGrid mdc-layout-grid mdc-layout-grid--align-left",
  2565. //style: "overflow-y: scroll; max-height: 500px; overflow-x: hidden;",
  2566. $components: [
  2567. {
  2568. $type: "div",
  2569. class: "mdc-layout-grid__inner",
  2570. $components: [
  2571. {
  2572. $cell: true,
  2573. $type: "div",
  2574. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2575. $components: [
  2576. nodesCell
  2577. ]
  2578. }
  2579. ]
  2580. }
  2581. ]
  2582. }
  2583. let sideBar = {
  2584. $cell: true,
  2585. $type: "div",
  2586. id: 'sideBar',
  2587. class: "sideBar mdc-toolbar-fixed-adjust",
  2588. _sideBarComponent: {},
  2589. _sideCurrentNode: '',
  2590. $init: function () {
  2591. this.style.visibility = 'hidden';
  2592. this._importScript("/" + self.getRoot() + "/appui.js");
  2593. },
  2594. _importScript: function (sSrc, fOnload) {
  2595. var oScript = document.createElement("script");
  2596. oScript.type = "text\/javascript";
  2597. oScript.async = false;
  2598. //oScript.onerror = loadError;
  2599. if (fOnload) { oScript.onload = fOnload; }
  2600. oScript.src = sSrc;
  2601. //let sideBar = document.querySelector('#sideBar');
  2602. this.appendChild(oScript);
  2603. },
  2604. _getAppDef: async function () {
  2605. let response = await fetch("/" + self.getRoot() + "/appui.js");
  2606. let data = await response.text();
  2607. //console.log(data)
  2608. return data
  2609. },
  2610. $update: function () {
  2611. this.$components = [
  2612. {
  2613. $cell: true,
  2614. $type: "button",
  2615. class: "mdc-button mdc-button--compact",
  2616. $text: "X",
  2617. onclick: function (e) {
  2618. document.querySelector('#sideBar').style.visibility = 'hidden';
  2619. }
  2620. },
  2621. this._sideBarComponent
  2622. ]
  2623. }
  2624. //$components: [this._sideComponents]
  2625. }
  2626. document.querySelector('#' + 'sideBar').$cell(sideBar)
  2627. let defaultApp = function () {
  2628. return {
  2629. $cell: true,
  2630. $type: "div",
  2631. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  2632. $components: [
  2633. {
  2634. $cell: true,
  2635. $type: "div",
  2636. class: "mdc-layout-grid__inner",
  2637. $components: [
  2638. {
  2639. $cell: true,
  2640. $type: "div",
  2641. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2642. $components: [
  2643. {
  2644. $cell: true,
  2645. $type: "h3",
  2646. class: "mdc-typography--headline",
  2647. $text: "Application",
  2648. }
  2649. ]
  2650. }
  2651. ]
  2652. }
  2653. ]
  2654. }
  2655. }
  2656. let drawerCell = {
  2657. $cell: true,
  2658. $type: "nav",
  2659. class: "mdc-temporary-drawer__drawer",
  2660. $components: [
  2661. {
  2662. $cell: true,
  2663. $type: "header",
  2664. class: "mdc-temporary-drawer__header",
  2665. $components: [
  2666. {
  2667. $cell: true,
  2668. $type: "div",
  2669. class: "mdc-temporary-drawer__header-content mdc-theme--primary-bg mdc-theme--text-primary-on-primary",
  2670. $text: self.lang.t("home")
  2671. }
  2672. ]
  2673. },
  2674. {
  2675. $cell: true,
  2676. $type: "nav",
  2677. class: "mdc-temporary-drawer__content mdc-list-group",
  2678. $components: [
  2679. {
  2680. $cell: true,
  2681. $type: "div",
  2682. class: "mdc-list",
  2683. $components: [
  2684. {
  2685. $cell: true,
  2686. $type: "a",
  2687. class: "mdc-list-item",
  2688. $href: "#",
  2689. onclick: function (e) {
  2690. let sideBar = document.querySelector('#sideBar');
  2691. try {
  2692. sideBar._sideBarComponent = createApp.call(self);
  2693. } catch (e) {
  2694. sideBar._sideBarComponent = defaultApp();
  2695. }
  2696. drawer.open = !drawer.open
  2697. document.querySelector('#sideBar').style.visibility = 'visible';
  2698. },
  2699. $components: [{
  2700. $type: "i",
  2701. class: "material-icons mdc-list-item__start-detail",
  2702. 'aria-hidden': "true",
  2703. $text: "play_arrow"
  2704. },
  2705. {
  2706. $text: self.lang.t("App")
  2707. }]
  2708. },
  2709. {
  2710. $cell: true,
  2711. $type: "a",
  2712. class: "mdc-list-item",
  2713. $href: "#",
  2714. onclick: function (e) {
  2715. let sideBar = document.querySelector('#sideBar');
  2716. sideBar._sideBarComponent = viewSceneProps;
  2717. let currentNode = document.querySelector('#sideBar')._sideCurrentNode;
  2718. currentNode == '' ? document.querySelector('#sideBar')._sideCurrentNode = (vwf_view.kernel.find("", "/")[0]) :
  2719. document.querySelector('#sideBar')._sideCurrentNode = currentNode;
  2720. document.querySelector('#sideBar').style.visibility = 'visible';
  2721. drawer.open = !drawer.open
  2722. // let currentNode = document.querySelector('#currentNode')._currentNode;
  2723. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  2724. // document.querySelector('#currentNode')._setNode(currentNode);
  2725. },
  2726. $components: [{
  2727. $cell: true,
  2728. $type: "i",
  2729. class: "material-icons mdc-list-item__start-detail",
  2730. $text: "description"
  2731. },
  2732. {
  2733. $text: "Scene"
  2734. }
  2735. ]
  2736. },
  2737. {
  2738. $cell: true,
  2739. $type: "a",
  2740. class: "mdc-list-item",
  2741. $href: "#",
  2742. onclick: function (e) {
  2743. //self.currentNodeID = m.ID;
  2744. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2745. // document.querySelector('#clientsWindow').style.visibility = 'visible';
  2746. let sideBar = document.querySelector('#sideBar');
  2747. sideBar._sideBarComponent = createSettings;
  2748. drawer.open = !drawer.open
  2749. document.querySelector('#sideBar').style.visibility = 'visible';
  2750. },
  2751. $components: [{
  2752. $type: "i",
  2753. class: "material-icons mdc-list-item__start-detail",
  2754. 'aria-hidden': "true",
  2755. $text: "create"
  2756. },
  2757. {
  2758. $text: "Create"
  2759. }]
  2760. },
  2761. {
  2762. $cell: true,
  2763. $type: "a",
  2764. class: "mdc-list-item",
  2765. $href: "#",
  2766. onclick: function (e) {
  2767. // var currentNode = document.querySelector('#currentNode')._currentNode;
  2768. // if (currentNode == '') {
  2769. // currentNode = vwf_view.kernel.find("", "/")[0];
  2770. // }
  2771. document.querySelector('#liveCodeEditor')._setNode(vwf_view.kernel.find("", "/")[0]);
  2772. //createAceEditor(self, currentNode);
  2773. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  2774. },
  2775. $components: [{
  2776. $type: "i",
  2777. class: "material-icons mdc-list-item__start-detail",
  2778. 'aria-hidden': "true",
  2779. $text: "code"
  2780. },
  2781. {
  2782. $text: "Code editor"
  2783. }]
  2784. },
  2785. {
  2786. $cell: true,
  2787. $type: "a",
  2788. class: "mdc-list-item",
  2789. $href: "#",
  2790. onclick: function (e) {
  2791. //self.currentNodeID = m.ID;
  2792. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2793. // document.querySelector('#clientsWindow').style.visibility = 'visible';
  2794. let sideBar = document.querySelector('#sideBar');
  2795. sideBar._sideBarComponent = avatarSettings;
  2796. drawer.open = !drawer.open
  2797. document.querySelector('#sideBar').style.visibility = 'visible';
  2798. },
  2799. $components: [{
  2800. $type: "i",
  2801. class: "material-icons mdc-list-item__start-detail",
  2802. 'aria-hidden': "true",
  2803. $text: "account_circle"
  2804. },
  2805. {
  2806. $text: "My Avatar"
  2807. }]
  2808. },
  2809. {
  2810. $cell: true,
  2811. $type: "a",
  2812. class: "mdc-list-item",
  2813. $href: "#",
  2814. onclick: function (e) {
  2815. //self.currentNodeID = m.ID;
  2816. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2817. let sideBar = document.querySelector('#sideBar');
  2818. sideBar._sideBarComponent = viewSettings;
  2819. drawer.open = !drawer.open
  2820. document.querySelector('#sideBar').style.visibility = 'visible';
  2821. },
  2822. $components: [{
  2823. $type: "i",
  2824. class: "material-icons mdc-list-item__start-detail",
  2825. 'aria-hidden': "true",
  2826. $text: "settings"
  2827. },
  2828. {
  2829. $text: "Settings"
  2830. }]
  2831. },
  2832. {
  2833. $cell: true,
  2834. $type: "a",
  2835. class: "mdc-list-item",
  2836. $href: "#",
  2837. onclick: function (e) {
  2838. //self.currentNodeID = m.ID;
  2839. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2840. let sideBar = document.querySelector('#sideBar');
  2841. sideBar._sideBarComponent = loadSaveSettings;
  2842. if (document.querySelector('#loadSaveSettings')) {
  2843. document.querySelector('#loadSaveSettings')._getStates();
  2844. }
  2845. //sideBar._sideBarComponent._getStates();
  2846. drawer.open = !drawer.open
  2847. document.querySelector('#sideBar').style.visibility = 'visible';
  2848. },
  2849. $components: [{
  2850. $type: "i",
  2851. class: "material-icons mdc-list-item__start-detail",
  2852. 'aria-hidden': "true",
  2853. $text: "save"
  2854. },
  2855. {
  2856. $text: "Load/Save"
  2857. }]
  2858. }
  2859. ]
  2860. },
  2861. widgets.divider,
  2862. webrtcGUI,
  2863. widgets.divider,
  2864. widgets.headerH3("h3", "Users online", "userList mdc-list-group__subheader"),
  2865. clientListCell
  2866. //widgets.headerH3("h3", "WebRTC", "userList mdc-list-group__subheader"),
  2867. ]
  2868. }
  2869. // {
  2870. // $cell: true,
  2871. // $type: "div",
  2872. // class: "mdc-persistent-drawer__toolbar-spacer",
  2873. // },
  2874. // {
  2875. // $cell: true,
  2876. // $type: "div",
  2877. // class: "mdc-list-group",
  2878. // $components: [{
  2879. // $cell: true,
  2880. // $type: "nav",
  2881. // class: "mdc-list",
  2882. // $components: [
  2883. // ]
  2884. // }]
  2885. // }
  2886. ]
  2887. };
  2888. // <div class="mdc-form-field">
  2889. // <input type="checkbox" id="input">
  2890. // <label for="input">Input Label</label>
  2891. // </div>
  2892. document.querySelector("#drawer").$cell({
  2893. $cell: true,
  2894. $type: "aside",
  2895. class: "mdc-temporary-drawer",
  2896. $components: [drawerCell]
  2897. }
  2898. );
  2899. let toolbar = {
  2900. $cell: true,
  2901. $type: "div",
  2902. class: "mdc-toolbar__row",
  2903. $components: [{
  2904. $type: "section",
  2905. class: "mdc-toolbar__section mdc-toolbar__section--align-start",
  2906. $components: [
  2907. {
  2908. $type: "button",
  2909. class: "demo-menu material-icons mdc-toolbar__menu-icon",
  2910. $text: "menu"
  2911. },
  2912. {
  2913. $type: "span",
  2914. class: "mdc-toolbar__title catalog-title",
  2915. $text: "LiveCoding.space"
  2916. },
  2917. {
  2918. $type: "a",
  2919. href: "#",
  2920. class: "material-icons mdc-toolbar__icon toggleCreate",
  2921. $text: "apps",
  2922. 'aria-label': "More"
  2923. },
  2924. {
  2925. $type: "div",
  2926. class: "mdc-menu-anchor",
  2927. $components: [
  2928. {
  2929. $type: "div",
  2930. class: "mdc-simple-menu",
  2931. "tabindex": "-1",
  2932. id: "create-menu",
  2933. $init: function(){
  2934. //var menuEl = document.querySelector('#demo-menu');
  2935. var menu = new mdc.menu.MDCSimpleMenu(this);
  2936. var toggle = document.querySelector('.toggleCreate');
  2937. toggle.addEventListener('click', function() {
  2938. menu.open = !menu.open;
  2939. });
  2940. },
  2941. style: "transform-origin: right top 0px; right: 0px; top: 0px; transform: scale(0, 0);",
  2942. $components: [
  2943. {
  2944. $type: "ul",
  2945. class: "mdc-simple-menu__items mdc-list",
  2946. role: "menu",
  2947. 'aria-hidden': "true",
  2948. style: "transform: scale(1, 1);",
  2949. $components: [
  2950. {
  2951. $type: "li",
  2952. class: "mdc-list-item",
  2953. role: "menuitem",
  2954. tabindex: "0",
  2955. $text: "Apps"
  2956. }
  2957. ]
  2958. }
  2959. ]
  2960. }
  2961. ]
  2962. },
  2963. widgets.icontoggle({
  2964. 'styleClass': "mdc-toolbar__icon",
  2965. 'id': "selectNodeSwitch",
  2966. 'label': 'select',
  2967. 'on': JSON.stringify({"content": "radio_button_checked", "label": "Select"}),
  2968. 'off': JSON.stringify({"content": "radio_button_unchecked", "label": "Unselect"}),
  2969. 'state': false,
  2970. 'init': function(){
  2971. this.addEventListener('MDCIconToggle:change', (e) => {
  2972. let avatarID = 'avatar-'+ vwf.moniker_;
  2973. let avatarNode = self.nodes['avatar-'+ vwf.moniker_];
  2974. let mode = JSON.parse(avatarNode.properties.selectMode.getValue());
  2975. if (mode) {
  2976. console.log("unselect");
  2977. vwf_view.kernel.setProperty(avatarID, "selectMode", false);
  2978. } else {
  2979. console.log("select")
  2980. vwf_view.kernel.setProperty(avatarID, "selectMode", true);
  2981. }
  2982. });
  2983. }
  2984. })
  2985. ]
  2986. },
  2987. {
  2988. $type: "section",
  2989. class: "mdc-toolbar__section mdc-toolbar__section--align-end",
  2990. $components: [
  2991. {
  2992. $type: "a",
  2993. href: "#",
  2994. class: "mdc-toolbar__icon",
  2995. $text: "EN",
  2996. onclick: function(){
  2997. //self.lang.changeLanguageTo('en')
  2998. localStorage.setItem('krestianstvo_locale', 'en');
  2999. window.location.reload(true);
  3000. }
  3001. },
  3002. {
  3003. $type: "a",
  3004. href: "#",
  3005. class: "mdc-toolbar__icon",
  3006. $text: "RU",
  3007. onclick: function(){
  3008. //self.lang.changeLanguageTo('ru')
  3009. localStorage.setItem('krestianstvo_locale', 'ru');
  3010. window.location.reload(true);
  3011. }
  3012. },
  3013. {
  3014. $type: "a",
  3015. href: "#",
  3016. class: "material-icons mdc-toolbar__icon toggle",
  3017. $text: "help",
  3018. 'aria-label': "Help"
  3019. }
  3020. ]
  3021. }
  3022. ]
  3023. };
  3024. document.querySelector("#toolbar").$cell({
  3025. $cell: true,
  3026. $type: "div",
  3027. class: "mdc-toolbar mdc-toolbar--fixed",
  3028. $components: [toolbar]
  3029. }
  3030. );
  3031. // let drawer = new mdc.drawer.MDCTemporaryDrawer(document.querySelector('.mdc-temporary-drawer'));
  3032. // document.querySelector('.menu').addEventListener('click', () => drawer.open = true);
  3033. var toggleNodes = document.querySelectorAll('.mdc-icon-toggle');
  3034. toggleNodes.forEach( el => {
  3035. mdc.iconToggle.MDCIconToggle.attachTo(el);
  3036. });
  3037. var drawerEl = document.querySelector('.mdc-temporary-drawer');
  3038. var MDCTemporaryDrawer = mdc.drawer.MDCTemporaryDrawer;
  3039. var drawer = new MDCTemporaryDrawer(drawerEl);
  3040. document.querySelector('.demo-menu').addEventListener('click', function () {
  3041. //self.currentNodeID = (self.currentNodeID == '') ? (vwf_view.kernel.find("", "/")[0]) : self.currentNodeID;
  3042. // let currentNode = document.querySelector('#currentNode')._currentNode;
  3043. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  3044. // document.querySelector('#currentNode')._setNode(currentNode);
  3045. //document.querySelector('#currentNode')._setNode(self.currentNodeID);
  3046. drawer.open = !drawer.open;
  3047. });
  3048. drawerEl.addEventListener('MDCTemporaryDrawer:open', function () {
  3049. //console.log('Received MDCPersistentDrawer:open');
  3050. });
  3051. drawerEl.addEventListener('MDCTemporaryDrawer:close', function () {
  3052. //console.log('Received MDCPersistentDrawer:close');
  3053. });
  3054. //==============
  3055. },
  3056. createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  3057. childSource, childType, childIndex, childName, callback /* ( ready ) */) {
  3058. // var nodeIDAttribute = $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  3059. // var childIDAttribute = $.encoder.encodeForHTMLAttribute("id", childID, true);
  3060. // var childIDAlpha = $.encoder.encodeForAlphaNumeric(childID);
  3061. var kernel = this.kernel;
  3062. var self = this;
  3063. var parent = this.nodes[nodeID];
  3064. var node = this.nodes[childID] = {
  3065. children: [],
  3066. properties: [],
  3067. events: {},
  3068. methods: {},
  3069. parent: parent,
  3070. parentID: nodeID,
  3071. ID: childID,
  3072. extendsID: childExtendsID,
  3073. implementsIDs: childImplementsIDs,
  3074. source: childSource,
  3075. name: childName,
  3076. };
  3077. if (parent) {
  3078. parent.children.push(node);
  3079. }
  3080. if (childID == vwf_view.kernel.find("", "/")[0] && childExtendsID && this.kernel.test(childExtendsID,
  3081. "self::element(*,'http://vwf.example.com/aframe/ascene.vwf')", childExtendsID)) {
  3082. this.scenes[childID] = node;
  3083. }
  3084. let nodeCell = document.querySelector("#currentNode");
  3085. if (nodeCell !== null) {
  3086. if (nodeCell._currentNode === nodeID) {
  3087. nodeCell._getChildNodes();
  3088. }
  3089. }
  3090. if (nodeID === this.kernel.application()) {
  3091. // document.querySelector('a-scene').classList.add("mdc-toolbar-fixed-adjust");
  3092. document.querySelector('body').classList.add("editor-body");
  3093. }
  3094. },
  3095. createdProperty: function (nodeID, propertyName, propertyValue) {
  3096. return this.initializedProperty(nodeID, propertyName, propertyValue);
  3097. },
  3098. initializedProperty: function (nodeID, propertyName, propertyValue) {
  3099. var node = this.nodes[nodeID];
  3100. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  3101. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  3102. node.properties.push(property);
  3103. },
  3104. deletedNode: function (nodeID) {
  3105. var node = this.nodes[nodeID];
  3106. node.parent.children.splice(node.parent.children.indexOf(node), 1);
  3107. delete this.nodes[nodeID];
  3108. let nodeCell = document.querySelector("#currentNode");
  3109. if (nodeCell) {
  3110. if (nodeCell._currentNode !== "") {
  3111. if (nodeCell._currentNode !== nodeID) {
  3112. //&& (this.nodes[nodeID] !== undefined)
  3113. nodeCell._getChildNodes();
  3114. } else {
  3115. nodeCell._setNode(vwf_view.kernel.find("", "/")[0]);
  3116. nodeCell._getChildNodes();
  3117. }
  3118. }
  3119. }
  3120. },
  3121. //addedChild: [ /* nodeID, childID, childName */ ],
  3122. //removedChild: [ /* nodeID, childID */ ],
  3123. satProperty: function (nodeID, propertyName, propertyValue) {
  3124. var node = this.nodes[nodeID];
  3125. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  3126. // It is possible for a property to have satProperty called for it without ever getting an
  3127. // initializedProperty (if that property delegated to itself or another on replication)
  3128. // Catch that case here and create the property
  3129. if (!node.properties[propertyName]) {
  3130. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  3131. node.properties.push(property);
  3132. }
  3133. try {
  3134. propertyValue = utility.transform(propertyValue, utility.transforms.transit);
  3135. node.properties[propertyName].value = JSON.stringify(propertyValue);
  3136. node.properties[propertyName].rawValue = propertyValue;
  3137. } catch (e) {
  3138. this.logger.warnx("satProperty", nodeID, propertyName, propertyValue,
  3139. "stringify error:", e.message);
  3140. node.properties[propertyName].value = propertyValue;
  3141. }
  3142. let nodeCell = document.querySelector('#currentNode');
  3143. if (nodeCell !== null) {
  3144. if (nodeCell._currentNode == nodeID && propertyName == 'isPlaying') {
  3145. console.log('SET PLAY !!!');
  3146. let compID = 'soundStopStartSwitch-' + nodeID;
  3147. let playSwitch = document.querySelector("[id='" + compID + "']");
  3148. if (playSwitch){
  3149. // const mycomp = new mdc.iconToggle.MDCIconToggle(playSwitch); //new mdc.select.MDCIconToggle
  3150. playSwitch._comp.on = propertyValue;
  3151. }
  3152. }
  3153. }
  3154. if (nodeCell !== null) {
  3155. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  3156. console.log('EDIT !!!')
  3157. }
  3158. }
  3159. let propCell = document.querySelector("#currentNode #prop-" + propertyName);
  3160. let propSlider = document.querySelector("#currentNode #prop-slider-" + propertyName);
  3161. if (propCell !== null) {
  3162. if (propCell._currentNode == nodeID) {
  3163. propCell.value = node.properties[propertyName].getValue();
  3164. }
  3165. }
  3166. if (propSlider !== null) {
  3167. if (propSlider._currentNode == nodeID) {
  3168. //const propSliderComp = new new mdc.slider.MDCSlider(propSlider);
  3169. propSlider._comp.value = node.properties[propertyName].getValue();
  3170. }
  3171. }
  3172. },
  3173. //gotProperty: [ /* nodeID, propertyName, propertyValue */ ],
  3174. gotProperty: function (nodeID, propertyName, propertyValue) {
  3175. var node = this.nodes[nodeID];
  3176. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  3177. let nodeCell = document.querySelector('#currentNode');
  3178. if (nodeCell !== null) {
  3179. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  3180. let editCheckBox = document.querySelector("#currentNode #editnode");
  3181. if (editCheckBox) {
  3182. if (propertyValue) {
  3183. editCheckBox.setAttribute('checked', '');
  3184. } else {
  3185. let checkAttr = editCheckBox.getAttribute('checked');
  3186. if (checkAttr) editCheckBox.removeAttribute('checked');
  3187. }
  3188. }
  3189. console.log('EDIT !!! is ' + propertyValue)
  3190. }
  3191. }
  3192. },
  3193. createdMethod: function (nodeID, methodName, methodParameters, methodBody) {
  3194. var node = this.nodes[nodeID];
  3195. if (node) {
  3196. node.methods[methodName] = methodParameters;
  3197. }
  3198. },
  3199. //calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {
  3200. //},
  3201. createdEvent: function (nodeID, eventName, eventParameters) {
  3202. var node = this.nodes[nodeID];
  3203. if (node) {
  3204. node.events[eventName] = eventParameters;
  3205. }
  3206. },
  3207. firedEvent: function (nodeID, eventName, eventParameters) {
  3208. },
  3209. executed: function (nodeID, scriptText, scriptType) {
  3210. // var nodeScript = {
  3211. // text: scriptText,
  3212. // type: scriptType,
  3213. // };
  3214. // if ( !this.allScripts[ nodeID ] ) {
  3215. // var nodeScripts = new Array();
  3216. // nodeScripts.push(nodeScript);
  3217. // this.allScripts[ nodeID ] = nodeScripts;
  3218. // }
  3219. // else {
  3220. // this.allScripts[ nodeID ].push(nodeScript);
  3221. // }
  3222. },
  3223. //ticked: [ /* time */ ],
  3224. });
  3225. function createCellWindow(elementID, cellNode, title) {
  3226. document.querySelector('#' + elementID).$cell({
  3227. $cell: true,
  3228. $type: "div",
  3229. id: elementID,
  3230. class: 'draggable',
  3231. $init: function () {
  3232. // let draggie = new Draggabilly('.draggable', {
  3233. // handle: '.handle',
  3234. // containment: true
  3235. // });
  3236. // get all draggie elements
  3237. var draggableElems = document.querySelectorAll('.draggable');
  3238. // array of Draggabillies
  3239. var draggies = []
  3240. // init Draggabillies
  3241. for (var i = 0, len = draggableElems.length; i < len; i++) {
  3242. var draggableElem = draggableElems[i];
  3243. var draggie = new Draggabilly(draggableElem, {
  3244. handle: '.handle',
  3245. containment: true
  3246. });
  3247. draggies.push(draggie);
  3248. }
  3249. this.style.visibility = 'hidden';
  3250. },
  3251. $components: [
  3252. {
  3253. $cell: true,
  3254. $type: "div",
  3255. class: "handle"
  3256. },
  3257. {
  3258. $cell: true,
  3259. $type: "button",
  3260. class: "mdc-button mdc-button--compact",
  3261. $text: "X",
  3262. onclick: function (e) {
  3263. //self.currentNodeID = m.ID;
  3264. document.querySelector('#' + elementID).style.visibility = 'hidden';
  3265. }
  3266. },
  3267. {
  3268. $cell: true,
  3269. $type: "span",
  3270. class: "mdc-typography--button",
  3271. $text: title
  3272. },
  3273. cellNode,
  3274. {
  3275. $cell: true,
  3276. $type: "div",
  3277. class: "handle",
  3278. style: "height: 10px; width: inherit;",
  3279. //$text: "sdfsdf"
  3280. }
  3281. // { $text: "23423"}
  3282. ]
  3283. }
  3284. );
  3285. }
  3286. // -- getChildByName --------------------------------------------------------------------
  3287. function getChildByName(node, childName) {
  3288. var childNode = undefined;
  3289. for (var i = 0; i < node.children.length && childNode === undefined; i++) {
  3290. if (node.children[i].name == childName) {
  3291. childNode = node.children[i];
  3292. }
  3293. }
  3294. return childNode;
  3295. };
  3296. // -- viewScript ------------------------------------------------------------------------
  3297. function createAceEditor(view, nodeID, elID) {
  3298. var editor = view.ace.edit(elID);
  3299. editor.setTheme("ace/theme/monokai");
  3300. editor.setFontSize(16);
  3301. editor.getSession().setMode("ace/mode/javascript");
  3302. editor.commands.addCommand({
  3303. name: "doit",
  3304. bindKey: { win: "Ctrl-e", mac: "Command-e" },
  3305. exec: function () {
  3306. codeEditorDoit(editor, nodeID);
  3307. }
  3308. });
  3309. editor.commands.addCommand({
  3310. name: "printit",
  3311. bindKey: { win: "Ctrl-b", mac: "Command-b" },
  3312. exec: function () {
  3313. codeEditorPrintit(editor, nodeID);
  3314. }
  3315. });
  3316. return editor;
  3317. }
  3318. function getPrototypes(kernel, extendsID) {
  3319. var prototypes = [];
  3320. var id = extendsID;
  3321. while (id !== undefined) {
  3322. prototypes.push(id);
  3323. id = kernel.prototype(id);
  3324. }
  3325. return prototypes;
  3326. }
  3327. function getPrototypes(kernel, extendsID) {
  3328. var prototypes = [];
  3329. var id = extendsID;
  3330. while (id !== undefined) {
  3331. prototypes.push(id);
  3332. id = kernel.prototype(id);
  3333. }
  3334. return prototypes;
  3335. }
  3336. function createProperty(node, propertyName, propertyValue) {
  3337. var property = {
  3338. name: propertyName,
  3339. rawValue: propertyValue,
  3340. value: undefined,
  3341. getValue: function () {
  3342. var propertyValue;
  3343. if (this.value == undefined) {
  3344. try {
  3345. propertyValue = utility.transform(this.rawValue, utility.transforms.transit);
  3346. this.value = JSON.stringify(propertyValue);
  3347. } catch (e) {
  3348. this.logger.warnx("createdProperty", nodeID, this.propertyName, this.rawValue,
  3349. "stringify error:", e.message);
  3350. this.value = this.rawValue;
  3351. }
  3352. }
  3353. return this.value;
  3354. }
  3355. };
  3356. return property;
  3357. }
  3358. function getProperties(kernel, extendsID) {
  3359. var pTypes = getPrototypes(kernel, extendsID);
  3360. var pProperties = {};
  3361. if (pTypes) {
  3362. for (var i = 0; i < pTypes.length; i++) {
  3363. var nd = this.nodes[pTypes[i]];
  3364. if (nd && nd.properties) {
  3365. for (var key in nd.properties) {
  3366. pProperties[key] = { "prop": nd.properties[key], "prototype": pTypes[i] };
  3367. }
  3368. }
  3369. }
  3370. }
  3371. return pProperties;
  3372. }
  3373. function getChildren(kernel, extendsID) {
  3374. var pTypes = getPrototypes(kernel, extendsID);
  3375. var pChildren = {};
  3376. if (pTypes) {
  3377. for (var i = 0; i < pTypes.length; i++) {
  3378. var nd = this.nodes[pTypes[i]];
  3379. if (nd && nd.children) {
  3380. for (var key in nd.children) {
  3381. pChildren[key] = nd.children[key];
  3382. }
  3383. }
  3384. }
  3385. }
  3386. return pChildren;
  3387. }
  3388. function getEvents(kernel, extendsID) {
  3389. var pTypes = getPrototypes(kernel, extendsID);
  3390. var events = {};
  3391. if (pTypes) {
  3392. for (var i = 0; i < pTypes.length; i++) {
  3393. var nd = this.nodes[pTypes[i]];
  3394. if (nd && nd.events) {
  3395. for (var key in nd.events) {
  3396. events[key] = nd.events[key];
  3397. }
  3398. }
  3399. }
  3400. }
  3401. return events;
  3402. }
  3403. function getMethods(kernel, extendsID) {
  3404. var pTypes = getPrototypes(kernel, extendsID);
  3405. var methods = {};
  3406. if (pTypes) {
  3407. for (var i = 0; i < pTypes.length; i++) {
  3408. var nd = this.nodes[pTypes[i]];
  3409. if (nd && nd.methods) {
  3410. for (var key in nd.methods) {
  3411. methods[key] = nd.methods[key];
  3412. }
  3413. }
  3414. }
  3415. }
  3416. return methods;
  3417. }
  3418. // -- Show Code Editor tab
  3419. function codeEditorDoit(editor, nodeID) {
  3420. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3421. if (selectedText == "") {
  3422. var currline = editor.getSelectionRange().start.row;
  3423. var selectedText = editor.session.getLine(currline);
  3424. }
  3425. //console.log(selectedText);
  3426. //var sceneID = self.kernel.application();
  3427. vwf_view.kernel.execute(nodeID, selectedText);
  3428. }
  3429. function codeEditorPrintit(editor, nodeID) {
  3430. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3431. if (selectedText == "") {
  3432. var currline = editor.getSelectionRange().start.row;
  3433. var selectedText = editor.session.getLine(currline);
  3434. }
  3435. //console.log(selectedText);
  3436. //var sceneID = self.kernel.application();
  3437. let scriptText = 'console.log(' + selectedText + ');'
  3438. self.kernel.execute(nodeID, scriptText);
  3439. }
  3440. function saveStateAsFile(filename) // invoke with the view as "this"
  3441. {
  3442. this.logger.info("Saving: " + filename);
  3443. var clients = this.nodes["http://vwf.example.com/clients.vwf"];
  3444. if (supportAjaxUploadWithProgress.call(this)) {
  3445. var xhr = new XMLHttpRequest();
  3446. // Save State Information
  3447. var state = vwf.getState();
  3448. state.nodes[0].children = {};
  3449. var timestamp = state["queue"].time;
  3450. timestamp = Math.round(timestamp * 1000);
  3451. var objectIsTypedArray = function (candidate) {
  3452. var typedArrayTypes = [
  3453. Int8Array,
  3454. Uint8Array,
  3455. // Uint8ClampedArray,
  3456. Int16Array,
  3457. Uint16Array,
  3458. Int32Array,
  3459. Uint32Array,
  3460. Float32Array,
  3461. Float64Array
  3462. ];
  3463. var isTypedArray = false;
  3464. if (typeof candidate == "object" && candidate != null) {
  3465. typedArrayTypes.forEach(function (typedArrayType) {
  3466. isTypedArray = isTypedArray || candidate instanceof typedArrayType;
  3467. });
  3468. }
  3469. return isTypedArray;
  3470. };
  3471. var transitTransformation = function (object) {
  3472. return objectIsTypedArray(object) ?
  3473. Array.prototype.slice.call(object) : object;
  3474. };
  3475. var json = JSON.stringify(
  3476. require("vwf/utility").transform(
  3477. state, transitTransformation
  3478. )
  3479. );
  3480. //json = $.encoder.encodeForURL(json);
  3481. var path = window.location.pathname;
  3482. var pathSplit = path.split('/');
  3483. if (pathSplit[0] == "") {
  3484. pathSplit.shift();
  3485. }
  3486. if (pathSplit[pathSplit.length - 1] == "") {
  3487. pathSplit.pop();
  3488. }
  3489. var inst = undefined;
  3490. var instIndex = pathSplit.length - 1;
  3491. if (pathSplit.length > 2) {
  3492. if (pathSplit[pathSplit.length - 2] == "load") {
  3493. instIndex = pathSplit.length - 3;
  3494. }
  3495. }
  3496. if (pathSplit.length > 3) {
  3497. if (pathSplit[pathSplit.length - 3] == "load") {
  3498. instIndex = pathSplit.length - 4;
  3499. }
  3500. }
  3501. inst = pathSplit[instIndex];
  3502. var root = "";
  3503. for (var i = 0; i < instIndex; i++) {
  3504. if (root != "") {
  3505. root = root + "/";
  3506. }
  3507. root = root + pathSplit[i];
  3508. }
  3509. if (filename == '') filename = inst;
  3510. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  3511. xhr.open("POST", "/" + root + "/save/" + filename, true);
  3512. xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  3513. xhr.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.json" + "&jsonState=" + json);
  3514. // Save Config Information
  3515. var config = { "info": {}, "model": {}, "view": {} };
  3516. // Save browser title
  3517. config["info"]["title"] = document.title//$('title').html();
  3518. // Save model drivers
  3519. Object.keys(vwf_view.kernel.kernel.models).forEach(function (modelDriver) {
  3520. if (modelDriver.indexOf('vwf/model/') != -1) config["model"][modelDriver] = "";
  3521. });
  3522. // If neither glge or threejs model drivers are defined, specify nodriver
  3523. if (config["model"]["vwf/model/glge"] === undefined && config["model"]["vwf/model/threejs"] === undefined) config["model"]["nodriver"] = "";
  3524. // Save view drivers and associated parameters, if any
  3525. Object.keys(vwf_view.kernel.kernel.views).forEach(function (viewDriver) {
  3526. if (viewDriver.indexOf('vwf/view/') != -1) {
  3527. if (vwf_view.kernel.kernel.views[viewDriver].parameters) {
  3528. config["view"][viewDriver] = vwf_view.kernel.kernel.views[viewDriver].parameters;
  3529. }
  3530. else config["view"][viewDriver] = "";
  3531. }
  3532. });
  3533. //var jsonConfig = $.encoder.encodeForURL(JSON.stringify(config));
  3534. var jsonConfig = JSON.stringify(config);
  3535. // Save config file to server
  3536. var xhrConfig = new XMLHttpRequest();
  3537. xhrConfig.open("POST", "/" + root + "/save/" + filename, true);
  3538. xhrConfig.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  3539. xhrConfig.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.config.json" + "&jsonState=" + jsonConfig);
  3540. }
  3541. else {
  3542. console.error("Unable to save state.");
  3543. }
  3544. }
  3545. // -- LoadSavedState --------------------------------------------------------------------------
  3546. function loadSavedState(filename, applicationpath, revision) {
  3547. this.logger.info("Loading: " + filename);
  3548. // Redirect until setState ID conflict is resolved
  3549. var path = window.location.pathname;
  3550. var inst = path.substring(path.length - 17, path.length - 1);
  3551. var pathSplit = path.split('/');
  3552. if (pathSplit[0] == "") {
  3553. pathSplit.shift();
  3554. }
  3555. if (pathSplit[pathSplit.length - 1] == "") {
  3556. pathSplit.pop();
  3557. }
  3558. var inst = undefined;
  3559. var instIndex = pathSplit.length - 1;
  3560. if (pathSplit.length > 2) {
  3561. if (pathSplit[pathSplit.length - 2] == "load") {
  3562. instIndex = pathSplit.length - 3;
  3563. }
  3564. }
  3565. if (pathSplit.length > 3) {
  3566. if (pathSplit[pathSplit.length - 3] == "load") {
  3567. instIndex = pathSplit.length - 4;
  3568. }
  3569. }
  3570. inst = pathSplit[instIndex];
  3571. if (revision) {
  3572. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/' + revision + '/';
  3573. }
  3574. else {
  3575. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/';
  3576. }
  3577. // $.get(filename,function(data,status){
  3578. // vwf.setState(data);
  3579. // });
  3580. }
  3581. // -- SupportAjax -----------------------------------------------------------------------------
  3582. function supportAjaxUploadWithProgress() {
  3583. return supportAjaxUploadProgressEvents();
  3584. function supportAjaxUploadProgressEvents() {
  3585. var xhr = new XMLHttpRequest();
  3586. return !!(xhr && ('upload' in xhr) && ('onprogress' in xhr.upload));
  3587. }
  3588. }
  3589. });