app.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490
  1. import page from '/lib/page.mjs';
  2. import { Lang } from '/lib/polyglot/language.js';
  3. import { Helpers } from '/helpers.js';
  4. import { IndexApp } from '/web/index-app.js';
  5. import { Widgets } from '/lib/widgets.js';
  6. class App {
  7. constructor() {
  8. console.log("app constructor");
  9. this.widgets = new Widgets;
  10. //globals
  11. window._app = this;
  12. window._cellWidgets = this.widgets;
  13. window._LangManager = new Lang;
  14. window._noty = new Noty;
  15. _LangManager.setLanguage().then(res => {
  16. return this.initDB()
  17. }).then(res => {
  18. this.helpers = new Helpers;
  19. this.initUser();
  20. //client routes
  21. page('/', this.HandleIndex);
  22. page('/setup', this.HandleSetupIndex);
  23. page('/settings', this.HandleSettingsIndex);
  24. page('/profile', this.HandleUserIndex);
  25. page('/worlds', this.HandleIndex);
  26. page('/:user/worlds', this.HandleUserWorlds);
  27. page('/:user/worlds/:type', this.HandleUserWorldsWithType);
  28. page('/:user/:type/:name/edit/:file', this.HandleFileEdit);
  29. page('/:user/:space', this.HandleParsableRequestGenID);
  30. page('/:user/:space/:id', this.HandleParsableRequestWithID);
  31. page('/:user/:space/index.vwf/:id', this.HandleParsableRequestWithID);
  32. page('/:user/:space/load/:savename', this.HandleParsableLoadRequest);
  33. page('/:user/:space/:id/load/:savename', this.HandleParsableRequestWithID);
  34. page('/:user/:space/load/:savename/:rev', this.HandleParsableLoadRequestWithRev);
  35. page('/:user/:space/:id/load/:savename/:rev', this.HandleParsableRequestWithID);
  36. page('*', this.HandleNoPage);
  37. page();
  38. })
  39. }
  40. initDB() {
  41. var config = JSON.parse(localStorage.getItem('lcs_config'));
  42. if (!config) {
  43. config = {
  44. 'dbhost': 'https://' + window.location.hostname + ':8080/gun', //'http://localhost:8080/gun',
  45. 'reflector': 'https://' + window.location.hostname + ':3002',
  46. 'language': 'en'
  47. }
  48. localStorage.setItem('lcs_config', JSON.stringify(config));
  49. }
  50. const dbConnection = new Promise((resolve, reject) => {
  51. this.db = Gun(this.dbHost);
  52. this.user = this.db.user();
  53. window._LCSDB = this.db;
  54. window._LCSUSER = this.user;
  55. window._LCS_SYS_USER = undefined;
  56. window._LCS_WORLD_USER = undefined;
  57. _LCSDB.get('lcs/app').get('pub').once(res => {
  58. if (res) {
  59. window._LCS_SYS_USER = this.db.user(res);
  60. }
  61. });
  62. _LCSDB.on('hi', function (peer) {
  63. let msg = 'Connected to ' + peer.url;
  64. let noty = new Noty({
  65. text: msg,
  66. timeout: 2000,
  67. theme: 'mint',
  68. layout: 'bottomRight',
  69. type: 'success'
  70. });
  71. noty.show();
  72. console.log(msg)
  73. })
  74. _LCSDB.on('bye', function (peer) {
  75. let msg = 'No connection to ' + peer.url;
  76. let noty = new Noty({
  77. text: msg,
  78. timeout: 1000,
  79. theme: 'mint',
  80. layout: 'bottomRight',
  81. type: 'error'
  82. });
  83. noty.show();
  84. console.log(msg)
  85. })
  86. resolve('ok');
  87. });
  88. return dbConnection
  89. }
  90. initUser() {
  91. _LCSUSER.recall({ sessionStorage: 1 });
  92. }
  93. get reflectorHost() {
  94. var res = "";
  95. let config = localStorage.getItem('lcs_config');
  96. if (config) {
  97. res = JSON.parse(config).reflector;
  98. }
  99. return res;
  100. }
  101. get dbHost() {
  102. var res = "";
  103. let config = localStorage.getItem('lcs_config');
  104. if (config) {
  105. res = JSON.parse(config).dbhost;
  106. }
  107. return res;
  108. }
  109. async loadProxyDefaults() {
  110. //load to DB default proxy files (VWF & A-Frame components)
  111. let proxyResponse = await fetch('/proxy-files', { method: 'get' });
  112. let proxyFiles = await proxyResponse.json();
  113. let filterProxyFiles = proxyFiles.filter(el => (el !== null));
  114. console.log(filterProxyFiles);
  115. var origin = window.location.origin;
  116. //var userPub = _LCSUSER.is.pub;
  117. let proxyObj = {};
  118. for (var index in filterProxyFiles) {
  119. let el = filterProxyFiles[index];
  120. if (el) {
  121. var url = origin + el;
  122. var entryName = url.replace(origin + '/defaults/', "").split(".").join("_");
  123. let proxyFile = await fetch(url, { method: 'get' });
  124. let responseText = await proxyFile.text();
  125. if (responseText) {
  126. let created = new Date().valueOf();
  127. let obj = {
  128. //'owner': userPub,
  129. 'file': responseText,
  130. 'modified': created,
  131. 'created': created
  132. }
  133. proxyObj[entryName] = obj;
  134. }
  135. }
  136. }
  137. console.log(proxyObj);
  138. Object.keys(proxyObj).forEach(el => {
  139. _LCSDB.user().get('proxy').get(el).put(proxyObj[el]);
  140. })
  141. }
  142. async loadWorldsDefaults(replace) {
  143. //load to DB default worlds
  144. let worldsResponse = await fetch('/world-files', { method: 'get' });
  145. let worldFiles = await worldsResponse.json();
  146. let filterworldFiles = worldFiles.filter(el => (el !== null));
  147. console.log(filterworldFiles);
  148. let worldsObj = {};
  149. for (var index in filterworldFiles) {
  150. let el = filterworldFiles[index];
  151. if (el) {
  152. let url = window.location.origin + el;
  153. var entryName = url.replace(window.location.origin + '/defaults/worlds/', "").split(".").join("_");
  154. let worldName = entryName.split("/")[0];
  155. let userPub = _LCSUSER.is.pub;
  156. let worldFile = await fetch(url, { method: 'get' });
  157. let worldSource = await worldFile.text();
  158. if (worldSource) {
  159. //let modified = new Date().valueOf();
  160. let created = new Date().valueOf();
  161. let obj = {
  162. 'file': worldSource,
  163. 'modified': created,
  164. 'created': created
  165. }
  166. if (!worldsObj[worldName]) {
  167. worldsObj[worldName] = {
  168. 'parent': '-',
  169. 'owner': userPub,
  170. 'featured': true,
  171. 'published': true
  172. }
  173. }
  174. let entry = entryName.replace(worldName + '/', "");
  175. worldsObj[worldName][entry] = obj;
  176. }
  177. }
  178. }
  179. console.log(worldsObj);
  180. if(replace){
  181. Object.entries(worldsObj).forEach(el => {
  182. let worldName = el[0];
  183. let files = el[1];
  184. Object.entries(files).forEach(file => {
  185. _LCSDB.user().get('worlds').get(worldName).get(file[0]).put(file[1]);
  186. })
  187. })
  188. } else {
  189. //force replace all default worlds
  190. Object.entries(worldsObj).forEach(el => {
  191. let worldName = el[0];
  192. let files = el[1];
  193. Object.entries(files).forEach(file => {
  194. _LCSDB.user().get('worlds').get(worldName).get(file[0]).not(res=>{
  195. _LCSDB.user().get('worlds').get(worldName).get(file[0]).put(file[1]);
  196. })
  197. })
  198. })
  199. }
  200. }
  201. async loadEmptyDefaultProto() {
  202. //empty proto world
  203. let userPub = _LCSUSER.is.pub;
  204. let worldsObj = {};
  205. let emptyWorld = {
  206. "index_vwf_yaml": YAML.stringify(
  207. {
  208. "extends": "http://vwf.example.com/aframe/ascene.vwf"
  209. }, 4),
  210. "index_vwf_config_yaml": YAML.stringify(
  211. {
  212. "info": {
  213. "title": "Empty World"
  214. },
  215. "model": {
  216. "vwf/model/aframe": null
  217. },
  218. "view": {
  219. "vwf/view/aframe": null,
  220. "vwf/view/editor-new": null
  221. }
  222. }, 4),
  223. "assets_json": JSON.stringify ({}),
  224. "index_vwf_html": JSON.stringify ("<!-- DEFAULT HTML -->"),
  225. "appui_js": JSON.stringify ("//appui in JS"),
  226. "info_json": JSON.stringify ({
  227. "info": {
  228. "en": {
  229. "title": "Empty World",
  230. "imgUrl": "",
  231. "text": "Empty World"
  232. },
  233. "ru": {
  234. "title": "Новый Мир",
  235. "imgUrl": "",
  236. "text": "Новый Мир"
  237. }
  238. }
  239. }, null, 4)
  240. }
  241. worldsObj['empty'] = {
  242. 'parent': '-',
  243. 'owner': userPub,
  244. 'featured': true,
  245. 'published': true
  246. }
  247. Object.keys(emptyWorld).forEach(el=>{
  248. //let modified = new Date().valueOf();
  249. let created = new Date().valueOf();
  250. let obj = {
  251. 'file': emptyWorld[el],
  252. 'modified': created,
  253. 'created': created
  254. }
  255. worldsObj['empty'][el] = obj;
  256. })
  257. console.log(worldsObj);
  258. Object.entries(worldsObj).forEach(el => {
  259. let worldName = el[0];
  260. let files = el[1];
  261. Object.entries(files).forEach(file => {
  262. _LCSDB.user().get('worlds').get(worldName).get(file[0]).put(file[1]);
  263. })
  264. })
  265. }
  266. //load defaults for first registered user running ./setup
  267. HandleSettingsIndex() {
  268. window._app.hideProgressBar();
  269. window._app.hideUIControl();
  270. let el = document.createElement("div");
  271. el.setAttribute("id", "appGUI");
  272. document.body.appendChild(el);
  273. _cellWidgets.reflectorGUI();
  274. }
  275. HandleSetupIndex() {
  276. window._app.hideProgressBar();
  277. window._app.hideUIControl();
  278. let el = document.createElement("div");
  279. el.setAttribute("id", "admin");
  280. document.body.appendChild(el);
  281. _LCSDB.on('auth',
  282. async function (ack) {
  283. if (_LCSUSER.is) {
  284. let setPubKey = {
  285. $cell: true,
  286. $components: [
  287. {
  288. $type: "p",
  289. class: "mdc-typography--headline5",
  290. $text: "1. Set app system user PUB key"
  291. },
  292. {
  293. $type: "button",
  294. class: "mdc-button mdc-button--raised",
  295. $text: "Set app PUB key",
  296. onclick: function (e) {
  297. console.log("admin action");
  298. _LCSDB.get('lcs/app').get('pub').put(_LCSUSER.is.pub);
  299. }
  300. }
  301. ]
  302. }
  303. let adminComponents = [];
  304. let defaultPub = await _LCSDB.get('lcs/app').get('pub').once().then();
  305. if (!defaultPub) {
  306. adminComponents.push(setPubKey);
  307. }
  308. if (_LCSUSER.is.pub == defaultPub) {
  309. let loadEmpty = {
  310. $cell: true,
  311. $components: [
  312. {
  313. $type: "p",
  314. class: "mdc-typography--headline5",
  315. $text: "3. Initialize empty World proto"
  316. },
  317. {
  318. $type: "button",
  319. id: "loadDefaults",
  320. class: "mdc-button mdc-button--raised",
  321. $text: "Init empty world",
  322. onclick: function (e) {
  323. console.log("admin action");
  324. window._app.loadEmptyDefaultProto();
  325. }
  326. }
  327. ]
  328. }
  329. let loadDefaults = {
  330. $cell: true,
  331. _replaceSwitch: null,
  332. $components: [
  333. {
  334. $type: "p",
  335. class: "mdc-typography--headline5",
  336. $text: "4. Load Sample Worlds protos from server (optional)"
  337. },
  338. {
  339. $type: "button",
  340. id: "loadDefaults",
  341. class: "mdc-button mdc-button--raised",
  342. $text: "Load default worlds (from server)",
  343. onclick: function (e) {
  344. console.log("admin action");
  345. let forceReplace = this._replaceSwitch.checked;
  346. //console.log(forceReplace);
  347. window._app.loadWorldsDefaults(forceReplace);
  348. }
  349. },
  350. {
  351. $type: 'p'
  352. },
  353. _cellWidgets.switch({
  354. 'id': 'forceReplace',
  355. 'init': function () {
  356. this._switch = new mdc.switchControl.MDCSwitch(this);
  357. this._replaceSwitch = this._switch;
  358. this._switch.checked = false;
  359. }
  360. }
  361. ),
  362. {
  363. $type: 'label',
  364. for: 'input-forceReplace',
  365. $text: 'Force replace'
  366. }
  367. ]
  368. }
  369. let loadDefaultsProxy = {
  370. $cell: true,
  371. $components: [
  372. {
  373. $type: "p",
  374. class: "mdc-typography--headline5",
  375. $text: "3. Load VWF & A-Frame default components"
  376. },
  377. {
  378. $type: "button",
  379. class: "mdc-button mdc-button--raised",
  380. $text: "Load defaults Proxy",
  381. onclick: function (e) {
  382. console.log("admin action");
  383. window._app.loadProxyDefaults();
  384. }
  385. }
  386. ]
  387. }
  388. adminComponents.push(setPubKey, loadDefaultsProxy, loadEmpty, loadDefaults);
  389. }
  390. document.querySelector("#admin").$cell({
  391. $cell: true,
  392. id: 'adminComponents',
  393. $type: "div",
  394. $components: adminComponents
  395. });
  396. }
  397. })
  398. }
  399. //TODO: profile
  400. HandleUserIndex(ctx) {
  401. console.log("USER INDEX");
  402. window._app.hideProgressBar();
  403. window._app.hideUIControl();
  404. _LCSDB.on('auth',
  405. async function (ack) {
  406. if(ack.pub){
  407. document.querySelector("#profile")._status = "User: " + _LCSUSER.is.alias //+' pub: ' + _LCSUSER.is.pub;
  408. document.querySelector("#profile").$update();
  409. }
  410. })
  411. let el = document.createElement("div");
  412. el.setAttribute("id", "userProfile");
  413. document.body.appendChild(el);
  414. let userProfile = {
  415. $type: 'div',
  416. id: "profile",
  417. _status: "",
  418. $init: function(){
  419. this._status = "user is not signed in..."
  420. },
  421. $update: function(){
  422. this.$components = [
  423. {
  424. $type: "h1",
  425. class: "mdc-typography--headline4",
  426. $text: this._status //"Profile for: " + _LCSUSER.is.alias
  427. }
  428. ]
  429. }
  430. }
  431. document.querySelector("#userProfile").$cell({
  432. $cell: true,
  433. $type: "div",
  434. $components: [userProfile]
  435. })
  436. }
  437. async HandleUserWorlds(ctx) {
  438. console.log("USER WORLDS INDEX");
  439. console.log(ctx.params);
  440. let user = ctx.params.user;
  441. page.redirect('/' + user + '/worlds/protos');
  442. }
  443. async HandleFileEdit(ctx) {
  444. console.log("USER WORLD FILE EDIT");
  445. let user = ctx.params.user;
  446. let worldName = ctx.params.name;
  447. let fileOriginal = ctx.params.file;
  448. let type = ctx.params.type;
  449. window._app.hideProgressBar();
  450. window._app.hideUIControl();
  451. _LCSDB.on('auth',
  452. async function (ack) {
  453. if (_LCSUSER.is) {
  454. if (_LCSUSER.is.alias == user) {
  455. var worldType = 'worlds';
  456. var file = fileOriginal;
  457. if (type == 'state') {
  458. worldType = 'documents';
  459. file = _app.helpers.replaceSubStringALL(fileOriginal, "~", '/');
  460. }
  461. let worldFile = await _LCSUSER.get(worldType).get(worldName).get(file).once().then();
  462. if (worldFile) {
  463. console.log(worldFile.file);
  464. let el = document.createElement("div");
  465. el.setAttribute("id", "worldFILE");
  466. document.body.appendChild(el);
  467. let aceEditorCell = {
  468. $type: "div",
  469. $components: [
  470. {
  471. class: "aceEditor",
  472. id: "aceEditor",
  473. //style: "width:1200px; height: 800px",
  474. $type: "div",
  475. $text: worldFile.file,
  476. $init: function () {
  477. var mode = "ace/mode/json";
  478. if (file.includes('_yaml'))
  479. mode = "ace/mode/yaml"
  480. if (file.includes('_js'))
  481. mode = "ace/mode/javascript"
  482. var editor = ace.edit("aceEditor");
  483. editor.setTheme("ace/theme/monokai");
  484. editor.setFontSize(16);
  485. editor.getSession().setMode(mode);
  486. editor.setOptions({
  487. maxLines: Infinity
  488. });
  489. }
  490. },
  491. {
  492. $type: "button",
  493. class: "mdc-button mdc-button--raised",
  494. $text: "Save",
  495. onclick: async function (e) {
  496. console.log("save new info");
  497. let editor = document.querySelector("#aceEditor").env.editor;
  498. let newInfo = editor.getValue();
  499. _LCSUSER.get(worldType).get(worldName).get(file).get('file').put(newInfo, res => {
  500. if (res) {
  501. let modified = new Date().valueOf();
  502. _LCSUSER.get(worldType).get(worldName).get(file).get('modified').put(modified);
  503. }
  504. })
  505. }
  506. },
  507. {
  508. $type: "button",
  509. class: "mdc-button mdc-button--raised",
  510. $text: "Close",
  511. onclick: function (e) {
  512. console.log("close");
  513. if (type == "proto")
  514. window.location.pathname = "/" + user + '/worlds/protos'
  515. if (type == "state")
  516. window.location.pathname = "/" + user + '/worlds/states'
  517. }
  518. }
  519. ]
  520. }
  521. document.querySelector("#worldFILE").$cell({
  522. $cell: true,
  523. $type: "div",
  524. $components: [aceEditorCell
  525. ]
  526. })
  527. }
  528. }
  529. }
  530. })
  531. }
  532. async HandleUserWorldsWithType(ctx) {
  533. console.log("USER WORLDS INDEX");
  534. console.log(ctx.params);
  535. let user = ctx.params.user;
  536. let type = ctx.params.type;
  537. window._app.hideProgressBar();
  538. window._app.hideUIControl();
  539. if (!_app.indexApp) {
  540. _app.indexApp = new IndexApp;
  541. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="/web/index-app.css">';
  542. }
  543. if (!document.querySelector('#app')) {
  544. await _app.indexApp.initApp();
  545. }
  546. if (type == 'protos') {
  547. await _app.indexApp.getWorldsProtosFromUserDB(user);
  548. } else if (type == 'states') {
  549. await _app.indexApp.getWorldsFromUserDB(user);
  550. }
  551. }
  552. async HandleIndex() {
  553. console.log("INDEX");
  554. window._app.hideProgressBar();
  555. window._app.hideUIControl();
  556. _app.indexApp = new IndexApp;
  557. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="/web/index-app.css">';
  558. await _app.indexApp.generateFrontPage();
  559. await _app.indexApp.initApp();
  560. await _app.indexApp.getAppDetailsFromDB();
  561. }
  562. HandleNoPage() {
  563. console.log("no such page")
  564. }
  565. //handle parcable requests
  566. HandleParsableLoadRequest(ctx) {
  567. let app = window._app;
  568. console.log(ctx.params);
  569. //var pathname = ctx.pathname;
  570. var spaceName = ctx.params.space;
  571. var saveName = ctx.params.savename;
  572. let user = ctx.params.user;
  573. page.redirect('/' + user + '/' + spaceName + '/' + app.helpers.GenerateInstanceID() + '/load/' + saveName);
  574. }
  575. HandleParsableLoadRequestWithRev(ctx) {
  576. let app = window._app;
  577. console.log(ctx.params);
  578. //var pathname = ctx.pathname;
  579. var spaceName = ctx.params.space;
  580. var saveName = ctx.params.savename;
  581. var rev = ctx.params.rev;
  582. let user = ctx.params.user;
  583. page.redirect('/' + user + '/' + spaceName + '/' + app.helpers.GenerateInstanceID() + '/load/' + saveName + '/' + rev);
  584. }
  585. async setUserPaths(user) {
  586. await _LCSDB.get('users').get(user).get('pub').once(res => {
  587. if (res)
  588. window._LCS_WORLD_USER = _LCSDB.user(res);
  589. }).then();
  590. }
  591. async HandleParsableRequestGenID(ctx) {
  592. let app = window._app;
  593. console.log(ctx.params);
  594. let user = ctx.params.user;
  595. var pathname = ctx.pathname;
  596. await app.setUserPaths(user);
  597. if (pathname[pathname.length - 1] == '/') {
  598. pathname = pathname.slice(0, -1)
  599. }
  600. let pathToParse = pathname.replace('/' + user, "");
  601. app.helpers.Process(pathToParse).then(parsedRequest => {
  602. localStorage.setItem('lcs_app', JSON.stringify({ path: parsedRequest }));
  603. console.log(parsedRequest);
  604. if ((parsedRequest['instance'] == undefined) && (parsedRequest['private_path'] == undefined) && (parsedRequest['public_path'] !== "/") && (parsedRequest['application'] !== undefined)) {
  605. page.redirect(pathname + '/' + app.helpers.GenerateInstanceID());
  606. }
  607. });
  608. }
  609. async HandleParsableRequestWithID(ctx) {
  610. let app = window._app;
  611. console.log(ctx.params);
  612. var pathname = ctx.pathname;
  613. let user = ctx.params.user;
  614. if (pathname[pathname.length - 1] == '/') {
  615. pathname = pathname.slice(0, -1)
  616. }
  617. await app.setUserPaths(user);
  618. let pathToParse = pathname.replace('/' + user, "");
  619. app.helpers.Process(pathToParse).then(async function(parsedRequest) {
  620. localStorage.setItem('lcs_app', JSON.stringify({ path: parsedRequest }));
  621. console.log(parsedRequest);
  622. var userLibraries = { model: {}, view: {} };
  623. var application;
  624. await vwf.loadConfiguration(application, userLibraries, compatibilityCheck);
  625. });
  626. }
  627. async HandleParsableRequest(ctx) {
  628. let app = window._app;
  629. console.log(ctx.params);
  630. var pathname = ctx.pathname;
  631. if (pathname[pathname.length - 1] == '/') {
  632. pathname = pathname.slice(0, -1)
  633. }
  634. var parsedRequest = await app.helpers.Process(pathname);
  635. localStorage.setItem('lcs_app', JSON.stringify({ path: parsedRequest }));
  636. console.log(parsedRequest);
  637. if ((parsedRequest['instance'] == undefined) && (parsedRequest['private_path'] == undefined) && (parsedRequest['public_path'] !== "/") && (parsedRequest['application'] !== undefined)) {
  638. // Redirect if the url request does not include an application/file && a default 'index.vwf.yaml' exists
  639. // page.redirect(pathname + '/' + app.helpers.GenerateInstanceID());
  640. window.location.pathname = pathname + '/' + app.helpers.GenerateInstanceID()
  641. //return true;
  642. } else {
  643. //return false;
  644. }
  645. var userLibraries = { model: {}, view: {} };
  646. var application;
  647. await vwf.loadConfiguration(application, userLibraries, compatibilityCheck);
  648. }
  649. //get DB application state information for reflector (called from VWF)
  650. async getApplicationState() {
  651. let dataJson = JSON.parse(localStorage.getItem('lcs_app'));
  652. if (dataJson) {
  653. if (!dataJson.path['instance']) return undefined;
  654. }
  655. let userAlias = await _LCS_WORLD_USER.get('alias').once().then();
  656. let userPub = await _LCSDB.get('users').get(userAlias).get('pub').once().then();
  657. let loadInfo = await this.getLoadInformation(dataJson);
  658. let saveInfo = await this.loadSaveObject(loadInfo);
  659. let loadObj = {
  660. loadInfo: loadInfo,
  661. path: dataJson.path,
  662. saveObject: saveInfo,
  663. user: userAlias
  664. }
  665. //dataJson.app = loadObj;
  666. localStorage.setItem('lcs_app', JSON.stringify(loadObj));
  667. console.log(loadObj);
  668. //temporary solution for syncing DB replicas using Gun.load()
  669. // _LCS_SYS_USER.get('proxy').load(res=>{
  670. // if (res)
  671. // {console.log('proxy loaded');
  672. // _LCSDB.user(userPub).get('worlds').get(loadObj.path.public_path.slice(1)).load(w=>{
  673. // if (w) {
  674. // console.log('world files loaded');
  675. // vwf.ready( vwf.application, loadObj)
  676. // }
  677. // }, {wait: 200});
  678. // }
  679. // }, {wait: 200});
  680. return loadObj
  681. }
  682. // LookupSaveRevisions takes the public path and the name of a save, and provides
  683. // an array of all revisions for that save. (If the save does not exist, this will be
  684. // an empty array).
  685. async lookupSaveRevisions(public_path, save_name) {
  686. var result = [];
  687. var states = [];
  688. let docName = 'savestate_/' + public_path + '/' + save_name + '_vwf_json';
  689. let revs = await _LCS_WORLD_USER.get('documents').get(public_path).get(docName).get('revs').once().then();
  690. if (revs) {
  691. for (const res of Object.keys(revs)) {
  692. if (res !== '_') {
  693. let el = await _LCS_WORLD_USER.get('documents').get(public_path).get(docName).get('revs').get(res).once().then();
  694. if (el)
  695. result.push(parseInt(el.revision));
  696. }
  697. }
  698. return result
  699. }
  700. }
  701. // GetLoadInformation receives a parsed request {private_path, public_path, instance, application} and returns the
  702. // details of the save that is designated by the initial request. The details are returned in an object
  703. // composed of: save_name (name of the save) save_revision (revision of the save), explicit_revision (boolean, true if the request
  704. // explicitly specified the revision, false if it did not), and application_path (the public_path of the application this is a save for).
  705. async getLoadInformation(response) {
  706. let parsedRequest = response.path;
  707. var result = { 'save_name': undefined, 'save_revision': undefined, 'explicit_revision': undefined, 'application_path': undefined };
  708. if (parsedRequest['private_path']) {
  709. var segments = this.helpers.GenerateSegments(parsedRequest['private_path']);
  710. if ((segments.length > 1) && (segments[0] == "load")) {
  711. var potentialRevisions = await this.lookupSaveRevisions((parsedRequest['public_path']).slice(1), segments[1]);
  712. console.log('!!!!! - ', potentialRevisions);
  713. if (potentialRevisions.length > 0) {
  714. result['save_name'] = segments[1];
  715. if (segments.length > 2) {
  716. var requestedRevision = parseInt(segments[2]);
  717. if (requestedRevision) {
  718. if (potentialRevisions.indexOf(requestedRevision) > -1) {
  719. result['save_revision'] = requestedRevision;
  720. result['explicit_revision'] = true;
  721. result['application_path'] = parsedRequest['public_path'];
  722. }
  723. }
  724. }
  725. if (result['explicit_revision'] == undefined) {
  726. result['explicit_revision'] = false;
  727. potentialRevisions.sort();
  728. result['save_revision'] = potentialRevisions.pop();
  729. result['application_path'] = parsedRequest['public_path'];
  730. }
  731. }
  732. }
  733. }
  734. return result;
  735. }
  736. async loadSaveObject(loadInfo) {
  737. //let objName = loadInfo[ 'save_name' ] +'/'+ "savestate_" + loadInfo[ 'save_revision' ];
  738. if(!loadInfo.save_name){
  739. return undefined
  740. }
  741. let objName = "savestate_" + loadInfo['application_path'] + '/' + loadInfo['save_name'] + '_vwf_json';
  742. let objNameRev = "savestate_" + loadInfo['save_revision'] + loadInfo['application_path'] + '/' + loadInfo['save_name'] + '_vwf_json';
  743. // if(loadInfo[ 'save_revision' ]){
  744. // }
  745. let worldName = this.helpers.appPath //loadInfo[ 'application_path' ].slice(1);
  746. let saveObject = await _LCS_WORLD_USER.get('documents').get(worldName).get(objName).get('revs').get(objNameRev).once().then();
  747. let saveInfo = saveObject ? JSON.parse(saveObject.jsonState) : saveObject;
  748. return saveInfo;
  749. }
  750. // GetSaveInformation is a helper function that takes the application_path (/path/to/application).
  751. // It returns an array of all saves found for that
  752. // application (including separate entries for individual revisions of saves ).
  753. async getSaveInformation(application_path, userPUB) {
  754. var result = [];
  755. let user = _LCSDB.user(userPUB);
  756. var docName = application_path.slice(1);
  757. let potentialSaveNames = await user.get('documents').get(docName).once().then();
  758. if (potentialSaveNames) {
  759. for (const res of Object.keys(potentialSaveNames)) {
  760. if (res !== '_') {
  761. let el = await user.get('documents').path(docName).get(res).once().then();
  762. let revisionList = await this.lookupSaveRevisions(application_path.slice(1), el.filename);
  763. var latestsave = true;
  764. revisionList.sort();
  765. while (revisionList.length > 0) {
  766. var newEntry = {};
  767. newEntry['applicationpath'] = application_path;
  768. newEntry['savename'] = el.filename;
  769. newEntry['revision'] = revisionList.pop().toString();
  770. newEntry['latestsave'] = latestsave;
  771. if (latestsave) {
  772. newEntry['url'] = this.helpers.JoinPath(window.location.origin, application_path, "load", el.filename + "/");
  773. }
  774. else {
  775. newEntry['url'] = this.helpers.JoinPath(window.location.origin, application_path, "load", el.filename + "/", newEntry['revision'] + "/");
  776. }
  777. latestsave = false;
  778. result.push(newEntry);
  779. }
  780. }
  781. }
  782. }
  783. return result;
  784. }
  785. async getProtoWorldFiles(userPub, worldName, date) {
  786. let fileNamesAll = await _LCSDB.user(userPub).get('worlds').get(worldName).once().then();
  787. let worldFileNames = Object.keys(fileNamesAll).filter(el => (el !== '_') && (el !== 'owner') && (el !== 'parent') && (el !== 'featured') && (el !== 'published') && (el !== 'info_json'));
  788. let worldObj = {};
  789. for (var el in worldFileNames) {
  790. let fn = worldFileNames[el];
  791. let res = await _LCSDB.user(userPub).get('worlds').get(worldName).get(fn).once().then();
  792. var data = {
  793. 'file': res.file,
  794. 'modified': res.modified,
  795. 'created': res.created
  796. }
  797. if (!date) {
  798. data = {
  799. 'file': res.file
  800. }
  801. }
  802. worldObj[fn] = data;
  803. }
  804. console.log(worldObj);
  805. return worldObj
  806. }
  807. async cloneWorldPrototype(worldName, userName, newWorldName) {
  808. let userPub = await _LCSDB.get('users').get(userName).get('pub').once().then();
  809. //let worldProto = await _LCSDB.user(userPub).get('worlds').get(worldName).once().then();
  810. var worldID = window._app.helpers.GenerateInstanceID().toString();
  811. if (newWorldName) {
  812. worldID = newWorldName
  813. }
  814. //let modified = new Date().valueOf();
  815. console.log('clone: ' + worldName + 'to: ' + worldID);
  816. let newOwner = _LCSUSER.is.pub;
  817. let created = new Date().valueOf();
  818. let worldObj = {
  819. 'owner': newOwner,
  820. 'parent': userName + '/' + worldName,
  821. 'featured': true,
  822. 'published': true
  823. };
  824. let fileNamesAll = await _LCSDB.user(userPub).get('worlds').get(worldName).once().then();
  825. let worldFileNames = Object.keys(fileNamesAll).filter(el => (el !== '_') && (el !== 'owner') && (el !== 'parent') && (el !== 'featured') && (el !== 'published'));
  826. for (var el in worldFileNames) {
  827. let fn = worldFileNames[el];
  828. let res = await _LCSDB.user(userPub).get('worlds').get(worldName).get(fn).once().then();
  829. let data = {
  830. 'file': res.file,
  831. 'modified': created
  832. }
  833. worldObj[fn] = data;
  834. }
  835. console.log(worldObj);
  836. Object.keys(worldObj).forEach(el => {
  837. _LCSUSER.get('worlds').get(worldID).get(el).put(worldObj[el]);
  838. })
  839. }
  840. async cloneWorldState(filename) {
  841. let myWorldProtos = await _LCSUSER.get('worlds').once().then();
  842. let userName = this.helpers.worldUser;
  843. let userPub = await _LCSDB.get('users').get(userName).get('pub').once().then();
  844. let protoUserRoot = this.helpers.getRoot(true).root;
  845. //let myName = _LCSUSER.is.alias;
  846. //let proto = Object.keys(myWorldProtos).filter(el => el == protoUserRoot);
  847. var protosKeys = [];
  848. if (myWorldProtos)
  849. protosKeys = Object.keys(myWorldProtos);
  850. if (protosKeys.includes(protoUserRoot)) {
  851. let userProtoFiles = await this.getProtoWorldFiles(userPub, protoUserRoot);
  852. let myProtoFiles = await this.getProtoWorldFiles(_LCSUSER.is.pub, protoUserRoot);
  853. let hashUP = await this.helpers.sha256(JSON.stringify(userProtoFiles));
  854. let hashMP = await this.helpers.sha256(JSON.stringify(myProtoFiles));
  855. if (hashUP == hashMP) {
  856. this.saveStateAsFile(filename);
  857. } else {
  858. let noty = new Noty({
  859. text: 'world prototype is modified.. could not clone world state',
  860. timeout: 2000,
  861. theme: 'mint',
  862. layout: 'bottomRight',
  863. type: 'error'
  864. });
  865. noty.show();
  866. }
  867. } else {
  868. await this.cloneWorldPrototype(protoUserRoot, userName, protoUserRoot);
  869. this.saveStateAsFile(filename);
  870. }
  871. }
  872. //TODO: refactor and config save
  873. saveStateAsFile(filename, otherProto) // invoke with the view as "this"
  874. {
  875. console.log("Saving: " + filename);
  876. //var clients = this.nodes["http://vwf.example.com/clients.vwf"];
  877. // Save State Information
  878. var state = vwf.getState();
  879. state.nodes[0].children = {};
  880. var timestamp = state["queue"].time;
  881. timestamp = Math.round(timestamp * 1000);
  882. var objectIsTypedArray = function (candidate) {
  883. var typedArrayTypes = [
  884. Int8Array,
  885. Uint8Array,
  886. // Uint8ClampedArray,
  887. Int16Array,
  888. Uint16Array,
  889. Int32Array,
  890. Uint32Array,
  891. Float32Array,
  892. Float64Array
  893. ];
  894. var isTypedArray = false;
  895. if (typeof candidate == "object" && candidate != null) {
  896. typedArrayTypes.forEach(function (typedArrayType) {
  897. isTypedArray = isTypedArray || candidate instanceof typedArrayType;
  898. });
  899. }
  900. return isTypedArray;
  901. };
  902. var transitTransformation = function (object) {
  903. return objectIsTypedArray(object) ?
  904. Array.prototype.slice.call(object) : object;
  905. };
  906. let jsonValuePure = require("vwf/utility").transform(
  907. state, transitTransformation
  908. );
  909. //remove all Ohm generated grammarsfrom state
  910. let jsonValue = _app.helpers.removeGrammarObj(jsonValuePure);
  911. var jsonState = JSON.stringify(jsonValue);
  912. let rootPath = this.helpers.getRoot(true);
  913. var inst = rootPath.inst;
  914. if (filename == '') filename = inst;
  915. //if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  916. var root = rootPath.root;
  917. var json = jsonState;
  918. if (otherProto) {
  919. console.log('need to modify state...');
  920. json = this.helpers.replaceSubStringALL(jsonState, '/' + root + '/', '/' + otherProto + '/');//jsonState.replace(('/' + root + '/'), ('/' + otherProto +'/') );
  921. root = otherProto;
  922. console.log(json);
  923. }
  924. //var documents = _LCSUSER.get('documents');
  925. var saveRevision = new Date().valueOf();
  926. var stateForStore = {
  927. "root": root,
  928. "filename": filename,
  929. "inst": inst,
  930. "timestamp": timestamp,
  931. "extension": ".vwf.json",
  932. "jsonState": json,
  933. "publish": true
  934. };
  935. //let objName = loadInfo[ 'save_name' ] +'/'+ "savestate_" + loadInfo[ 'save_revision' ];
  936. // "savestate_" + loadInfo[ 'save_revision' ] + '/' + loadInfo[ 'save_name' ] + '_vwf_json'
  937. var docName = 'savestate_/' + root + '/' + filename + '_vwf_json';
  938. _LCSUSER.get('documents').get(root).get(docName).put(stateForStore, res => {
  939. if (res) {
  940. let noty = new Noty({
  941. text: 'Saved to ' + docName,
  942. timeout: 2000,
  943. theme: 'mint',
  944. layout: 'bottomRight',
  945. type: 'success'
  946. });
  947. noty.show();
  948. }
  949. });
  950. _LCSUSER.get('worlds').get(root).get('info_json').once(res => {
  951. if (res) {
  952. let modified = saveRevision;
  953. let newOwner = _LCSUSER.is.pub;
  954. let userName = _LCSUSER.is.alias;
  955. let obj = {
  956. 'parent': userName + '/' + root,
  957. 'owner': newOwner,
  958. 'file': res.file,
  959. //'modified': modified,
  960. 'created': modified
  961. }
  962. let docInfoName = 'savestate_/' + root + '/' + filename + '_info_vwf_json';
  963. _LCSUSER.get('documents').get(root).get(docInfoName).not(res => {
  964. _LCSUSER.get('documents').get(root).get(docInfoName).put(obj);
  965. });
  966. _LCSUSER.get('documents').get(root).get(docInfoName).get('created').not(res => {
  967. _LCSUSER.get('documents').get(root).get(docInfoName).get('created').put(modified);
  968. });
  969. _LCSUSER.get('documents').get(root).get(docInfoName).get('modified').put(modified);
  970. }
  971. });
  972. var docNameRev = 'savestate_' + saveRevision.toString() + '/' + root + '/' + filename + '_vwf_json';
  973. _LCSUSER.get('documents').get(root).get(docName).get('revs').get(docNameRev).put(stateForStore)
  974. .path("revision").put(saveRevision);
  975. // Save Config Information
  976. var config = { "info": {}, "model": {}, "view": {} };
  977. // Save browser title
  978. config["info"]["title"] = document.title//$('title').html();
  979. // Save model drivers
  980. Object.keys(vwf_view.kernel.kernel.models).forEach(function (modelDriver) {
  981. if (modelDriver.indexOf('vwf/model/') != -1) config["model"][modelDriver] = "";
  982. });
  983. // If neither glge or threejs model drivers are defined, specify nodriver
  984. if (config["model"]["vwf/model/glge"] === undefined && config["model"]["vwf/model/threejs"] === undefined) config["model"]["nodriver"] = "";
  985. // Save view drivers and associated parameters, if any
  986. Object.keys(vwf_view.kernel.kernel.views).forEach(function (viewDriver) {
  987. if (viewDriver.indexOf('vwf/view/') != -1) {
  988. if (vwf_view.kernel.kernel.views[viewDriver].parameters) {
  989. config["view"][viewDriver] = vwf_view.kernel.kernel.views[viewDriver].parameters;
  990. }
  991. else config["view"][viewDriver] = "";
  992. }
  993. });
  994. //var jsonConfig = $.encoder.encodeForURL(JSON.stringify(config));
  995. var jsonConfig = JSON.stringify(config);
  996. let configStateForStore = {
  997. "root": root,
  998. "filename": filename,
  999. "inst": inst,
  1000. "timestamp": timestamp,
  1001. "extension": "config.vwf.json",
  1002. "jsonState": jsonConfig
  1003. };
  1004. //let objName = loadInfo[ 'save_name' ] +'/'+ "savestate_" + loadInfo[ 'save_revision' ];
  1005. // "savestate_" + loadInfo[ 'save_revision' ] + '/' + loadInfo[ 'save_name' ] + '_vwf_json'
  1006. // let configName = 'savestate_/' + root + '/' + filename + '_config_vwf_json';
  1007. // let documentSaveConfigState = _LCSUSER.get(configName).put(configStateForStore);
  1008. // //documents.path(root).set(documentSaveConfigState);
  1009. // let configNameRev = 'savestate_' + saveRevision.toString() + '/' + root + '/' + filename + '_config_vwf_json';
  1010. // _LCSUSER.get(configNameRev).put(configStateForStore);
  1011. // _LCSUSER.get(configNameRev).path("revision").put(saveRevision);
  1012. //documentSaveConfigState.path('revs').set(documentSaveStateRevision);
  1013. // Save config file to server
  1014. // var xhrConfig = new XMLHttpRequest();
  1015. // xhrConfig.open("POST", "/" + root + "/save/" + filename, true);
  1016. // xhrConfig.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  1017. // xhrConfig.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.config.json" + "&jsonState=" + jsonConfig);
  1018. }
  1019. // LoadSavedState
  1020. async loadSavedState(filename, applicationpath, revision) {
  1021. console.log("Loading: " + filename);
  1022. let userName = await _LCS_WORLD_USER.get('alias').once().then();
  1023. if (revision) {
  1024. window.location.pathname = '/' + userName + applicationpath + '/load/' + filename + '/' + revision + '/';
  1025. }
  1026. else { // applicationpath + "/" + inst + '/load/' + filename + '/';
  1027. window.location.pathname = '/' + userName + applicationpath + '/load/' + filename + '/';
  1028. }
  1029. }
  1030. hideUIControl() {
  1031. var el = document.getElementById("ui-controls");
  1032. if (el) {
  1033. el.classList.remove("visible");
  1034. el.classList.add("not-visible");
  1035. }
  1036. }
  1037. showUIControl() {
  1038. var el = document.getElementById("ui-controls");
  1039. if (el) {
  1040. el.classList.remove("not-visible");
  1041. el.classList.add("visible");
  1042. }
  1043. }
  1044. hideProgressBar() {
  1045. var progressbar = document.getElementById("load-progressbar");
  1046. if (progressbar) {
  1047. progressbar.classList.remove("visible");
  1048. progressbar.classList.add("not-visible");
  1049. progressbar.classList.add("mdc-linear-progress--closed");
  1050. }
  1051. }
  1052. showProgressBar() {
  1053. let progressbar = document.getElementById("load-progressbar");
  1054. if (progressbar) {
  1055. progressbar.classList.add("visible");
  1056. progressbar.classList.add("mdc-linear-progress--indeterminate");
  1057. }
  1058. }
  1059. // SUPPORT of DELETE USER WORLDS & SAVE STATES (experimental)
  1060. // TODO: manual garbage collection
  1061. async deleteWorldState(worldName, indexState) {
  1062. let revs = await _LCSUSER.get('documents').get(worldName).get(indexState).get('revs').once().then();
  1063. if (revs) {
  1064. for (const el of Object.keys(revs)) {
  1065. if (el !== '_') {
  1066. let doc = await _LCSUSER.get('documents').get(worldName).get(indexState).get('revs').get(el).once().then();
  1067. for (const rev of Object.keys(doc)) {
  1068. if (rev !== '_') {
  1069. await _LCSUSER.get('documents').get(worldName).get(indexState).get('revs').get(el).get(rev).put(null).then();
  1070. }
  1071. }
  1072. await _LCSUSER.get('documents').get(worldName).get(indexState).get('revs').get(el).put(null).then();
  1073. }
  1074. }
  1075. }
  1076. // clear all state params
  1077. let stateDoc = await _LCSUSER.get('documents').get(worldName).get(indexState).once().then();
  1078. for (const state of Object.keys(stateDoc)) {
  1079. if (state !== '_' && state !== 'revs') {
  1080. await _LCSUSER.get('documents').get(worldName).get(indexState).get(state).put(null).then();
  1081. }
  1082. }
  1083. await _LCSUSER.get('documents').get(worldName).get(indexState).get('revs').put(null).then();
  1084. await _LCSUSER.get('documents').get(worldName).get(indexState).put(null).then();
  1085. }
  1086. async deleteWorld(name, type) {
  1087. if (type == 'proto') {
  1088. let worldName = name;
  1089. //TODO check for states (ask for deleting all states first...)
  1090. //delete states
  1091. let documents = await _LCSUSER.get('documents').once().then();
  1092. if (documents) {
  1093. let states = await _LCSUSER.get('documents').get(worldName).once().then();
  1094. if (states) {
  1095. for (const el of Object.keys(states)) {
  1096. if (el !== '_') {
  1097. if (states[el]) {
  1098. await this.deleteWorldState(worldName, el);
  1099. }
  1100. }
  1101. }
  1102. }
  1103. }
  1104. let worldFiles = await _LCSUSER.get('worlds').get(worldName).once().then();
  1105. if (worldFiles) {
  1106. for (const el of Object.keys(worldFiles)) {
  1107. if (el !== '_') {
  1108. let doc = await _LCSUSER.get('worlds').get(worldName).get(el).once().then();
  1109. if(doc) {
  1110. if (doc.file) {
  1111. for (const fEl of Object.keys(doc)) {
  1112. if (fEl !== '_') {
  1113. await _LCSUSER.get('worlds').get(worldName).get(el).get(fEl).put(null).then();
  1114. }
  1115. }
  1116. await _LCSUSER.get('worlds').get(worldName).get(el).put(null).then();
  1117. } else {
  1118. await _LCSUSER.get('worlds').get(worldName).get(el).put(null).then()
  1119. }
  1120. }
  1121. }
  1122. }
  1123. }
  1124. // _LCSUSER.get('worlds').get(worldName).map((res, index) => {
  1125. // if(typeof res == 'object'){
  1126. // _LCSUSER.get('worlds').get(worldName).get(index)
  1127. // .get('file').put("null")
  1128. // .back(1)
  1129. // .get('modified').put("null")
  1130. // .back(1)
  1131. // .get('created').put("null")
  1132. // .back(1).put("null")
  1133. // } else {
  1134. // _LCSUSER.get('worlds').get(worldName).get(index).put("null")
  1135. // }
  1136. // })
  1137. await _LCSUSER.get('worlds').get(worldName).put(null).then();
  1138. } else if (type == 'state') {
  1139. let worldName = name.split('/')[0];
  1140. let stateName = name.split('/')[2];
  1141. let stateEntryInfo = 'savestate_/' + worldName + '/' + stateName + '_info_vwf_json';
  1142. let stateEntry = 'savestate_/' + worldName + '/' + stateName + '_vwf_json';
  1143. await this.deleteWorldState(worldName, stateEntryInfo);
  1144. await this.deleteWorldState(worldName, stateEntry);
  1145. }
  1146. }
  1147. }
  1148. export { App }