editor-new.js 152 KB

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