Ver código fonte

adding snippet server loading from url

msDestiny14 4 anos atrás
pai
commit
5ad41cc48b

+ 4 - 20
guiEditor/public/index.js

@@ -21,26 +21,9 @@ var checkHash = function () {
             cleanHash();
 
             previousHash = location.hash;
-
-            try {
-                var xmlHttp = new XMLHttpRequest();
-                xmlHttp.onreadystatechange = function () {
-                    if (xmlHttp.readyState == 4) {
-                        if (xmlHttp.status == 200) {
-
-                            //var snippet = JSON.parse(JSON.parse(xmlHttp.responseText).jsonPayload);
-                            showEditor();
-                        }
-                    }
-                }
-
-                var hash = location.hash.substr(1);
-                currentSnippetToken = hash.split("#")[0];
-                xmlHttp.open("GET", snippetUrl + "/" + hash.replace("#", "/"));
-                xmlHttp.send();
-            } catch (e) {
-
-            }
+            var hash = location.hash.substr(1);
+            currentSnippetToken = hash.split("#")[0];
+            showEditor();
         }
     }
 
@@ -54,6 +37,7 @@ var showEditor = function() {
     BABYLON.GuiEditor.Show({
         hostElement: hostElement,
         customLoadObservable: customLoadObservable,
+        currentSnippetToken: currentSnippetToken,
         customSave: {
             label: "Save as unique URL",
             action: (data) => {

+ 1 - 2
guiEditor/src/diagram/workbench.tsx

@@ -142,7 +142,6 @@ export class WorkbenchComponent extends React.Component<IWorkbenchComponentProps
 
         props.globalState.onSelectionChangedObservable.add(selection => {  
             console.log(selection);
-            
             this.selectedGuiNodes.forEach(element => {
                 element.isSelected = false;
             }); 
@@ -532,7 +531,7 @@ export class WorkbenchComponent extends React.Component<IWorkbenchComponentProps
         window.addEventListener("resize", function () {
         engine.resize();
         });
-
+        this.props.globalState.onErrorMessageDialogRequiredObservable.notifyObservers(`Please note: This editor is still a work in progress. You may submit feedback to msDestiny14 on GitHub.`);
         engine.runRenderLoop(() => {this.updateGUIs(); scene.render()});
     }
     

+ 12 - 3
guiEditor/src/guiEditor.ts

@@ -4,12 +4,15 @@ import { GlobalState } from "./globalState";
 import { WorkbenchEditor } from "./workbenchEditor";
 import { Popup } from "./sharedUiComponents/lines/popup";
 import { Observable } from "babylonjs/Misc/observable";
+import { WorkbenchComponent } from "./diagram/workbench";
+
 /**
  * Interface used to specify creation options for the gui editor
  */
 export interface IGUIEditorOptions {
     hostElement?: HTMLElement;
     customSave?: { label: string; action: (data: string) => Promise<void> };
+    currentSnippetToken?: string;
     customLoadObservable?: Observable<any>;
 }
 
@@ -42,16 +45,22 @@ export class GUIEditor {
         globalState.hostDocument = hostElement.ownerDocument!;
         globalState.customSave = options.customSave;
         globalState.hostWindow = hostElement.ownerDocument!.defaultView!;
-
+        
         const graphEditor = React.createElement(WorkbenchEditor, {
             globalState: globalState,
         });
-
+        
         ReactDOM.render(graphEditor, hostElement);
-
         // create the middle workbench canvas
         if (!globalState.guiTexture) {
             globalState.workbench.createGUICanvas();
+            try {
+                if(options.currentSnippetToken) {
+                    globalState.workbench.loadFromSnippet(options.currentSnippetToken);
+                }
+            } catch (error) {
+                console.log(error);
+            }
         }
 
         if (options.customLoadObservable) {