editor-new.js 187 KB

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