浏览代码

Add more declarations to typescript playground

Gary Hsu 4 年之前
父节点
当前提交
6c4c50b038
共有 2 个文件被更改,包括 31 次插入24 次删除
  1. 26 19
      Playground/src/tools/monacoManager.ts
  2. 5 5
      sandbox/src/tools/environmentTools.ts

+ 26 - 19
Playground/src/tools/monacoManager.ts

@@ -121,7 +121,7 @@ export class MonacoManager {
     private _setNewContent() {
         this._createEditor();
 
-        if(this.globalState.language === "JS"){
+        if (this.globalState.language === "JS") {
             this._editor?.setValue(`// You have to create a function called createScene. This function must return a BABYLON.Scene object
 // You can reference the following variables: engine, canvas
 // You must at least define a camera
@@ -219,26 +219,34 @@ class Playground {
     public async setupMonacoAsync(hostElement: HTMLDivElement, initialCall = false) {
         this._hostElement = hostElement;
 
-        let response = await fetch("https://preview.babylonjs.com/babylon.d.ts");
-        if (!response.ok) {
-            return;
-        }
-
-        let libContent = await response.text();
+        const declarations = [
+            "https://preview.babylonjs.com/babylon.d.ts",
+            "https://preview.babylonjs.com/gui/babylon.gui.d.ts",
+            "https://preview.babylonjs.com/glTF2Interface/babylon.glTF2Interface.d.ts",
+            "https://preview.babylonjs.com/loaders/babylonjs.loaders.d.ts",
+            "https://preview.babylonjs.com/materialsLibrary/babylonjs.materials.d.ts",
+            "https://preview.babylonjs.com/nodeEditor/babylon.nodeEditor.d.ts",
+            "https://preview.babylonjs.com/postProcessesLibrary/babylonjs.postProcess.d.ts",
+            "https://preview.babylonjs.com/proceduralTexturesLibrary/babylonjs.proceduralTextures.d.ts",
+            "https://preview.babylonjs.com/serializers/babylonjs.serializers.d.ts",
+            "https://preview.babylonjs.com/inspector/babylon.inspector.d.ts",
+        ];
+
+        let libContent = "";
+        const responses = await Promise.all(declarations.map((declaration) => fetch(declaration)));
+        for (const response of responses) {
+            if (!response.ok) {
+                return;
+            }
 
-        response = await fetch("https://preview.babylonjs.com/gui/babylon.gui.d.ts");
-        if (!response.ok) {
-            return;
+            libContent += await response.text();
         }
 
-        libContent += await response.text();
-
         this._createEditor();
 
         // Definition worker
         this._setupDefinitionWorker(libContent);
 
-
         // Setup the Monaco compilation pipeline, so we can reuse it directly for our scrpting needs
         this._setupMonacoCompilationPipeline(libContent);
 
@@ -247,21 +255,20 @@ class Playground {
 
         if (initialCall) {
             // Load code templates
-            response = await fetch("templates.json");
+            const response = await fetch("templates.json");
             if (response.ok) {
                 this._templates = await response.json();
-            }        
-            
+            }
+
             // enhance templates with extra properties
             for (const template of this._templates) {
                 (template.kind = monaco.languages.CompletionItemKind.Snippet), (template.sortText = "!" + template.label); // make sure templates are on top of the completion window
                 template.insertTextRules = monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet;
-            }       
-            
+            }
+
             this._hookMonacoCompletionProvider();
         }
 
-
         if (!this.globalState.loadingCodeInProgress) {
             this._setDefaultContent();
         }

+ 5 - 5
sandbox/src/tools/environmentTools.ts

@@ -14,13 +14,13 @@ export class EnvironmentTools {
         "https://assets.babylonjs.com/environments/environmentSpecular.env",
         "https://assets.babylonjs.com/environments/studio.env",
     ];
-    
+
     public static SkyboxesNames = [
         "Default",
         "Studio",
-    ];    
+    ];
 
-    public static LoadSkyboxPathTexture(scene: Scene) {                
+    public static LoadSkyboxPathTexture(scene: Scene) {
         var defaultSkyboxIndex = Math.max(0, LocalStorageHelper.ReadLocalStorageValue("defaultSkyboxId", 0));
         let path = this.SkyboxPath || this.Skyboxes[defaultSkyboxIndex];
         if (path.indexOf(".hdr") === (path.length - 4)) {
@@ -30,7 +30,7 @@ export class EnvironmentTools {
     }
 
     public static HookWithEnvironmentChange(globalState: GlobalState) {
-        globalState.onEnvironmentChanged.add(option => {
+        globalState.onEnvironmentChanged.add((option) => {
             this.SkyboxPath = "";
             let index = EnvironmentTools.SkyboxesNames.indexOf(option);
 
@@ -52,6 +52,6 @@ export class EnvironmentTools {
                     }
                 }
             }
-        });        
+        });
     }
 }