浏览代码

fixing bugs with snippet

msDestiny14 4 年之前
父节点
当前提交
27795e6fb1

+ 2 - 19
guiEditor/src/components/propertyTab/propertyTabComponent.tsx

@@ -13,7 +13,6 @@ import { Observer } from 'babylonjs/Misc/observable';
 import { TextLineComponent } from "../../sharedUiComponents/lines/textLineComponent";
 import { StringTools } from "../../stringTools";
 import { AdvancedDynamicTexture } from "babylonjs-gui/2D/index";
-import { SerializationTools } from "../../serializationTools";
 //import { SceneExplorerComponent } from "../sceneExplorer/sceneExplorerComponent";
 import { Engine } from "babylonjs/Engines/engine";
 import { LockObject } from "../../sharedUiComponents/tabs/propertyGrids/lockObject";
@@ -99,7 +98,7 @@ export class PropertyTabComponent extends React.Component<IPropertyTabComponentP
     load(file: File) {
         Tools.ReadFile(file, (data) => {
             let decoder = new TextDecoder("utf-8");
-            SerializationTools.Deserialize(JSON.parse(decoder.decode(data)), this.props.globalState);
+            this.props.globalState.workbench.loadFromJson(JSON.parse(decoder.decode(data)));
 
             this.props.globalState.onSelectionChangedObservable.notifyObservers(null);
         }, undefined, true);
@@ -110,15 +109,6 @@ export class PropertyTabComponent extends React.Component<IPropertyTabComponentP
         StringTools.DownloadAsFile(this.props.globalState.hostDocument, json, "guiTexture.json");
     }
 
-    customSave() {
-        /*this.props.globalState.onLogRequiredObservable.notifyObservers({message: "Saving your material to Babylon.js snippet server...", isError: false});
-        this.props.globalState.customSave!.action(SerializationTools.Serialize(this.props.globalState.nodeMaterial, this.props.globalState)).then(() => {
-            this.props.globalState.onLogRequiredObservable.notifyObservers({message: "Material saved successfully", isError: false});
-        }).catch((err) => {
-            this.props.globalState.onLogRequiredObservable.notifyObservers({message: err, isError: true});
-        });*/
-    }
-
     saveToSnippetServer() {
         var adt = this.props.globalState.guiTexture;
         let content = JSON.stringify(adt.serializeContent());
@@ -177,8 +167,7 @@ export class PropertyTabComponent extends React.Component<IPropertyTabComponentP
         if (!snippedID) {
             return;
         }
-        this.props.globalState.onSelectionChangedObservable.notifyObservers(null);
-        this.props.globalState.guiTexture.parseFromSnippetAsync(snippedID);
+        this.props.globalState.workbench.loadFromSnippet(snippedID);
     }
 
     renderProperties()
@@ -326,12 +315,6 @@ export class PropertyTabComponent extends React.Component<IPropertyTabComponentP
                         <ButtonLineComponent label="Save" onClick={() => {
                             this.save();
                         }} />
-                        {
-                            this.props.globalState.customSave &&
-                            <ButtonLineComponent label={this.props.globalState.customSave!.label} onClick={() => {
-                                this.customSave();
-                            }} />
-                        }
                     </LineContainerComponent>
                     {
                         

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

@@ -204,12 +204,23 @@ export class WorkbenchComponent extends React.Component<IWorkbenchComponentProps
 		return gridSize * Math.ceil(position / gridSize);
 	}
 
-    loadFromGuiTexture(serializationObject: any) {
+    loadFromJson(serializationObject: any) {
         this.globalState.onSelectionChangedObservable.notifyObservers(null);
         this._guiNodes = [];
         this.globalState.guiTexture.parseContent(serializationObject);
+        this.props.globalState.workbench.loadFromGuiTexture();
+    }
+    
+    async loadFromSnippet(snippedID: string){
+        this.globalState.onSelectionChangedObservable.notifyObservers(null);
+        this._guiNodes = [];
+        await this.globalState.guiTexture.parseFromSnippetAsync(snippedID);
+        this.props.globalState.workbench.loadFromGuiTexture();
+    }
+    
+    loadFromGuiTexture()
+    {
         var children = this.globalState.guiTexture.getChildren();
-
         children[0].children.forEach(guiElement => {
             var newGuiNode = new GUINode(this.props.globalState, guiElement);
             this._guiNodes.push(newGuiNode);

+ 0 - 9
guiEditor/src/serializationTools.ts

@@ -1,9 +0,0 @@
-import { GlobalState } from './globalState';
-
-export class SerializationTools {
-
-    public static Deserialize(serializationObject: any, globalState: GlobalState) {
-        globalState.onIsLoadingChanged.notifyObservers(true);
-        globalState.workbench.loadFromGuiTexture(serializationObject);
-    }
-}