Преглед изворни кода

allow to edit source files

Nikolay Suslov пре 6 година
родитељ
комит
4fcd1cc17c
4 измењених фајлова са 288 додато и 87 уклоњено
  1. 120 34
      public/app.js
  2. 6 6
      public/defaults/worlds/orchestra/index.vwf.yaml
  3. 17 0
      public/web/index-app.js
  4. 145 47
      public/web/world-app.js

+ 120 - 34
public/app.js

@@ -637,14 +637,97 @@ class App {
               file = _app.helpers.replaceSubStringALL(fileOriginal, "~", '/');
             }
 
-            let worldFile = await _LCSDB.user().get(worldType).get(worldName).get(file).once().then();
+            var worldFile = await _LCSDB.user().get(worldType).get(worldName).get(file).once().then();
             if (worldFile) {
-              console.log(worldFile.file);
+              var source = worldFile.file;
+              if (type == 'state') {
+                source = worldFile.jsonState;
+                var saveName = worldFile.filename;
+              }
+              console.log(source);
 
               let el = document.createElement("div");
               el.setAttribute("id", "worldFILE");
               document.body.appendChild(el);
 
+              var saveGUI = {};
+              if(type == 'proto'){
+
+                saveGUI =  {
+                  $type: "button",
+                  class: "mdc-button mdc-button--raised",
+                  $text: "Save",
+                  onclick: async function (e) {
+                    console.log("save new info");
+                    let editor = document.querySelector("#aceEditor").env.editor;
+                    let newInfo = editor.getValue();
+                    _LCSDB.user().get(worldType).get(worldName).get(file).get('file').put(newInfo, function(res) {
+                      if (res) {
+
+                        let noty = new Noty({
+                          text: 'Saved!',
+                          timeout: 2000,
+                          theme: 'mint',
+                          layout: 'bottomRight',
+                          type: 'success'
+                        });
+                        noty.show();
+
+                        let modified = new Date().valueOf();
+                        _LCSDB.user().get(worldType).get(worldName).get(file).get('modified').put(modified);
+                      }
+                    })
+                  }
+                }
+
+              }
+              if (type == 'state') {
+                saveGUI =  
+                
+                {
+                  $type: "div",
+                  class: "",
+                  $components: [
+                      {    
+                        $type: "button",
+                        class: "mdc-button mdc-button--raised",
+                        $text: "Replace state",
+                        onclick: async function (e) {
+                          console.log("fix state");
+                          let editor = document.querySelector("#aceEditor").env.editor;
+                          let newInfo = editor.getValue();
+                          let fixedState = newInfo; //_app.fixSaveState(newInfo, worldName, oldProtoName);
+
+                          let userPub = await _LCSDB.get('users').get(user).get('pub').then();
+                          let revs = await _app.lookupSaveRevisions(worldName, saveName, userPub);
+                          let lastRevision = revs.sort()[0];
+
+                          var newFile = file.replace('savestate_','savestate_' + lastRevision.toString());
+                          
+                          _LCSDB.user().get(worldType).get(worldName).get(file).get('revs').get(newFile).get('jsonState').put(fixedState);
+                          _LCSDB.user().get(worldType).get(worldName).get(file).get('jsonState').put(fixedState, function(res) {
+                            if (res) {
+      
+                              let noty = new Noty({
+                                text: 'Repalced!',
+                                timeout: 2000,
+                                theme: 'mint',
+                                layout: 'bottomRight',
+                                type: 'success'
+                              });
+                              noty.show();
+      
+                              let modified = new Date().valueOf();
+                              _LCSDB.user().get(worldType).get(worldName).get(file).get('modified').put(modified);
+                            }
+                          })
+                        }
+      
+                      } 
+                  ]
+              }
+                
+              }
 
               let aceEditorCell = {
 
@@ -655,7 +738,7 @@ class App {
                     id: "aceEditor",
                     //style: "width:1200px; height: 800px",
                     $type: "div",
-                    $text: worldFile.file,
+                    $text: source,
                     $init: function () {
                       var mode = "ace/mode/json";
                       if (file.includes('_yaml'))
@@ -670,34 +753,11 @@ class App {
                       editor.setOptions({
                         maxLines: Infinity
                       });
+                      editor.session.setUseWrapMode(true);
+                      
                     }
                   },
-                  {
-                    $type: "button",
-                    class: "mdc-button mdc-button--raised",
-                    $text: "Save",
-                    onclick: async function (e) {
-                      console.log("save new info");
-                      let editor = document.querySelector("#aceEditor").env.editor;
-                      let newInfo = editor.getValue();
-                      _LCSDB.user().get(worldType).get(worldName).get(file).get('file').put(newInfo, function(res) {
-                        if (res) {
-
-                          let noty = new Noty({
-                            text: 'Saved!',
-                            timeout: 2000,
-                            theme: 'mint',
-                            layout: 'bottomRight',
-                            type: 'success'
-                          });
-                          noty.show();
-
-                          let modified = new Date().valueOf();
-                          _LCSDB.user().get(worldType).get(worldName).get(file).get('modified').put(modified);
-                        }
-                      })
-                    }
-                  },
+                  saveGUI,
                   {
                     $type: "button",
                     class: "mdc-button mdc-button--raised",
@@ -963,9 +1023,17 @@ class App {
   // an array of all revisions for that save. (If the save does not exist, this will be
   // an empty array).
 
-  async lookupSaveRevisions(public_path, save_name) {
+  async lookupSaveRevisions(public_path, save_name, userPub) {
 
-    let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
+    var pub = "";
+
+    if(!_LCS_WORLD_USER) {
+      pub = userPub;
+    } else {
+      pub = _LCS_WORLD_USER.pub
+    }
+  
+    let userDB = _LCSDB.user(pub);
 
     var result = [];
     var states = [];
@@ -1121,7 +1189,16 @@ class App {
 
     let users = await _LCSDB.get('users');
     let userPub = await _LCSDB.get('users').get(userName).get('pub').then();
-    //let worldProto = await _LCSDB.user(userPub).get('worlds').get(worldName).once().then();
+    let newOwner = _LCSDB.user().is.pub;
+
+    if(newWorldName){
+
+    let worldProto = await _LCSDB.user(newOwner).get('worlds').get(newWorldName).then();
+    if(worldProto) {
+      console.log('already exist!');
+        return
+    }
+  }
 
     var worldID = window._app.helpers.GenerateInstanceID().toString();
     if (newWorldName) {
@@ -1131,7 +1208,7 @@ class App {
     //let modified = new Date().valueOf();
     console.log('clone: ' + worldName + 'to: ' + worldID);
 
-    let newOwner = _LCSDB.user().is.pub;
+    
     let created = new Date().valueOf();
 
     let worldObj = {
@@ -1447,6 +1524,15 @@ class App {
 
   }
 
+  fixSaveState(jsonState, otherProto, oldProtoName) {
+
+      console.log('fix proto in state...');
+      let json = this.helpers.replaceSubStringALL(jsonState, '/' + oldProtoName + '/', '/' + otherProto + '/');//jsonState.replace(('/' + root + '/'), ('/' + otherProto +'/') );
+      console.log(json);
+
+      return json
+  }
+
   // LoadSavedState 
 
   async loadSavedState(filename, applicationpath, revision) {
@@ -1951,7 +2037,7 @@ class App {
 
     var info = {};
 
-
+    let worlds = await userdb.get('worlds').then();
     let world = await userdb.get('worlds').get(space).then();
     if (world) {
       let res = await userdb.get('worlds').get(space).get('info_json').then();

+ 6 - 6
public/defaults/worlds/orchestra/index.vwf.yaml

@@ -24,15 +24,15 @@ children:
   myLight:
     extends: http://vwf.example.com/aframe/alight.vwf
     properties:
-      type: "directional"
-      intensity: 0.5
-      position: "0.5 2.0 1.0"
-      castShadow: true
+      type: "spot"
+      position: [-2.5, 1, 1.5]
+      rotation: [0, -40, 0]
   myLight2:
     extends: http://vwf.example.com/aframe/alight.vwf
     properties:
-      type: "ambient"
-      intensity: 0.5
+      type: "spot"
+      position: [2, 1.8, 6.5]
+      rotation: [25, 25, -40]
   spaceText:
     extends: http://vwf.example.com/aframe/atext.vwf
     properties:

+ 17 - 0
public/web/index-app.js

@@ -1030,6 +1030,23 @@ class IndexApp {
 
                                     localStorage.setItem('lcs_app_manual_settings', JSON.stringify(arSettings));
                                 } 
+
+                                if (el._turnArOnSwitch.checked){
+
+                                    let arSettings = {
+                                        model:{
+                                            'vwf/model/aframe': null
+                                    }, 
+                                        view:{
+                                            'vwf/view/aframe' : null,
+                                            'vwf/view/aframe-ar-driver': null
+                                    }
+                                }
+    
+                                        localStorage.setItem('lcs_app_manual_settings', JSON.stringify(arSettings));
+                                    } 
+    
+                                
                             }
     }
 

+ 145 - 47
public/web/world-app.js

@@ -15,7 +15,7 @@ class WorldApp {
 
         //this.worlds = {};
         this.language = _LangManager.language;
-          
+
     }
 
 
@@ -77,11 +77,11 @@ class WorldApp {
                                 $type: "div",
                                 class: "mdc-layout-grid__inner",
                                 $components: Object.entries(this._states)
-                                .filter(el =>Object.keys(el[1]).length !== 0)
-                                .sort(function (el1, el2) {
-                                    return parseInt(el2[1].created) - parseInt(el1[1].created)
-                                })
-                                .map(this._makeWorldCard)
+                                    .filter(el => Object.keys(el[1]).length !== 0)
+                                    .sort(function (el1, el2) {
+                                        return parseInt(el2[1].created) - parseInt(el1[1].created)
+                                    })
+                                    .map(this._makeWorldCard)
                             }
                         ]
 
@@ -96,10 +96,10 @@ class WorldApp {
     }
 
 
-    async makeGUI(userPub){
-        
+    async makeGUI(userPub) {
+
         let self = this;
-        let user = {'user': this.userAlias, pub: userPub};
+        let user = { 'user': this.userAlias, pub: userPub };
         let space = this.worldName;
         let saveName = this.saveName;
 
@@ -112,7 +112,7 @@ class WorldApp {
         let worldStatesGUI = [];
 
         var info = {};
-        
+
 
         if (!saveName) {
             info = await _app.getWorldInfo(user, space);
@@ -132,16 +132,17 @@ class WorldApp {
 
         var runWorldGUI = {};
         let settings = worldCardGUI._worldInfo.settings;
-        if(settings){
-            if (settings.ar){
+        if (settings) {
+            if (settings.ar) {
 
                 runWorldGUI = {
                     id: "runWorldGUI",
                     $type: "div",
-                    $init: function(){
+                    $init: function () {
                         console.log(worldCardGUI);
                     },
                     _arSwitch: null,
+                    _turnArOnSwitch: null,
                     $components: [
                         {
                             $type: "div",
@@ -150,25 +151,40 @@ class WorldApp {
                         _cellWidgets.switch({
                             'id': 'arjsView',
                             'init': function () {
-                              this._switch = new mdc.switchControl.MDCSwitch(this);
-                              this._switch.checked = false;
-                              this._arSwitch = this._switch;
+                                this._switch = new mdc.switchControl.MDCSwitch(this);
+                                this._switch.checked = false;
+                                this._arSwitch = this._switch;
                             }
-                          }
-                          ),
-                          {
+                        }
+                        ),
+                        {
                             $type: 'label',
                             for: 'input-forceReplace',
                             $text: 'Edit mode'
-                          }
+                        },
+                        {$type: "div", style: "margin-top: 20px"},
+                        _cellWidgets.switch({
+                            'id': 'arOnView',
+                            'init': function () {
+                                this._turnArOn = new mdc.switchControl.MDCSwitch(this);
+                                this._turnArOn.checked = false;
+                                this._turnArOnSwitch = this._turnArOn;
+                            }
+                        }
+                        ),
+                        {
+                            $type: 'label',
+                            for: 'input-forceReplace',
+                            $text: 'Ar mode'
+                        }
                     ]
-        
+
                 }
-            } 
+            }
 
         }
 
-        
+
 
         let actionsGUI = {
             $cell: true,
@@ -209,7 +225,7 @@ class WorldApp {
                         userGUI.push(
                             {
                                 $type: "a",
-                                class: "mdc-button mdc-button--raised mdc-card__action actionButton",
+                                class: "mdc-button ",
                                 $text: "Edit info",
                                 //href: "/" + desc[2] + '/worlds/' + desc[0] + '/edit', ///:user/worlds/:name/edit
                                 onclick: function (e) {
@@ -223,23 +239,83 @@ class WorldApp {
                                     }
                                     //self.refresh();
                                 }
+                            },
+                            {
+                                $type: "a",
+                                class: "mdc-button ",
+                                $text: "Edit source",
+                                //href: "/" + desc[2] + '/worlds/' + desc[0] + '/edit', ///:user/worlds/:name/edit
+                                onclick: function (e) {
+                                    //'/:user/:type/:name/edit/:file'
+                                    if (desc.type == 'proto') {
+                                        window.location.pathname = "/" + desc.userAlias + '/proto/' + desc.worldName + '/edit/index_vwf_yaml'
+                                    } else if (desc.type == 'saveState') {
+                                        let names = desc.worldName.split('/');
+                                        let filename = ('savestate_/' + names[0] + '/' + names[2] + '_vwf_json').split('/').join("~");
+                                        window.location.pathname = "/" + desc.userAlias + '/state/' + names[0] + '/edit/' + filename;
+                                    }
+                                    //self.refresh();
+                                }
                             }
+
                         );
 
                         if (desc.type == 'proto') {
+                          
                             userGUI.push(
+                                // {
+                                //     $type: "a",
+                                //     class: "mdc-button mdc-button--raised mdc-card__action actionButton",
+                                //     $text: "Edit proto",
+                                //     //href: "/" + desc[2] + '/worlds/' + desc[0] + '/edit', ///:user/worlds/:name/edit
+                                //     onclick: function (e) {
+                                //         window.location.pathname = "/" + desc.userAlias + '/proto/' + desc.worldName + '/edit/index_vwf_yaml'
+                                //     }
+                                // },
+                               
+                                   {
+                                    $type: "a",
+                                    class: "mdc-button ",
+                                    $text: "Edit config",
+                                    //href: "/" + desc[2] + '/worlds/' + desc[0] + '/edit', ///:user/worlds/:name/edit
+                                    onclick: function (e) {
+                                        window.location.pathname = "/" + desc.userAlias + '/proto/' + desc.worldName + '/edit/index_vwf_config_yaml'
+                                    }
+                                },
+                                {$type: "br"},
                                 {
                                     $type: "a",
-                                    class: "mdc-button mdc-button--raised mdc-card__action actionButton",
-                                    $text: "Edit proto",
+                                    class: "mdc-button",
+                                    $text: "Edit appui.js",
                                     //href: "/" + desc[2] + '/worlds/' + desc[0] + '/edit', ///:user/worlds/:name/edit
                                     onclick: function (e) {
-                                        window.location.pathname = "/" + desc.userAlias + '/proto/' + desc.worldName + '/edit/index_vwf_yaml'
+                                        window.location.pathname = "/" + desc.userAlias + '/proto/' + desc.worldName + '/edit/appui_js'
+                                    }
+                                },
+                               
+                                {
+                                    $type: "a",
+                                    class: "mdc-button",
+                                    $text: "Edit assets.json",
+                                    //href: "/" + desc[2] + '/worlds/' + desc[0] + '/edit', ///:user/worlds/:name/edit
+                                    onclick: function (e) {
+                                        window.location.pathname = "/" + desc.userAlias + '/proto/' + desc.worldName + '/edit/assets_json'
+                                    }
+                                },
+                                {
+                                    $type: "a",
+                                    class: "mdc-button",
+                                    $text: "Edit index.vwf.html",
+                                    //href: "/" + desc[2] + '/worlds/' + desc[0] + '/edit', ///:user/worlds/:name/edit
+                                    onclick: function (e) {
+                                        window.location.pathname = "/" + desc.userAlias + '/proto/' + desc.worldName + '/edit/index_vwf_html'
                                     }
                                 }
+                            
                             );
 
                             userGUI.push(
+                                {$type: "br"},
                                 {
                                     $type: "a",
                                     class: "mdc-button mdc-button--raised mdc-card__action actionButton",
@@ -250,11 +326,13 @@ class WorldApp {
                                     }
                                 }
                             );
+                            
                         }
 
 
                         if (desc.type == 'saveState') {
                             userGUI.push(
+                                {$type: "br"},
                                 {
                                     $type: "a",
                                     class: "mdc-button mdc-button--raised mdc-card__action actionButton",
@@ -271,18 +349,38 @@ class WorldApp {
                     }
 
                     if (desc.type == 'proto') {
+                        let worldID = window._app.helpers.GenerateInstanceID().toString();
+
                         userGUI.push(
                             {
-                                $type: "a",
-                                class: "mdc-button mdc-button--raised mdc-card__action actionButton",
-                                $text: self.language.t('clone proto'),//"clone",
-                                onclick: function (e) {
-                                    //console.log('clone');
-                                    _app.cloneWorldPrototype(desc.worldName, desc.userAlias);
-                                    //self.refresh();
-                                }
+                                $type: "div",
+                                style: "margin-top: 20px;",
+                                _protoName: null,
+                                _protoNameField: null,
+                                $components:
+                                    [
+                                        window._app.widgets.inputTextFieldOutlined({
+                                            "id": 'protoName',
+                                            "label": worldID,
+                                            "value": this._protoName,
+                                            "type": "text",
+                                            "init": function () {
+                                                this._protoNameField = new mdc.textField.MDCTextField(this);
+                                            }
+                                        }),
+                                        {
+                                            $type: "a",
+                                            class: "mdc-button mdc-button--raised mdc-card__action actionButton",
+                                            $text: self.language.t('clone proto'),//"clone",
+                                            onclick: function (e) {
+                                                //console.log('clone');
+                                                let newProtoName = this._protoNameField.value;
+                                                _app.cloneWorldPrototype(desc.worldName, desc.userAlias, newProtoName);
+                                                //self.refresh();
+                                            }
+                                        }
+                                    ]
                             }
-
                         )
                     } else if (desc.type == 'saveState') {
 
@@ -315,7 +413,7 @@ class WorldApp {
             }
         }
 
-    
+
         document.querySelector("#aboutWorld").$cell({
             id: 'aboutWorld',
             $cell: true,
@@ -345,7 +443,7 @@ class WorldApp {
                                     class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
                                     $components: [
                                         worldCardGUI,
-                                        {$type: 'p'},
+                                        { $type: 'p' },
                                         runWorldGUI
                                     ]
                                 },
@@ -376,22 +474,22 @@ class WorldApp {
 
     async initWorldGUI() {
 
-    //  _LCSDB.on('auth',
-    //     function (ack) {
-    //         if(ack.pub)
-    //             document.querySelector('#worldActionsGUI')._refresh();
-            
-    //     });
+        //  _LCSDB.on('auth',
+        //     function (ack) {
+        //         if(ack.pub)
+        //             document.querySelector('#worldActionsGUI')._refresh();
+
+        //     });
 
         let self = this;
-       let users =  await _LCSDB.get('users').then();
-        await _LCSDB.get('users').get(this.userAlias).get('pub').then(function(res){
+        let users = await _LCSDB.get('users').then();
+        await _LCSDB.get('users').get(this.userAlias).get('pub').then(function (res) {
 
             self.makeGUI(res)
 
         });
 
-       
+
 
     }