editor-new.js 180 KB

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