editor-new.js 196 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/widgets"
  28. ], function (module, version, view, utility, ace, colorpicker, widgets) {
  29. var self;
  30. return view.load(module, {
  31. // == Module Definition ====================================================================
  32. initialize: function () {
  33. self = this;
  34. this.ace = window.ace;
  35. this.widgets = widgets;
  36. this.lang = _LangManager.language;
  37. this.nodes = {};
  38. this.scenes = {};
  39. this.allScripts = {};
  40. //$(document.head).append('<style type="text/css" media="screen"> #editorlive { height: 500px; width: 800px; } </style>');
  41. document.querySelector('head').innerHTML += '<style type="text/css" media="screen"> #editorlive { height: 500px; width: 800px; } </style>';
  42. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/editorLive.css">';
  43. //document.querySelector('head').innerHTML += '<script type="text/javascript" src="vwf/view/lib/colorpicker/colorpicker.min.js">';
  44. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/colorpicker/themes.css">';
  45. //$(document.head).append('<meta name="viewport" content="width=device-width, initial-scale=1">');
  46. document.querySelector('head').innerHTML += '<meta name="viewport" content="width=device-width, initial-scale=1">';
  47. // $('body').append('<script>mdc.autoInit()</script>');
  48. this.removeProps = (obj) => {
  49. Object.keys(obj).forEach(key =>
  50. (key === 'id' || key === 'patches' || key === 'random' || key === 'sequence') && delete obj[key] ||
  51. (obj[key] && typeof obj[key] === 'object') && this.removeProps(obj[key])
  52. );
  53. return obj;
  54. };
  55. this.getNodeDef = function (nodeID) {
  56. let node = vwf.getNode(nodeID, true);
  57. let nodeDef = self.removeProps(node);
  58. return nodeDef
  59. }
  60. this.GUID = function () {
  61. var S4 = function () {
  62. return Math.floor(
  63. Math.random() * 0x10000 /* 65536 */
  64. ).toString(16);
  65. };
  66. return (
  67. S4() + S4() + "-" +
  68. S4() + "-" +
  69. S4() + "-" +
  70. S4() + "-" +
  71. S4() + S4() + S4()
  72. );
  73. }
  74. this.getRoot = function () {
  75. var app = window.location.pathname;
  76. var pathSplit = app.split('/');
  77. if (pathSplit[0] == "") {
  78. pathSplit.shift();
  79. }
  80. if (pathSplit[pathSplit.length - 1] == "") {
  81. pathSplit.pop();
  82. }
  83. var instIndex = pathSplit.length - 1;
  84. if (pathSplit.length > 2) {
  85. if (pathSplit[pathSplit.length - 2] == "load") {
  86. instIndex = pathSplit.length - 3;
  87. }
  88. }
  89. if (pathSplit.length > 3) {
  90. if (pathSplit[pathSplit.length - 3] == "load") {
  91. instIndex = pathSplit.length - 4;
  92. }
  93. }
  94. var root = "";
  95. for (var i = 0; i < instIndex; i++) {
  96. if (root != "") {
  97. root = root + "/";
  98. }
  99. root = root + pathSplit[i];
  100. }
  101. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  102. return root
  103. };
  104. this.getRandomInt = function (min, max) {
  105. min = Math.ceil(min);
  106. max = Math.floor(max);
  107. return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
  108. };
  109. ["drawer", "toolbar", "sideBar", "propWindow", "clientsWindow", "codeEditorWindow", "propEditorWindow", "viewSceneProps"].forEach(item => {
  110. let el = document.createElement("div");
  111. el.setAttribute("id", item);
  112. document.body.appendChild(el);
  113. }
  114. );
  115. this.avatarCardDef = function (src, desc, onclickfunc) {
  116. return {
  117. $cell: true,
  118. $type: "div",
  119. class: "mdc-card avatar-card",
  120. $init: function () {
  121. this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.0) ), url(' + src + ')'
  122. },
  123. onclick: onclickfunc,
  124. $components: [
  125. {
  126. $type: "section",
  127. class: "mdc-card__primary",
  128. $components: [
  129. {
  130. $type: "h1",
  131. class: "mdc-card__title mdc-card__title--large",
  132. $text: desc.subtitle
  133. },
  134. {
  135. $type: "h2",
  136. class: "mdc-card__subtitle",
  137. $text: desc.title
  138. }
  139. ]
  140. },
  141. {
  142. $type: "section",
  143. class: "mdc-card__actions",
  144. $components: [
  145. {
  146. $type: "button",
  147. class: "mdc-button mdc-button--compact mdc-card__action",
  148. //$text: "Use it",
  149. onclick: onclickfunc
  150. }
  151. ]
  152. }
  153. ]
  154. }
  155. }
  156. let createSettings =
  157. {
  158. $cell: true,
  159. $type: "div",
  160. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  161. $components: [
  162. {
  163. $cell: true,
  164. $type: "section",
  165. $components: [
  166. {
  167. $cell: true,
  168. $type: "h3",
  169. class: "mdc-typography--title",
  170. $text:"Primitives"
  171. },
  172. {
  173. $cell: true,
  174. $type: "div",
  175. class: "mdc-grid-list",
  176. $components: [
  177. {
  178. $cell: true,
  179. $type: "ul",
  180. class: "mdc-grid-list__tiles",
  181. $components: make3DPrimitiveList()
  182. }
  183. ]
  184. },
  185. //widgets.divider,
  186. {
  187. $cell: true,
  188. $type: "h3",
  189. $text:"Lights",
  190. class: "mdc-typography--title"
  191. },
  192. {
  193. $cell: true,
  194. $type: "div",
  195. class: "mdc-grid-list",
  196. $components: [
  197. {
  198. $cell: true,
  199. $type: "ul",
  200. class: "mdc-grid-list__tiles",
  201. $components: makeLightsList()
  202. }
  203. ]
  204. },
  205. //widgets.divider,
  206. {
  207. $cell: true,
  208. $type: "h3",
  209. class: "mdc-typography--title",
  210. $text:"Objects"
  211. },
  212. {
  213. $cell: true,
  214. $type: "div",
  215. class: "mdc-grid-list",
  216. $components: [
  217. {
  218. $cell: true,
  219. $type: "ul",
  220. class: "mdc-grid-list__tiles",
  221. $components: [
  222. self.widgets.gridListItem({
  223. imgSrc: "vwf/view/lib/images/ui/icons/camera.png",
  224. title: 'Camera',
  225. styleClass: "createListItem",
  226. onclickfunc: function(){
  227. let avatarID = 'avatar-' + vwf.moniker_;
  228. //let cubeName = self.GUID();
  229. vwf_view.kernel.callMethod(vwf.application(), "createCamera", [null, null, avatarID])
  230. //let cubeName = self.GUID();
  231. // vwf_view.kernel.callMethod(vwf.application(), "createFloor")
  232. }
  233. }),
  234. self.widgets.gridListItem({
  235. imgSrc: "vwf/view/lib/images/ui/icons/camera_offset.png",
  236. title: 'Camera with view offset',
  237. styleClass: "createListItem",
  238. onclickfunc: function(){
  239. let avatarID = 'avatar-' + vwf.moniker_;
  240. //let cubeName = self.GUID();
  241. vwf_view.kernel.callMethod(vwf.application(), "createCameraWithOffset", [null, null, avatarID])
  242. //let cubeName = self.GUID();
  243. // vwf_view.kernel.callMethod(vwf.application(), "createFloor")
  244. }
  245. })
  246. ]
  247. }
  248. ]
  249. },
  250. //widgets.divider,
  251. {
  252. $cell: true,
  253. $type: "h3",
  254. class: "mdc-typography--title",
  255. $text:"Assets"
  256. },
  257. widgets.textField({
  258. id:"assetsrc",
  259. value:"Enter URL to asset source",
  260. funconchange: function(e){
  261. console.log(this.value)
  262. }
  263. }),
  264. {
  265. $cell: true,
  266. $type: "div",
  267. class: "mdc-grid-list",
  268. $components: [
  269. {
  270. $cell: true,
  271. $type: "ul",
  272. class: "mdc-grid-list__tiles",
  273. $components: [
  274. widgets.buttonSimple(
  275. {
  276. label: "Image",
  277. onclick: function(e){
  278. let srcEl = document.querySelector('#assetsrc');
  279. let avatarID = 'avatar-' + vwf.moniker_;
  280. vwf_view.kernel.callMethod(vwf.application(), "createImage", [srcEl.value, null, null, avatarID])
  281. }
  282. }
  283. ),
  284. widgets.buttonSimple(
  285. {
  286. label: "Sound",
  287. onclick: function(e){
  288. let srcEl = document.querySelector('#assetsrc');
  289. let avatarID = 'avatar-' + vwf.moniker_;
  290. vwf_view.kernel.callMethod(vwf.application(), "createAudio", [srcEl.value, null, null, avatarID])
  291. }
  292. }
  293. ),
  294. widgets.buttonSimple(
  295. {
  296. label: "Video",
  297. onclick: function(e){
  298. let srcEl = document.querySelector('#assetsrc');
  299. let avatarID = 'avatar-' + vwf.moniker_;
  300. vwf_view.kernel.callMethod(vwf.application(), "createVideo", [srcEl.value, null, null, avatarID])
  301. }
  302. }
  303. ),
  304. widgets.buttonSimple(
  305. {
  306. label: "GLTF",
  307. onclick: function(e){
  308. let srcEl = document.querySelector('#assetsrc');
  309. let avatarID = 'avatar-' + vwf.moniker_;
  310. if(srcEl.value.includes('.gltf'))
  311. vwf_view.kernel.callMethod(vwf.application(), "createModel", ['GLTF', srcEl.value, avatarID])
  312. }
  313. }
  314. ),
  315. widgets.buttonSimple(
  316. {
  317. label: "DAE",
  318. onclick: function(e){
  319. let srcEl = document.querySelector('#assetsrc');
  320. let avatarID = 'avatar-' + vwf.moniker_;
  321. if(srcEl.value.includes('.dae'))
  322. vwf_view.kernel.callMethod(vwf.application(), "createModel", ['DAE', srcEl.value, avatarID])
  323. }
  324. }
  325. ),
  326. widgets.buttonSimple(
  327. {
  328. label: "OBJ",
  329. onclick: function(e){
  330. let srcEl = document.querySelector('#assetsrc');
  331. let avatarID = 'avatar-' + vwf.moniker_;
  332. if(srcEl.value.includes('.obj'))
  333. vwf_view.kernel.callMethod(vwf.application(), "createModel", ['OBJ', srcEl.value, avatarID])
  334. }
  335. }
  336. )
  337. ]
  338. }
  339. ]
  340. },
  341. //widgets.divider,
  342. {
  343. $cell: true,
  344. $type: "h3",
  345. class: "mdc-typography--title",
  346. $text:"Resources"
  347. },
  348. {
  349. $cell: true,
  350. $type: "div",
  351. class: "mdc-grid-list",
  352. $components: [
  353. {
  354. $cell: true,
  355. $type: "ul",
  356. class: "mdc-grid-list__tiles",
  357. $components: [
  358. self.widgets.gridListItem({
  359. imgSrc: "vwf/view/lib/images/ui/icons/3ditem.png",
  360. title: 'Asset item',
  361. styleClass: "createListItem",
  362. onclickfunc: function(){
  363. let srcEl = document.querySelector('#assetsrc');
  364. vwf_view.kernel.callMethod(vwf.application(), "createAssetResource", ['ITEM', srcEl.value])
  365. }
  366. }),
  367. self.widgets.gridListItem({
  368. imgSrc: "vwf/view/lib/images/ui/icons/image.png",
  369. title: 'Image',
  370. styleClass: "createListItem",
  371. onclickfunc: function(){
  372. //let cubeName = self.GUID();
  373. let srcEl = document.querySelector('#assetsrc');
  374. vwf_view.kernel.callMethod(vwf.application(), "createAssetResource", ['IMG', srcEl.value])
  375. }
  376. }),
  377. self.widgets.gridListItem({
  378. imgSrc: "vwf/view/lib/images/ui/icons/video.png",
  379. title: 'Video',
  380. styleClass: "createListItem",
  381. onclickfunc: function(){
  382. let srcEl = document.querySelector('#assetsrc');
  383. vwf_view.kernel.callMethod(vwf.application(), "createAssetResource", ['VIDEO', srcEl.value])
  384. }
  385. }),
  386. self.widgets.gridListItem({
  387. imgSrc: "vwf/view/lib/images/ui/icons/sound.png",
  388. title: 'Sound',
  389. styleClass: "createListItem",
  390. onclickfunc: function(){
  391. let srcEl = document.querySelector('#assetsrc');
  392. vwf_view.kernel.callMethod(vwf.application(), "createAssetResource", ['AUDIO', srcEl.value])
  393. }
  394. }),
  395. self.widgets.buttonSimple(
  396. {
  397. label: "MTL",
  398. onclick: function(e){
  399. let srcEl = document.querySelector('#assetsrc');
  400. if(srcEl.value.includes('.mtl'))
  401. vwf_view.kernel.callMethod(vwf.application(), "createAssetResource", ['ITEM', srcEl.value])
  402. }
  403. }
  404. )
  405. ]
  406. }
  407. ]
  408. },
  409. {
  410. $cell: true,
  411. $type: "h3",
  412. class: "mdc-typography--title",
  413. $text:"Google Poly"
  414. },
  415. widgets.textField({
  416. id:"googlepolyid",
  417. value:"Enter Google Poly model ID",
  418. funconchange: function(e){
  419. console.log(this.value)
  420. }
  421. }),
  422. widgets.buttonSimple(
  423. {
  424. label: "Load Model from Poly",
  425. onclick: function(e){
  426. let srcEl = document.querySelector('#googlepolyid');
  427. let avatarID = 'avatar-' + vwf.moniker_;
  428. vwf_view.kernel.callMethod(vwf.application(), "createGooglePoly", [srcEl.value, null, null, avatarID])
  429. }
  430. }
  431. )
  432. ]
  433. }
  434. ]
  435. }
  436. function make3DPrimitiveList() {
  437. let nodeNames = ['Plane', 'Cube', 'Sphere', 'Cylinder', 'Cone', 'Text'];
  438. return nodeNames.map(el => {
  439. return self.widgets.gridListItem({
  440. imgSrc: "vwf/view/lib/images/ui/icons/" + el.toLowerCase()+".png",
  441. styleClass: "createListItem",
  442. title: el,
  443. onclickfunc: function(){
  444. let avatarID = 'avatar-' + vwf.moniker_;
  445. //let cubeName = self.GUID();
  446. vwf_view.kernel.callMethod(vwf.application(), "createPrimitive", [el.toLowerCase(), null, null, null, avatarID])
  447. }
  448. })
  449. })
  450. }
  451. function makeLightsList() {
  452. let nodeNames = ['Ambient', 'Directional', 'Hemisphere', 'Point', 'Spot'];
  453. return nodeNames.map(el => {
  454. return self.widgets.gridListItem({
  455. styleClass: "createListItem",
  456. imgSrc: "vwf/view/lib/images/ui/icons/light_"+el.toLowerCase()+".png",
  457. title: el,
  458. onclickfunc: function(){
  459. let avatarID = 'avatar-' + vwf.moniker_;
  460. //let cubeName = self.GUID();
  461. vwf_view.kernel.callMethod(vwf.application(), "createPrimitive", ["light", el.toLowerCase(), null, null, avatarID])
  462. }
  463. })
  464. })
  465. }
  466. let avatarSettings =
  467. {
  468. $cell: true,
  469. $type: "div",
  470. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  471. $components: [
  472. {
  473. $cell: true,
  474. $type: "div",
  475. class: "mdc-layout-grid__inner",
  476. $components: [
  477. {
  478. $cell: true,
  479. $type: "div",
  480. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  481. $components: [
  482. widgets.buttonStroked(
  483. {
  484. "label": "Go forward",
  485. "onclick": function (e) {
  486. function getMovementVector(el) {
  487. var directionVector = new THREE.Vector3(0, 0, 0);
  488. var rotationEuler = new THREE.Euler(0, 0, 0, 'YXZ');
  489. var rotation = el.getAttribute('rotation');
  490. var velocity = new THREE.Vector3(0, 0, -0.5);
  491. var xRotation;
  492. directionVector.copy(velocity);
  493. directionVector.multiplyScalar(1.0);
  494. // Absolute.
  495. if (!rotation) { return directionVector; }
  496. xRotation = 0;
  497. // Transform direction relative to heading.
  498. rotationEuler.set(THREE.Math.degToRad(xRotation), THREE.Math.degToRad(rotation.y), 0);
  499. directionVector.applyEuler(rotationEuler);
  500. return directionVector;
  501. }
  502. let el = document.querySelector('#avatarControl');
  503. let currentPosition = el.getAttribute('position');
  504. let movementVector = getMovementVector(el);
  505. let position = {};
  506. position.x = currentPosition.x + movementVector.x;
  507. position.y = currentPosition.y + movementVector.y;
  508. position.z = currentPosition.z + movementVector.z;
  509. el.setAttribute('position', position);
  510. }
  511. })
  512. ]
  513. },
  514. {
  515. $cell: true,
  516. $type: "div",
  517. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  518. $components: [
  519. widgets.buttonStroked(
  520. {
  521. "label": "Reset camera view",
  522. "onclick": function (e) {
  523. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  524. let controlEl = document.querySelector('#avatarControl');
  525. controlEl.setAttribute('camera', 'active', true);
  526. }
  527. }),
  528. widgets.buttonStroked(
  529. {
  530. "label": "Hide cursor",
  531. "onclick": function (e) {
  532. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  533. let avatarID = 'avatar-' + self.kernel.moniker();
  534. let cursorID = 'myCursor-' + avatarID;
  535. let controlEl = document.querySelector("[id='" + cursorID + "']");
  536. let vis = controlEl.getAttribute('visible');
  537. this.$text = vis ? 'Show cursor' : 'Hide cursor';
  538. vwf_view.kernel.callMethod(avatarID, "showHideCursor", [!vis]);
  539. //controlEl.setAttribute('visible', !vis);
  540. }
  541. }),
  542. widgets.buttonStroked(
  543. {
  544. "label": "Hide Avatar",
  545. "onclick": function (e) {
  546. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  547. let avatarID = 'avatar-' + self.kernel.moniker();
  548. //let cursorID = 'myCursor-' + avatarID;
  549. let controlEl = document.querySelector("[id='" + avatarID + "']");
  550. let vis = controlEl.getAttribute('visible');
  551. this.$text = vis ? 'Show Avatar' : 'Show Avatar';
  552. vwf_view.kernel.callMethod(avatarID, "showHideAvatar", [!vis]);
  553. //controlEl.setAttribute('visible', !vis);
  554. }
  555. }
  556. )
  557. ]
  558. },
  559. {
  560. $cell: true,
  561. $type: "div",
  562. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  563. $components: [
  564. {
  565. $type: "div",
  566. class: "mdc-layout-grid",
  567. $components: [
  568. {
  569. $type: "div",
  570. class: "mdc-layout-grid__inner",
  571. $components: [
  572. {
  573. $cell: true,
  574. $type: "div",
  575. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  576. $components: [
  577. self.avatarCardDef("/../assets/avatars/ico/simple.jpg", { title: "Simple", subtitle: "Cube" },
  578. function (e) {
  579. let avatarID = 'avatar-' + self.kernel.moniker();
  580. vwf_view.kernel.callMethod(avatarID, "createSimpleAvatar");
  581. }
  582. )
  583. ]
  584. },
  585. {
  586. $cell: true,
  587. $type: "div",
  588. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  589. $components: [
  590. self.avatarCardDef("/assets/avatars/ico/female.jpg", { title: "Human", subtitle: "Female" },
  591. function (e) {
  592. let avatarID = 'avatar-' + self.kernel.moniker();
  593. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/assets/avatars/female/avatar1.gltf"]);
  594. }
  595. )]
  596. },
  597. {
  598. $cell: true,
  599. $type: "div",
  600. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  601. $components: [
  602. self.avatarCardDef("/assets/avatars/ico/male.jpg", { title: "Human", subtitle: "Male" },
  603. function (e) {
  604. let avatarID = 'avatar-' + self.kernel.moniker();
  605. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/assets/avatars/male/avatar1.gltf"]);
  606. }
  607. )]
  608. }
  609. ]
  610. }
  611. ]
  612. }
  613. ]
  614. },
  615. {
  616. $cell: true,
  617. $type: "div",
  618. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  619. $components: [
  620. widgets.buttonStroked(
  621. {
  622. "label": "Wide",
  623. "onclick": function (e) {
  624. let avatarID = 'avatar-'+vwf.moniker_;
  625. vwf_view.kernel.callMethod(avatarID, "setBigVideoHead", []);
  626. }
  627. }),
  628. widgets.buttonStroked(
  629. {
  630. "label": "Small",
  631. "onclick": function (e) {
  632. let avatarID = 'avatar-'+vwf.moniker_;
  633. vwf_view.kernel.callMethod(avatarID, "setSmallVideoHead", []);
  634. }
  635. })
  636. ]
  637. }
  638. ]
  639. }
  640. ]
  641. }
  642. let viewSettings =
  643. {
  644. $cell: true,
  645. $type: "div",
  646. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  647. $components: [
  648. {
  649. $cell: true,
  650. $type: "div",
  651. class: "mdc-layout-grid__inner",
  652. $components: [
  653. {
  654. $cell: true,
  655. $type: "div",
  656. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  657. $components: [
  658. widgets.buttonStroked(
  659. {
  660. "label": "OSC Settings",
  661. "onclick": function (e) {
  662. let sideBar = document.querySelector('#sideBar');
  663. sideBar._sideBarComponent = oscSettings;
  664. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  665. }
  666. })
  667. ]
  668. }
  669. ]
  670. }
  671. ]
  672. }
  673. let savedStateEl = function (item) {
  674. return {
  675. $type: "li",
  676. class: "mdc-list-item",
  677. role: "option",
  678. $components: [
  679. {
  680. $text: "Saved world"
  681. }
  682. ]
  683. }
  684. }
  685. let stateListElement = function (item) {
  686. let liEl = {
  687. $type: "li",
  688. class: "mdc-list-item",
  689. role: "option",
  690. id: "",
  691. tabindex: "0",
  692. applicationpath: "",
  693. $components: [
  694. {
  695. $text: "no saves"
  696. }
  697. ]
  698. }
  699. let applicationName = item.applicationpath.split("/");
  700. if (applicationName == "") {
  701. return liEl
  702. }
  703. if (applicationName.length > 0) {
  704. applicationName = applicationName[applicationName.length - 1];
  705. }
  706. if (applicationName.length > 0) {
  707. applicationName = applicationName.charAt(0).toUpperCase() + applicationName.slice(1);
  708. }
  709. if (item.latestsave) {
  710. liEl = {
  711. $type: "li",
  712. class: "mdc-list-item",
  713. role: "option",
  714. tabindex: "0",
  715. id: item.savename,
  716. applicationpath: item.applicationpath,
  717. $components: [
  718. {
  719. $text: applicationName + ": " + item.savename
  720. }
  721. ]
  722. }
  723. }
  724. else {
  725. liEl = {
  726. $type: "li",
  727. class: "mdc-list-item",
  728. role: "option",
  729. tabindex: "0",
  730. id: item.savename,
  731. revision: item.revision,
  732. applicationpath: item.applicationpath,
  733. $components: [
  734. {
  735. $text: applicationName + ": " + item.savename + " Rev(" + item.revision + ")"
  736. }
  737. ]
  738. }
  739. }
  740. return liEl
  741. }
  742. let oscSettings =
  743. {
  744. $cell: true,
  745. $type: "div",
  746. id: "oscSettings",
  747. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  748. _oscHost: '',
  749. _oscPort: '',
  750. _oscStatus: '',
  751. _updateStatus: function () {
  752. this._oscStatus = window._OSCManager.getStatus()
  753. },
  754. $init: function () {
  755. if (window._OSCManager) {
  756. this._oscHost = window._OSCManager.hostValue;
  757. this._oscPort = window._OSCManager.portValue;
  758. this._oscStatus = window._OSCManager.getStatus();
  759. // var t = this;
  760. // setInterval(function () {
  761. // t._updateStatus();
  762. // }, 1000);
  763. }
  764. },
  765. $update: function () {
  766. let that = this
  767. var buttonText = "Connect";
  768. var buttonFunc = function (e) {
  769. }
  770. if (this._oscStatus == 1) {
  771. buttonText = "Disconnect";
  772. buttonFunc = function (e) {
  773. window._OSCManager.disconnect();
  774. }
  775. } else {
  776. var buttonFunc = function (e) {
  777. window._OSCManager.connect();
  778. window._OSCManager.port.on("open", function () {
  779. that._oscStatus = window._OSCManager.getStatus();
  780. console.log("connected");
  781. });
  782. window._OSCManager.port.on("close", function () {
  783. that._oscStatus = window._OSCManager.getStatus();
  784. console.log("disconnected");
  785. });
  786. }
  787. }
  788. this.$components = [
  789. {
  790. $cell: true,
  791. $type: "div",
  792. class: "mdc-layout-grid__inner",
  793. $components: [
  794. {
  795. $cell: true,
  796. $type: "div",
  797. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  798. $components: [
  799. {
  800. $type: "span",
  801. $text: "Host: "
  802. },
  803. {
  804. class: "mdc-text-field",
  805. $cell: true,
  806. $type: "span",
  807. $components: [
  808. {
  809. class: "mdc-text-field__input prop-text-field-input",
  810. id: "oscHost",
  811. $cell: true,
  812. $type: "input",
  813. type: "text",
  814. value: this._oscHost,
  815. onchange: function (e) {
  816. this._oscHost = this.value;
  817. window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  818. }
  819. }
  820. ]
  821. }
  822. ]
  823. },
  824. {
  825. $cell: true,
  826. $type: "div",
  827. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  828. $components: [
  829. {
  830. $type: "span",
  831. $text: "Port: "
  832. },
  833. {
  834. class: "mdc-text-field",
  835. $cell: true,
  836. $type: "span",
  837. $components: [
  838. {
  839. class: "mdc-text-field__input prop-text-field-input",
  840. id: "oscPort",
  841. $cell: true,
  842. $type: "input",
  843. type: "text",
  844. value: this._oscPort,
  845. onchange: function (e) {
  846. this._oscPort = this.value;
  847. window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  848. }
  849. }
  850. ]
  851. }
  852. ]
  853. },
  854. {
  855. $cell: true,
  856. $type: "div",
  857. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  858. $components: [
  859. widgets.buttonStroked(
  860. {
  861. "label": buttonText,
  862. "onclick": buttonFunc
  863. })
  864. ]
  865. }
  866. ]
  867. }
  868. ]
  869. }
  870. }
  871. let loadSaveSettings =
  872. {
  873. $cell: true,
  874. $type: "div",
  875. id: "loadSaveSettings",
  876. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  877. _saveStates: [],
  878. _getStates: async function () {
  879. let response = await fetch("/" + self.getRoot() + "/listallsaves");
  880. let data = await response.json();
  881. //this._saveStates = data;
  882. //let appName = self.getRoot();
  883. //console.log(data.filter(item => item.applicationpath.split("/")[1] == appName));
  884. let filterData = data.filter(item => item.applicationpath.split("/")[1] == self.getRoot());
  885. if (filterData.length !== 0) {
  886. this._saveStates = filterData
  887. //return filterData
  888. } else {
  889. this._saveStates = [{
  890. savename: "",
  891. latestsave: "",
  892. revision: "",
  893. applicationpath: "",
  894. url: ""
  895. }]
  896. }
  897. // this._saveStates.filter(item => item.applicationpath.split("/")[1] == self.getRoot()).map(stateListElement)
  898. //return data
  899. //console.log(data);
  900. return this._saveStates
  901. },
  902. $init: function () {
  903. this._getStates();
  904. },
  905. $update: function () {
  906. this.$components =
  907. [
  908. {
  909. $cell: true,
  910. $type: "div",
  911. class: "mdc-layout-grid__inner",
  912. $components: [
  913. {
  914. $cell: true,
  915. $type: "div",
  916. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  917. $components: [
  918. {
  919. class: "mdc-text-field",
  920. $cell: true,
  921. $type: "span",
  922. $components: [
  923. {
  924. class: "mdc-text-field__input prop-text-field-input",
  925. id: "fileName",
  926. $cell: true,
  927. $type: "input",
  928. type: "text",
  929. value: self.getRoot()
  930. }]
  931. }
  932. ]
  933. },
  934. {
  935. $cell: true,
  936. $type: "div",
  937. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  938. $components: [
  939. widgets.buttonStroked(
  940. {
  941. "label": "Save",
  942. "onclick": function (e) {
  943. let fileName = document.querySelector('#fileName')
  944. saveStateAsFile.call(self, fileName.value);
  945. document.querySelector("#fileName").value = '';
  946. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  947. }
  948. })
  949. ]
  950. },
  951. {
  952. $cell: true,
  953. $type: "div",
  954. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  955. $components: [
  956. {
  957. $cell: true,
  958. $type: "div",
  959. class: "mdc-select",
  960. tabindex: "0",
  961. role: "listbox",
  962. id: "loadselect",
  963. $init: function () {
  964. setTimeout(function() {
  965. var MDCSelect = mdc.select.MDCSelect;
  966. let selector = document.querySelector('#loadselect');
  967. let select = new MDCSelect(selector);
  968. selector.addEventListener('MDCSelect:change', () => {
  969. //this._selectedState = select.value;
  970. document.querySelector('#loadStateButton')._selectedState = select.selectedOptions[0];
  971. //console.log(select.value);
  972. //.selectedOptions[0]
  973. });
  974. }, 300);
  975. },
  976. $components: [
  977. {
  978. $type: "div",
  979. class: "mdc-select__surface mdc-ripple-upgraded",
  980. $components: [
  981. {
  982. $type: "div",
  983. class: "mdc-select__label",
  984. $text: "Select..."
  985. },
  986. {
  987. $type: "div",
  988. class: "mdc-select__selected-text"
  989. },
  990. {
  991. $type: "div",
  992. class: "mdc-select__bottom-line"
  993. }
  994. ]
  995. },
  996. {
  997. $type: "div",
  998. class: "mdc-simple-menu mdc-select__menu",
  999. $components: [
  1000. {
  1001. $type: "ul",
  1002. class: "mdc-list mdc-simple-menu__items",
  1003. $components: this._saveStates.map(stateListElement)
  1004. }
  1005. ]
  1006. }
  1007. ]
  1008. }
  1009. ]
  1010. },
  1011. {
  1012. $cell: true,
  1013. $type: "div",
  1014. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1015. $components: [
  1016. {
  1017. $cell: true,
  1018. $type: "button",
  1019. _selectedState: {},
  1020. id: "loadStateButton",
  1021. class: "mdc-button mdc-button--raised",
  1022. $text: "Load",
  1023. onclick: function (e) {
  1024. loadSavedState.call(self, this._selectedState.getAttribute('id'), this._selectedState.getAttribute('applicationpath'), this._selectedState.getAttribute('revision'));
  1025. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  1026. }
  1027. }
  1028. ]
  1029. }
  1030. ]
  1031. }
  1032. ]
  1033. }
  1034. }
  1035. let protoPropertiesCell = function (m) {
  1036. return {
  1037. $type: "div",
  1038. class: "mdc-layout-grid__inner",
  1039. _prop: {},
  1040. $init: function () {
  1041. let prop = m[1].prop;
  1042. if (prop.value == undefined && this._currentNode !== undefined) {
  1043. prop.value = JSON.stringify(utility.transform(vwf.getProperty(this._currentNode, prop.name, []), utility.transforms.transit));
  1044. }
  1045. this._prop = prop
  1046. },
  1047. $update: function () {
  1048. this.$components = [
  1049. // {
  1050. // $type: "div",
  1051. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-10",
  1052. // $components: [
  1053. // { $text: this._prop.name }
  1054. // ]
  1055. // },
  1056. // {
  1057. // $type: "div",
  1058. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1059. // },
  1060. {
  1061. $type: "div",
  1062. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1063. $components: [
  1064. {
  1065. $type: "span",
  1066. class: "mdc-typography--body2 mdc-typography--adjust-margin protoPropLabel",
  1067. $text: this._prop.name + ': '
  1068. },
  1069. {
  1070. class: "mdc-text-field",
  1071. $cell: true,
  1072. $type: "div",
  1073. $components: [{
  1074. class: "mdc-text-field__input prop-text-field-input",
  1075. $cell: true,
  1076. $type: "input",
  1077. type: "text",
  1078. value: this._prop.getValue(),
  1079. onchange: function (e) {
  1080. let propValue = this.value;
  1081. try {
  1082. propValue = JSON.parse(propValue);
  1083. self.kernel.setProperty(this._currentNode, this._prop.name, propValue);
  1084. } catch (e) {
  1085. // restore the original value on error
  1086. this.value = propValue;
  1087. }
  1088. }
  1089. }]
  1090. }
  1091. ]
  1092. }
  1093. ]
  1094. }
  1095. }
  1096. }
  1097. let propertiesCell = function (m) {
  1098. var editComponents = [{}, {}];
  1099. // fullWidth:
  1100. // fullHeight:
  1101. // xoffset:
  1102. // yoffset:
  1103. // width:
  1104. // height:
  1105. let sliderPropNames = ['width', 'height', 'depth', 'fullWidth', 'fullHeight', 'xoffset', 'yoffset', 'subcamWidth', 'subcamHeight'];
  1106. let sliderProps = {
  1107. 'width': {
  1108. min: 0,
  1109. max: 30
  1110. },
  1111. 'height': {
  1112. min: 0,
  1113. max: 30
  1114. },
  1115. 'depth': {
  1116. min: 0,
  1117. max: 30
  1118. },
  1119. 'fullWidth': {
  1120. min: 0,
  1121. max: 5000,
  1122. step:10
  1123. },
  1124. 'fullHeight': {
  1125. min: 0,
  1126. max: 5000,
  1127. step:10
  1128. },
  1129. 'xoffset': {
  1130. min: -10000,
  1131. max: 10000,
  1132. step: 10
  1133. },
  1134. 'yoffset': {
  1135. min: -10000,
  1136. max: 10000,
  1137. step: 10
  1138. },
  1139. 'subcamWidth': {
  1140. min: 0,
  1141. max: 5000,
  1142. step:10
  1143. },
  1144. 'subcamHeight': {
  1145. min: 0,
  1146. max: 5000,
  1147. step:10
  1148. }
  1149. }
  1150. if (sliderPropNames.includes(m.name)){
  1151. let currenValue = JSON.parse(m.getValue());
  1152. var sliderComponent = widgets.sliderContinuous({
  1153. 'id': 'prop-slider-' + m.name,
  1154. 'label': 'Slider',
  1155. 'min': sliderProps[m.name].min,
  1156. 'max': sliderProps[m.name].max,
  1157. 'step': sliderProps[m.name].step ? sliderProps[m.name].step: 0.1,
  1158. 'value': currenValue,
  1159. 'init': function(){
  1160. const myEl = this;
  1161. var continuousSlider = new mdc.slider.MDCSlider(myEl);
  1162. this._comp = continuousSlider;
  1163. continuousSlider.listen('MDCSlider:input', function(e) {
  1164. // console.log(continuousSlider.value)
  1165. let myEl = e.currentTarget;
  1166. // let prop = myEl._prop.body;
  1167. //document.querySelector('#propAceEditor').env.editor.setValue(prop);
  1168. self.kernel.setProperty(myEl._currentNode, m.name, continuousSlider.value);
  1169. //continuousValue.textContent = continuousSlider.value;
  1170. });
  1171. continuousSlider.listen('MDCSlider:change', function(e) {
  1172. //console.log(continuousSlider.value);
  1173. let myEl = e.currentTarget;
  1174. // let prop = myEl._prop.body;
  1175. //document.querySelector('#propAceEditor').env.editor.setValue(prop);
  1176. self.kernel.setProperty(myEl._currentNode, m.name, continuousSlider.value);
  1177. //continuousCommittedValue.textContent = continuousSlider.value;
  1178. })
  1179. }
  1180. })
  1181. } else {
  1182. sliderComponent = {}
  1183. }
  1184. if (m.name.indexOf("semantics") > -1) { }
  1185. else if (m.name.indexOf("grammar") > -1) { }
  1186. else if (m.name.indexOf("ohm") > -1) {
  1187. editComponents = [
  1188. {
  1189. $type: "div",
  1190. $cell: true,
  1191. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  1192. $components: [
  1193. {
  1194. $cell: true,
  1195. $type: "button",
  1196. class: "mdc-button",
  1197. $text: "Edit", //edit grammar
  1198. onclick: function (e) {
  1199. var currentNode = document.querySelector('#currentNode')._currentNode;
  1200. if (currentNode == '') {
  1201. currentNode = vwf_view.kernel.find("", "/")[0];
  1202. }
  1203. let editor = document.querySelector('#livePropEditor');
  1204. editor._setNode(currentNode);
  1205. editor._propName = m.name;
  1206. editor._prop = { body: m.rawValue, type: 'complex' }
  1207. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  1208. }
  1209. }
  1210. ]
  1211. },
  1212. {
  1213. $type: "div",
  1214. $cell: true,
  1215. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  1216. $components: []
  1217. }
  1218. ]
  1219. } else {
  1220. editComponents = [
  1221. {
  1222. $type: "div",
  1223. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  1224. $components: [
  1225. sliderComponent,
  1226. {
  1227. class: "mdc-text-field prop-mdc-text-field mdc-ripple-upgraded",
  1228. $cell: true,
  1229. $type: "div",
  1230. $components: [
  1231. {
  1232. class: "mdc-text-field__input prop-text-field-input",
  1233. id: "prop-" + m.name,
  1234. $cell: true,
  1235. $type: "input",
  1236. type: "text",
  1237. value: m.getValue(),
  1238. onchange: function (e) {
  1239. let propValue = this.value;
  1240. try {
  1241. propValue = JSON.parse(propValue);
  1242. self.kernel.setProperty(this._currentNode, m.name, propValue);
  1243. } catch (e) {
  1244. // restore the original value on error
  1245. this.value = propValue;
  1246. }
  1247. }
  1248. }
  1249. ]
  1250. }
  1251. ]
  1252. },
  1253. {
  1254. $type: "div",
  1255. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  1256. $components: [
  1257. {
  1258. $cell: true,
  1259. $type: "button",
  1260. class: "mdc-button mdc-button--compact",
  1261. $text: "^", //edit grammar
  1262. onclick: function (e) {
  1263. var currentNode = document.querySelector('#currentNode')._currentNode;
  1264. if (currentNode == '') {
  1265. currentNode = vwf_view.kernel.find("", "/")[0];
  1266. }
  1267. let editor = document.querySelector('#livePropEditor');
  1268. editor._setNode(currentNode);
  1269. editor._propName = m.name;
  1270. editor._prop = { body: m.getValue(), type: 'simple' }
  1271. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  1272. }
  1273. }
  1274. ]
  1275. }
  1276. ];
  1277. }
  1278. return {
  1279. $type: "div",
  1280. class: "mdc-layout-grid__inner",
  1281. $components: [
  1282. {
  1283. $type: "div",
  1284. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1285. $components: [
  1286. { $text: m.name }
  1287. ]
  1288. },
  1289. {
  1290. $type: "div",
  1291. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1292. },
  1293. editComponents[0],
  1294. editComponents[1]
  1295. ]
  1296. }
  1297. }
  1298. let nodeLink = function (m) {
  1299. var myClass = "nodeItem";
  1300. let myAvatarName = 'avatar-' + self.kernel.moniker();
  1301. (myAvatarName == m.name) ? (myClass = "avatarName mdc-typography--subheading2") :
  1302. myClass = "nodeItem"
  1303. var nodeName = m.name;
  1304. let displayName = vwf.getProperty(m.ID, 'displayName');
  1305. if (displayName)
  1306. {
  1307. nodeName = displayName
  1308. }
  1309. return {
  1310. $type: "li",
  1311. class: "mdc-list-item",
  1312. $components: [{
  1313. $type: "a",
  1314. class: "mdc-list-item",
  1315. $href: "#",
  1316. $components: [{
  1317. $type: 'span',
  1318. class: myClass,
  1319. $text: nodeName
  1320. }
  1321. ],
  1322. onclick: function (e) {
  1323. //self.currentNodeID = m.ID;
  1324. document.querySelector('#currentNode')._setNode(m.ID);
  1325. // document.querySelector('#liveCodeEditor')._editorNode = m.ID;
  1326. // createAceEditor(self, m.ID);
  1327. }
  1328. }]
  1329. }
  1330. };
  1331. let listDivider = {
  1332. $cell: true,
  1333. $type: "hr",
  1334. class: "mdc-list-divider",
  1335. }
  1336. let webrtcGUI = {
  1337. $type: "div",
  1338. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1339. $components: [
  1340. {
  1341. $type: "div",
  1342. class: "mdc-layout-grid__inner",
  1343. $components: [
  1344. {
  1345. $type: "div",
  1346. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1347. $components: [
  1348. {
  1349. $type: "span",
  1350. $text: "Chat"
  1351. }
  1352. ]
  1353. },
  1354. {
  1355. $type: "div",
  1356. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1357. $components: [
  1358. widgets.icontoggle({
  1359. 'id': "webrtcswitch",
  1360. 'label': 'visibility',
  1361. 'on': JSON.stringify({"content": "visibility", "label": "Turn On Mic"}),
  1362. 'off': JSON.stringify({"content": "visibility_off", "label": "Turn Off Mic"}),
  1363. 'state': false,
  1364. 'init': function(){
  1365. this._driver = vwf.views["vwf/view/webrtc"];
  1366. if (!this._driver) {
  1367. this.classList.add('mdc-icon-toggle--disabled');
  1368. }
  1369. this.addEventListener('MDCIconToggle:change', (e) => {
  1370. let driver = e.target._driver;
  1371. let chkAttr = e.detail.isOn;
  1372. let avatarID = 'avatar-' + self.kernel.moniker();
  1373. let micToggle = document.querySelector('#webrtcaudio');
  1374. let camToggle = document.querySelector('#webrtcvideo');
  1375. if (chkAttr) {
  1376. driver.startWebRTC(avatarID);
  1377. micToggle.classList.remove('mdc-icon-toggle--disabled');
  1378. camToggle.classList.remove('mdc-icon-toggle--disabled');
  1379. console.log("on")
  1380. } else {
  1381. driver.stopWebRTC(avatarID);
  1382. micToggle.classList.add('mdc-icon-toggle--disabled');
  1383. camToggle.classList.add('mdc-icon-toggle--disabled');
  1384. console.log("off")
  1385. }
  1386. //console.log(e, detail)
  1387. //status.textContent = `Icon Toggle is ${detail.isOn ? 'on' : 'off'}`;
  1388. });
  1389. }
  1390. })
  1391. ]
  1392. },
  1393. {
  1394. $type: "div",
  1395. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1396. $components: [
  1397. widgets.icontoggle({
  1398. 'id': "webrtcaudio",
  1399. 'label': 'mic',
  1400. 'on': JSON.stringify({"content": "mic", "label": "Turn On Mic"}),
  1401. 'off': JSON.stringify({"content": "mic_off", "label": "Turn Off Mic"}),
  1402. 'state': false,
  1403. 'init': function(){
  1404. this._driver = vwf.views["vwf/view/webrtc"];
  1405. let webrtcswitch = document.querySelector('#webrtcswitch');
  1406. if (!this._driver) {
  1407. this.classList.add('mdc-icon-toggle--disabled');
  1408. }
  1409. this.classList.add('mdc-icon-toggle--disabled');
  1410. this.addEventListener('MDCIconToggle:change', (e) => {
  1411. let driver = e.target._driver;
  1412. let chkAttr = e.detail.isOn;
  1413. if (chkAttr) {
  1414. driver.muteAudio(chkAttr);
  1415. console.log("on")
  1416. } else {
  1417. driver.muteAudio(chkAttr);
  1418. console.log("off")
  1419. }
  1420. //console.log(e, detail)
  1421. //status.textContent = `Icon Toggle is ${detail.isOn ? 'on' : 'off'}`;
  1422. });
  1423. }
  1424. })
  1425. ]
  1426. },
  1427. {
  1428. $type: "div",
  1429. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1430. $components: [
  1431. widgets.icontoggle({
  1432. 'id': "webrtcvideo",
  1433. 'label': 'videocam',
  1434. 'on': JSON.stringify({"content": "videocam", "label": "Turn On Video"}),
  1435. 'off': JSON.stringify({"content": "videocam_off", "label": "Turn Off Video"}),
  1436. 'state': false,
  1437. 'init': function(){
  1438. this._driver = vwf.views["vwf/view/webrtc"];
  1439. if (!this._driver) {
  1440. this.classList.add('mdc-icon-toggle--disabled');
  1441. }
  1442. this.classList.add('mdc-icon-toggle--disabled');
  1443. this.addEventListener('MDCIconToggle:change', (e) => {
  1444. let driver = e.target._driver;
  1445. let chkAttr = e.detail.isOn;
  1446. if (chkAttr) {
  1447. driver.muteVideo(chkAttr);
  1448. console.log("on")
  1449. } else {
  1450. driver.muteVideo(chkAttr);
  1451. console.log("off")
  1452. }
  1453. //console.log(e, detail)
  1454. //status.textContent = `Icon Toggle is ${detail.isOn ? 'on' : 'off'}`;
  1455. });
  1456. }
  1457. })
  1458. ]
  1459. }
  1460. ]
  1461. }
  1462. ]
  1463. }
  1464. let audioGUI = {
  1465. $type: "div",
  1466. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1467. $components: [
  1468. {
  1469. $type: "div",
  1470. class: "mdc-layout-grid__inner",
  1471. $components: [
  1472. {
  1473. $type: "div",
  1474. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1475. $components: [
  1476. {
  1477. $cell: true,
  1478. $type: "span",
  1479. $text: "Sound: "
  1480. }
  1481. ]
  1482. },
  1483. {
  1484. $type: "div",
  1485. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1486. $components: [
  1487. widgets.icontoggle({
  1488. 'id': "soundStopStartSwitch",
  1489. 'label': 'play',
  1490. 'on': JSON.stringify({"content": "pause", "label": "stop"}),
  1491. 'off': JSON.stringify({"content": "play_arrow", "label": "play"}),
  1492. 'state': false,
  1493. 'init': function(){
  1494. var nodeID = this._currentNode;
  1495. this._comp = new mdc.iconToggle.MDCIconToggle(this);
  1496. this.setAttribute('id', "soundStopStartSwitch-" + nodeID );
  1497. let isPlaying = vwf.getProperty(nodeID, 'isPlaying');
  1498. mdc.iconToggle.MDCIconToggle.attachTo(this);
  1499. this._comp.on = isPlaying;
  1500. this.addEventListener('MDCIconToggle:change', (e) => {
  1501. // let avatarID = 'avatar-'+ vwf.moniker_;
  1502. // let avatarNode = self.nodes['avatar-'+ vwf.moniker_];
  1503. // let mode = JSON.parse(avatarNode.properties.selectMode.getValue());
  1504. var nodeID = document.querySelector('#currentNode')._currentNode;
  1505. let isPlaying = vwf.getProperty(nodeID, 'isPlaying');
  1506. if (isPlaying) {
  1507. console.log("stop");
  1508. vwf_view.kernel.callMethod(nodeID, "pauseSound");
  1509. } else {
  1510. console.log("play")
  1511. vwf_view.kernel.callMethod(nodeID, "playSound");
  1512. }
  1513. });
  1514. }
  1515. })
  1516. ]
  1517. },
  1518. {
  1519. $type: "div",
  1520. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1521. $components: [
  1522. {
  1523. $type: "div",
  1524. style: "padding: 12px",
  1525. $components: [
  1526. widgets.iconButton({
  1527. 'label': 'stop',
  1528. onclickfunc: function () {
  1529. var nodeID = this._currentNode;
  1530. vwf_view.kernel.callMethod(nodeID, "stopSound");
  1531. }
  1532. })
  1533. ]
  1534. }
  1535. ]
  1536. }
  1537. // {
  1538. // $type: "div",
  1539. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1540. // $components: [
  1541. // widgets.switch({
  1542. // 'id': 'editnode',
  1543. // 'init': function(){
  1544. // vwf_view.kernel.getProperty(this._currentNode, 'edit');
  1545. // },
  1546. // 'onchange': function(e){
  1547. // var nodeID = document.querySelector('#currentNode')._currentNode;
  1548. // let chkAttr = this.getAttribute('checked');
  1549. // if (chkAttr == "") {
  1550. // self.kernel.setProperty(this._currentNode, 'edit', false);
  1551. // } else {
  1552. // self.kernel.setProperty(this._currentNode, 'edit', true);
  1553. // }
  1554. // vwf_view.kernel.callMethod(nodeID, "showCloseGizmo");
  1555. // }
  1556. // }
  1557. // )
  1558. // ]
  1559. // }
  1560. ]
  1561. }
  1562. ]
  1563. }
  1564. let gizmoEdit = {
  1565. $type: "div",
  1566. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1567. $components: [
  1568. {
  1569. $type: "div",
  1570. class: "mdc-layout-grid__inner",
  1571. $components: [
  1572. {
  1573. $type: "div",
  1574. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1575. $components: [
  1576. {
  1577. $cell: true,
  1578. $type: "span",
  1579. $text: "Edit: ",
  1580. }
  1581. ]
  1582. },
  1583. {
  1584. $type: "div",
  1585. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1586. $components: [
  1587. widgets.switch({
  1588. 'id': 'editnode',
  1589. 'init': function(){
  1590. vwf_view.kernel.getProperty(this._currentNode, 'edit');
  1591. },
  1592. 'onchange': function(e){
  1593. var nodeID = document.querySelector('#currentNode')._currentNode;
  1594. let chkAttr = this.getAttribute('checked');
  1595. if (chkAttr == "") {
  1596. self.kernel.setProperty(this._currentNode, 'edit', false);
  1597. } else {
  1598. self.kernel.setProperty(this._currentNode, 'edit', true);
  1599. }
  1600. vwf_view.kernel.callMethod(nodeID, "showCloseGizmo");
  1601. }
  1602. }
  1603. )
  1604. ]
  1605. },
  1606. {
  1607. $type: "div",
  1608. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1609. $components: [
  1610. self.widgets.imageButton({
  1611. imgSrc: "vwf/view/lib/images/ui/icons/translate.png",
  1612. styleClass: "editButton",
  1613. onclickfunc: function (e) {
  1614. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['translate'])
  1615. }
  1616. })
  1617. ]
  1618. },
  1619. {
  1620. $type: "div",
  1621. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1622. $components: [
  1623. self.widgets.imageButton({
  1624. imgSrc: "vwf/view/lib/images/ui/icons/rotate.png",
  1625. styleClass: "editButton",
  1626. onclickfunc: function (e) {
  1627. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['rotate'])
  1628. }
  1629. })
  1630. ]
  1631. },
  1632. {
  1633. $type: "div",
  1634. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1635. $components: [
  1636. self.widgets.imageButton({
  1637. imgSrc: "vwf/view/lib/images/ui/icons/scale.png",
  1638. styleClass: "editButton",
  1639. onclickfunc: function (e) {
  1640. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['scale'])
  1641. }
  1642. })
  1643. ]
  1644. },
  1645. {
  1646. $type: "div",
  1647. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1648. $components: [
  1649. // self.widgets.floatActionButton({
  1650. // label: "content_copy",
  1651. // styleClass: "mdc-fab--mini"
  1652. // }),
  1653. // {
  1654. // $type: "span",
  1655. // $text: " "
  1656. // },
  1657. self.widgets.floatActionButton({
  1658. label: "delete_forever",
  1659. styleClass: "mdc-fab--mini",
  1660. onclickfunc: function(){
  1661. var nodeID = document.querySelector('#currentNode')._currentNode;
  1662. let node = self.nodes[nodeID];
  1663. //vwf_view.kernel.deleteChild(node.parentID, node.name);
  1664. vwf_view.kernel.deleteNode(nodeID);
  1665. //vwf_view.kernel.callMethod(node.parentID, "deleteNode", [node.name])
  1666. }
  1667. })
  1668. ]
  1669. },
  1670. ]
  1671. }
  1672. ]
  1673. }
  1674. let nodesCell = {
  1675. $cell: true,
  1676. $type: "div",
  1677. id: "currentNode",
  1678. _childNodes: [],
  1679. _currentNode: '',
  1680. _displayedProperties: {},
  1681. _setNode: function (aNode) {
  1682. this._currentNode = aNode;
  1683. document.querySelector('#sideBar')._sideCurrentNode = this._currentNode
  1684. },
  1685. $init: function () {
  1686. this._currentNode = document.querySelector('#sideBar')._sideCurrentNode
  1687. //this._currentNode = vwf_view.kernel.find("", "/")[0];
  1688. //this._currentNode = '3333';
  1689. },
  1690. _getChildNodes: function () {
  1691. this._childNodes = self.nodes[this._currentNode];
  1692. if (this._childNodes !== undefined) {
  1693. return this._childNodes.children
  1694. } else {
  1695. return []
  1696. }
  1697. //let nodeIDAlpha = he.encode(this._currentNode);
  1698. },
  1699. // _getNodeComplexProperties: function () {
  1700. // let node = self.nodes[this._currentNode];
  1701. // let props = this._getNodeProperties();
  1702. // let filterFunction = function (prop) {
  1703. // return (prop.name == 'ohmLang')
  1704. // };
  1705. // let complexProps = props.filter(filterFunction.bind(this));
  1706. // return complexProps
  1707. // },
  1708. _getNodeProperties: function () {
  1709. let node = self.nodes[this._currentNode];
  1710. this._displayedProperties = {};
  1711. let filterFunction = function (prop) {
  1712. return (!this._displayedProperties[prop.name] && prop.name.indexOf('$') === -1) ? (this._displayedProperties[prop.name] = "instance", true) : (false);
  1713. };
  1714. let props = node.properties.filter(filterFunction.bind(this));
  1715. return props
  1716. },
  1717. _getNodeProtoProperties: function () {
  1718. let node = self.nodes[this._currentNode];
  1719. let filterFunction = function (prop) {
  1720. return (!this._displayedProperties[prop[1].prop.name]) ? (this._displayedProperties[prop[1].prop.name] = prop[1].prototype, true) : (false);
  1721. };
  1722. let props = Object.entries(getProperties.call(self, self.kernel, node.extendsID)).filter(filterFunction.bind(this));
  1723. return props
  1724. },
  1725. $update: function () {
  1726. //this.$text = this._currentNode;
  1727. let node = self.nodes[this._currentNode];
  1728. let nodeProtos = getPrototypes(self.kernel, node.extendsID);
  1729. var viewerProps = {};
  1730. var viewerPropsCell = {};
  1731. var gizmoCell = {};
  1732. if (this._currentNode !== self.kernel.application()) {
  1733. if (nodeProtos.includes('http://vwf.example.com/aframe/componentNode.vwf')) {
  1734. //gizmoCell = {};
  1735. if (nodeProtos.includes('http://vwf.example.com/aframe/a-sound-component.vwf'))
  1736. {
  1737. //console.log("sound gui")
  1738. gizmoCell = audioGUI
  1739. }
  1740. } else {
  1741. gizmoCell = gizmoEdit
  1742. }
  1743. }
  1744. if (node !== undefined) {
  1745. if (node.extendsID == "http://vwf.example.com/aframe/acamera.vwf") {
  1746. viewerProps = {
  1747. $type: "li",
  1748. class: "mdc-list-item",
  1749. $components: [
  1750. {
  1751. $text: "Viewer properties",
  1752. $type: "span",
  1753. class: "mdc-list-item__text mdc-typography--button"
  1754. }
  1755. ]
  1756. }
  1757. viewerPropsCell = {
  1758. $cell: true,
  1759. $type: "div",
  1760. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1761. $components: [
  1762. {
  1763. $cell: true,
  1764. $type: "div",
  1765. class: "mdc-layout-grid__inner",
  1766. $components: [
  1767. {
  1768. $cell: true,
  1769. $type: "div",
  1770. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1771. $components: [
  1772. widgets.buttonStroked(
  1773. {
  1774. "label": "Active",
  1775. "onclick": function (e) {
  1776. //let camera = document.querySelector('#' + this._currentNode);
  1777. vwf_view.kernel.callMethod(this._currentNode, "setCameraToActive", [vwf.moniker_]);
  1778. //camera.setAttribute('camera', 'active', true);
  1779. }
  1780. })
  1781. ]
  1782. }
  1783. ]
  1784. }
  1785. ]
  1786. //$components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1787. }
  1788. } else {
  1789. viewerProps = {};
  1790. viewerPropsCell = {};
  1791. }
  1792. }
  1793. this.$components = [
  1794. {
  1795. $cell: true,
  1796. $type: "ul",
  1797. class: "mdc-list",
  1798. $components: [
  1799. widgets.buttonStroked(
  1800. {
  1801. "label": "<--",
  1802. "onclick": function (e) {
  1803. let node = self.nodes[this._currentNode];
  1804. if (node.parentID !== 0) {
  1805. //self.currentNodeID = node.parentID,
  1806. document.querySelector('#currentNode')._setNode(node.parentID)
  1807. }
  1808. }
  1809. }),
  1810. {
  1811. $type: "li",
  1812. class: "mdc-list-item",
  1813. $components: [
  1814. {
  1815. $text: "name",
  1816. $type: "span",
  1817. $init: function () {
  1818. let node = self.nodes[this._currentNode];
  1819. if (node) {
  1820. let displayName = vwf.getProperty(node.ID, 'displayName');
  1821. if (displayName)
  1822. {
  1823. this.$text = displayName
  1824. } else {
  1825. this.$text = node.name;
  1826. }
  1827. }
  1828. //console.log(node.properties.displayName)
  1829. },
  1830. class: "mdc-list-item__text mdc-typography--headline"
  1831. //<h1 class="mdc-typography--display4">Big header</h1>
  1832. }]
  1833. }, listDivider,
  1834. {
  1835. // $cell: true,
  1836. // $type: "ul",
  1837. // class: "mdc-list",
  1838. $type: "div",
  1839. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1840. $components: [
  1841. {
  1842. $type: "div",
  1843. class: "mdc-layout-grid__inner",
  1844. $components: [
  1845. {
  1846. $type: "div",
  1847. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1848. $components: [
  1849. widgets.buttonStroked(
  1850. {
  1851. "label": "Methods browser",
  1852. "onclick": function (e) {
  1853. var currentNode = document.querySelector('#currentNode')._currentNode;
  1854. if (currentNode == '') {
  1855. currentNode = vwf_view.kernel.find("", "/")[0];
  1856. }
  1857. document.querySelector('#liveCodeEditor')._setNode(currentNode);
  1858. //createAceEditor(self, currentNode);
  1859. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  1860. }
  1861. })
  1862. ]
  1863. }
  1864. ]
  1865. }
  1866. ]
  1867. },
  1868. gizmoCell,
  1869. listDivider,
  1870. {
  1871. $type: "li",
  1872. class: "mdc-list-item",
  1873. $components: [
  1874. {
  1875. $text: "Children",
  1876. $type: "span",
  1877. class: "mdc-list-item__text mdc-typography--button"
  1878. }]
  1879. },
  1880. {
  1881. $cell: true,
  1882. $type: "ul",
  1883. class: "mdc-list",
  1884. $components: this._getChildNodes().map(nodeLink)
  1885. }, listDivider, {
  1886. $type: "li",
  1887. class: "mdc-list-item",
  1888. $components: [
  1889. {
  1890. $text: "Properties",
  1891. $type: "span",
  1892. class: "mdc-list-item__text mdc-typography--button"
  1893. //<h1 class="mdc-typography--display4">Big header</h1>
  1894. }]
  1895. },
  1896. {
  1897. // $cell: true,
  1898. // $type: "ul",
  1899. // class: "mdc-list",
  1900. $type: "div",
  1901. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1902. $components: this._getNodeProperties().map(propertiesCell)
  1903. },
  1904. listDivider,
  1905. {
  1906. $type: "li",
  1907. class: "mdc-list-item",
  1908. $components: [
  1909. {
  1910. $text: "Proto properties",
  1911. $type: "span",
  1912. class: "mdc-list-item__text mdc-typography--button"
  1913. }]
  1914. },
  1915. {
  1916. $cell: true,
  1917. $type: "div",
  1918. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1919. $components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1920. }, listDivider,
  1921. viewerProps,
  1922. viewerPropsCell
  1923. ]
  1924. }
  1925. ]
  1926. }
  1927. }
  1928. let numberSliderComponent = {
  1929. $cell: true,
  1930. $type: "div",
  1931. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  1932. $init: function () {
  1933. },
  1934. $components: [
  1935. {
  1936. $cell: true,
  1937. $type: "div",
  1938. style: "padding: 0 16px;",
  1939. $components:[
  1940. {}
  1941. ]
  1942. }
  1943. ]
  1944. }
  1945. let colorPickerComponent = {
  1946. $cell: true,
  1947. $type: "div",
  1948. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  1949. $init: function () {
  1950. let myEl = this;
  1951. let cp = ColorPicker(
  1952. document.getElementById('slide'),
  1953. document.getElementById('picker'),
  1954. function (hex, hsv, rgb, mousePicker, mouseSlide) {
  1955. ColorPicker.positionIndicators(
  1956. document.getElementById('slide-indicator'),
  1957. document.getElementById('picker-indicator'),
  1958. mouseSlide, mousePicker
  1959. );
  1960. if (myEl._propName.toLowerCase().includes('color')) {
  1961. // console.log(hex);
  1962. document.querySelector('#propAceEditor').env.editor.setValue(JSON.stringify(hex));
  1963. self.kernel.setProperty(myEl._editorNode, myEl._propName, hex);
  1964. }
  1965. });
  1966. if (myEl._propName.toLowerCase().includes('color')) {
  1967. cp.setHex(JSON.parse(myEl._prop.body));
  1968. }
  1969. },
  1970. $components: [
  1971. {
  1972. $cell: true,
  1973. $type: "div",
  1974. id: "color-picker",
  1975. class: "cp-default",
  1976. $components: [
  1977. {
  1978. $cell: true,
  1979. $type: "div",
  1980. class: "picker-wrapper",
  1981. $components: [
  1982. {
  1983. $cell: true,
  1984. $type: "div",
  1985. id: "picker",
  1986. class: "picker",
  1987. style: "width: 130px; height: 130px"
  1988. },
  1989. {
  1990. $cell: true,
  1991. $type: "div",
  1992. id: "picker-indicator",
  1993. class: "picker-indicator"
  1994. }
  1995. ]
  1996. },
  1997. {
  1998. $cell: true,
  1999. $type: "div",
  2000. class: "slide-wrapper",
  2001. $components: [
  2002. {
  2003. $cell: true,
  2004. $type: "div",
  2005. id: "slide",
  2006. class: "slide",
  2007. style: "width: 30px; height: 130px"
  2008. },
  2009. {
  2010. $cell: true,
  2011. $type: "div",
  2012. id: "slide-indicator",
  2013. class: "slide-indicator"
  2014. }
  2015. ]
  2016. }
  2017. ]
  2018. }
  2019. // {
  2020. // $cell: true,
  2021. // $type: "div",
  2022. // id: "color-picker",
  2023. // $init: function () {
  2024. // }
  2025. // }
  2026. ]
  2027. }
  2028. let propEditorWindow = {
  2029. $cell: true,
  2030. $type: "div",
  2031. _editorNode: '',
  2032. _prop: { body: '', type: 'simple' },
  2033. _propName: '',
  2034. id: "livePropEditor",
  2035. _setNode: function (node) {
  2036. this._editorNode = node;
  2037. this._prop.body = ''
  2038. },
  2039. class: "propEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2040. $update: function () {
  2041. var editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-8"
  2042. var livePropertyComponent = {}
  2043. if (this._prop.type == 'simple') {
  2044. if (this._propName.toLowerCase().includes('color')) {
  2045. livePropertyComponent = colorPickerComponent
  2046. }
  2047. } else {
  2048. editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-12"
  2049. }
  2050. this.$components = [
  2051. {
  2052. $cell: true,
  2053. $type: "div",
  2054. class: "mdc-layout-grid__inner",
  2055. $components: [
  2056. {
  2057. $cell: true,
  2058. $type: "div",
  2059. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2060. $components: [
  2061. widgets.buttonStroked(
  2062. {
  2063. "label": "Update",
  2064. "onclick": function (e) {
  2065. let editor = document.querySelector("#propAceEditor").env.editor;
  2066. let value = editor.getValue();
  2067. try {
  2068. let propValue = (this._prop.type == 'simple') ? (JSON.parse(value)) : (value)
  2069. //propValue = JSON.parse(value);
  2070. self.kernel.setProperty(this._editorNode, this._propName, propValue);
  2071. } catch (e) {
  2072. // restore the original value on error
  2073. this.value = propValue;
  2074. }
  2075. }
  2076. }
  2077. )]
  2078. },
  2079. {
  2080. $cell: true,
  2081. $type: "div",
  2082. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  2083. $components: [
  2084. {
  2085. $type: "h3",
  2086. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  2087. $text: this._editorNode
  2088. }
  2089. ]
  2090. },
  2091. {
  2092. $cell: true,
  2093. $type: "div",
  2094. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  2095. $components: [
  2096. {
  2097. $type: "h3",
  2098. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  2099. $text: this._propName
  2100. }
  2101. ]
  2102. }
  2103. ]
  2104. },
  2105. {
  2106. $cell: true,
  2107. $type: "div",
  2108. class: "mdc-layout-grid__inner",
  2109. $components: [
  2110. {
  2111. $cell: true,
  2112. $type: "div",
  2113. class: editorClass,
  2114. $components: [
  2115. {
  2116. $cell: true,
  2117. class: "aceEditor",
  2118. id: "propAceEditor",
  2119. $type: "div",
  2120. $text: this._prop.body,
  2121. $init: function () {
  2122. createAceEditor(self, this._editorNode, "propAceEditor");
  2123. this.env.editor.$blockScrolling = Infinity
  2124. }
  2125. }
  2126. ]
  2127. }, livePropertyComponent
  2128. // {
  2129. // $cell: true,
  2130. // $type: "div",
  2131. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2132. // $components: []
  2133. // },
  2134. ]
  2135. }
  2136. ]
  2137. //$components:
  2138. }
  2139. }
  2140. let codeEditorWindow = {
  2141. $cell: true,
  2142. $type: "div",
  2143. _editorNode: '',
  2144. _method: { body: '' },
  2145. _methodName: '',
  2146. _getNodeMethods: function () {
  2147. let node = self.nodes[this._editorNode];
  2148. return node.methods
  2149. },
  2150. _getProtoNodeMethods: function () {
  2151. let node = self.nodes[this._editorNode];
  2152. let prototypeMethods = getMethods.call(self, self.kernel, node.extendsID);
  2153. return prototypeMethods
  2154. },
  2155. id: "liveCodeEditor",
  2156. _setNode: function (node) {
  2157. this._editorNode = node;
  2158. this._method.body = ''
  2159. },
  2160. class: "codeEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2161. // _getComplexProps: function(){
  2162. // let node = self.nodes[this._editorNode];
  2163. // let currentNode = document.querySelector('#currentNode');
  2164. // var props = {}
  2165. // if (currentNode !== null) {
  2166. // props = currentNode._getNodeComplexProperties();
  2167. // }
  2168. // return props
  2169. // },
  2170. // _listPropertyElement: function (m) {
  2171. // return {
  2172. // $type: "li",
  2173. // class: "mdc-list-item",
  2174. // $components: [{
  2175. // $type: "a",
  2176. // class: "mdc-list-item",
  2177. // $href: "#",
  2178. // $text: m[1].name,
  2179. // onclick: function (e) {
  2180. // this._method = {};
  2181. // this._methodName = m[1].name;
  2182. // this._method.body = m[1].rawValue
  2183. // this._method.type = "complexProperty"
  2184. // }
  2185. // }]
  2186. // }
  2187. // },
  2188. _listElement: function (m) {
  2189. return {
  2190. $type: "li",
  2191. class: "mdc-list-item",
  2192. $components: [{
  2193. $type: "a",
  2194. class: "mdc-list-item",
  2195. $href: "#",
  2196. $text: m[0],
  2197. onclick: function (e) {
  2198. let method = vwf.getMethod(this._editorNode, m[0]);
  2199. //document.querySelector('#aceEditor').
  2200. this._method = method;
  2201. this._methodName = m[0];
  2202. //self.currentNodeID = m.ID;
  2203. //document.querySelector('#currentNode')._setNode(m.ID);
  2204. }
  2205. }]
  2206. }
  2207. },
  2208. $update: function () {
  2209. this.$components = [
  2210. {
  2211. $cell: true,
  2212. $type: "div",
  2213. class: "mdc-layout-grid__inner",
  2214. $components: [
  2215. {
  2216. $cell: true,
  2217. $type: "div",
  2218. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2219. $components: [
  2220. {
  2221. $type: "h3",
  2222. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  2223. $text: this._editorNode
  2224. }
  2225. ]
  2226. },
  2227. {
  2228. $cell: true,
  2229. $type: "div",
  2230. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2231. $components: [
  2232. widgets.buttonStroked(
  2233. {
  2234. "label": "Update",
  2235. "onclick": function (e) {
  2236. let editor = document.querySelector("#aceEditor").env.editor;
  2237. let evalText = editor.getValue();
  2238. // if (this._method.type == 'complexProperty') {
  2239. // let propValue = evalText;
  2240. // try {
  2241. // //propValue = JSON.parse(propValue);
  2242. // self.kernel.setProperty(this._editorNode, this._methodName, propValue);
  2243. // } catch (e) {
  2244. // // restore the original value on error
  2245. // this.value = propValue;
  2246. // }
  2247. // } else {
  2248. // }
  2249. self.kernel.setMethod(this._editorNode, this._methodName,
  2250. { body: evalText, type: "application/javascript", parameters: this._method.parameters });
  2251. }
  2252. }
  2253. )]
  2254. },
  2255. {
  2256. $cell: true,
  2257. $type: "div",
  2258. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2259. $components: [
  2260. widgets.buttonStroked(
  2261. {
  2262. "label": "Call",
  2263. "onclick": function (e) {
  2264. var params = [];
  2265. if (this._method.parameters) {
  2266. let paramsLength = this._method.parameters.length
  2267. if (paramsLength >= 1) {
  2268. let paramsVal = document.querySelector("#methodParams").value;
  2269. try {
  2270. params = JSON.parse(paramsVal);
  2271. //params.push(prmtr);
  2272. } catch (e) {
  2273. self.logger.error('Invalid Value');
  2274. }
  2275. }
  2276. };
  2277. self.kernel.callMethod(this._editorNode, this._methodName, params);
  2278. }
  2279. })
  2280. ]
  2281. },
  2282. {
  2283. $cell: true,
  2284. $type: "div",
  2285. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2286. $components: [
  2287. widgets.buttonStroked(
  2288. {
  2289. "label": "Do It",
  2290. "onclick": function (e) {
  2291. let editor = document.querySelector("#aceEditor").env.editor;
  2292. codeEditorDoit.call(self, editor, this._editorNode);
  2293. }
  2294. })
  2295. ]
  2296. },
  2297. {
  2298. $cell: true,
  2299. $type: "div",
  2300. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2301. $components: [
  2302. widgets.buttonStroked(
  2303. {
  2304. "label": "Print It",
  2305. "onclick": function (e) {
  2306. let editor = document.querySelector("#aceEditor").env.editor;
  2307. codeEditorPrintit.call(self, editor, this._editorNode);
  2308. }
  2309. })
  2310. ]
  2311. }
  2312. ]
  2313. },
  2314. {
  2315. $cell: true,
  2316. $type: "div",
  2317. class: "mdc-layout-grid__inner",
  2318. $components: [
  2319. {
  2320. $cell: true,
  2321. $type: "div",
  2322. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2323. style: "overflow-y: scroll; max-height: 400px;",
  2324. $components: [
  2325. {
  2326. $cell: true,
  2327. $type: "div",
  2328. class: "mdc-list-group",
  2329. $components: [
  2330. {
  2331. $type: "h3",
  2332. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2333. $text: "Node methods"
  2334. },
  2335. {
  2336. $cell: true,
  2337. $type: "ul",
  2338. class: "mdc-list",
  2339. $components: Object.entries(this._getNodeMethods()).map(this._listElement)
  2340. }, listDivider,
  2341. {
  2342. $type: "h3",
  2343. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2344. $text: "Proto methods"
  2345. },
  2346. {
  2347. $cell: true,
  2348. $type: "ul",
  2349. class: "mdc-list",
  2350. $components: Object.entries(this._getProtoNodeMethods()).map(this._listElement)
  2351. }, listDivider,
  2352. {
  2353. $type: "h3",
  2354. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2355. $text: "Events"
  2356. }
  2357. // {
  2358. // $cell: true,
  2359. // $type: "ul",
  2360. // class: "mdc-list",
  2361. // $components: Object.entries(this._getComplexProps()).map(this._listPropertyElement)
  2362. // }
  2363. ]
  2364. }
  2365. ]
  2366. },
  2367. {
  2368. $cell: true,
  2369. $type: "div",
  2370. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-9",
  2371. $components: [
  2372. {
  2373. $cell: true,
  2374. class: "aceEditor",
  2375. id: "aceEditor",
  2376. $type: "div",
  2377. $text: this._method.body,
  2378. $init: function () {
  2379. createAceEditor(self, this._editorNode, "aceEditor");
  2380. }
  2381. }
  2382. ]
  2383. }
  2384. ]
  2385. },
  2386. {
  2387. $cell: true,
  2388. $type: "div",
  2389. class: "mdc-layout-grid__inner",
  2390. $components: [
  2391. {
  2392. $cell: true,
  2393. $type: "div",
  2394. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2395. $components: [
  2396. {
  2397. $type: "span",
  2398. $text: "*"
  2399. }
  2400. ]
  2401. }
  2402. ]
  2403. },
  2404. { //params input
  2405. $cell: true,
  2406. $type: "div",
  2407. class: "mdc-layout-grid__inner",
  2408. $components: [
  2409. {
  2410. $cell: true,
  2411. $type: "div",
  2412. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2413. $components: [
  2414. {
  2415. class: "mdc-text-field",
  2416. $cell: true,
  2417. $type: "div",
  2418. $components: [{
  2419. class: "mdc-text-field__input prop-text-field-input",
  2420. id: "methodName",
  2421. $cell: true,
  2422. $type: "input",
  2423. type: "text",
  2424. value: "newMethodName",
  2425. onchange: function (e) {
  2426. let propValue = this.value;
  2427. try {
  2428. } catch (e) {
  2429. // restore the original value on error
  2430. }
  2431. }
  2432. }]
  2433. }
  2434. ]
  2435. },
  2436. {
  2437. $cell: true,
  2438. $type: "div",
  2439. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  2440. $components: [
  2441. {
  2442. class: "mdc-text-field params-text-field-input",
  2443. $cell: true,
  2444. $type: "div",
  2445. $components: [{
  2446. class: "mdc-text-field__input prop-text-field-input",
  2447. id: "methodParams",
  2448. $cell: true,
  2449. $type: "input",
  2450. type: "text",
  2451. value: JSON.stringify(this._method.parameters),
  2452. onchange: function (e) {
  2453. let propValue = this.value;
  2454. try {
  2455. } catch (e) {
  2456. // restore the original value on error
  2457. }
  2458. }
  2459. }]
  2460. }
  2461. ]
  2462. },
  2463. {
  2464. $cell: true,
  2465. $type: "div",
  2466. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2467. $components: [
  2468. widgets.buttonStroked(
  2469. {
  2470. "label": "Create",
  2471. "onclick": function (e) {
  2472. let methodName = document.querySelector('#methodName').value;
  2473. //let methodParams = document.querySelector('#methodParams');
  2474. var params = [];
  2475. let body = '';
  2476. let paramsVal = document.querySelector("#methodParams").value;
  2477. if (paramsVal !== '') {
  2478. try {
  2479. params = JSON.parse(paramsVal);
  2480. //params.push(prmtr);
  2481. } catch (e) {
  2482. self.logger.error('Invalid Value');
  2483. }
  2484. }
  2485. self.kernel.createMethod(this._editorNode, methodName, params, body);
  2486. this._setNode(this._editorNode);
  2487. // let editor = document.querySelector("#aceEditor").env.editor;
  2488. // codeEditorDoit.call(self, editor, this._editorNode);
  2489. }
  2490. })
  2491. ]
  2492. }
  2493. ]
  2494. }
  2495. ]
  2496. //$components:
  2497. }
  2498. }
  2499. let propWindow = {
  2500. $cell: true,
  2501. $type: "div",
  2502. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2503. style: "overflow-y: scroll; max-height: 800px;",
  2504. $components: [
  2505. {
  2506. $type: "div",
  2507. class: "mdc-layout-grid__inner",
  2508. $components: [
  2509. {
  2510. $cell: true,
  2511. $type: "div",
  2512. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2513. $components: [
  2514. nodesCell
  2515. ]
  2516. }
  2517. ]
  2518. }
  2519. // <button class="mdc-button">
  2520. // Flat button
  2521. // </button>
  2522. ]
  2523. }
  2524. let clientListCell = {
  2525. $cell: true,
  2526. $type: "div",
  2527. class: "mdc-list",
  2528. id: "clientsList",
  2529. _watchNodes: [],
  2530. _listElement: function (m) {
  2531. return {
  2532. $type: "a",
  2533. class: "mdc-list-item",
  2534. $href: "#",
  2535. $text: m.name,
  2536. onclick: function (e) {
  2537. //self.currentNodeID = m.ID;
  2538. //document.querySelector('#currentNode')._setNode(m.ID);
  2539. }
  2540. }
  2541. },
  2542. $init: function () {
  2543. var t = this;
  2544. setInterval(function () {
  2545. t._updateMe();
  2546. }, 1000);
  2547. },
  2548. _updateMe: function () {
  2549. let clientNodes = self.nodes["http://vwf.example.com/clients.vwf"];
  2550. if (clientNodes) 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. });