Przeglądaj źródła

stable version now works correctly

Raanan Weber 5 lat temu
rodzic
commit
9bd9217ebe

+ 2 - 2
Playground/index.html

@@ -418,11 +418,11 @@
          <!-- Extensions -->
          <script
              src="https://rawcdn.githack.com/BabylonJS/Extensions/f43ab677b4bca0a6ab77132d3f785be300382760/ClonerSystem/src/babylonx.cloner.js"
-             async>
+             >
          </script>
          <script
              src="https://rawcdn.githack.com/BabylonJS/Extensions/785013ec55b210d12263c91f3f0a2ae70cf0bc8a/CompoundShader/src/babylonx.CompoundShader.js"
-             async></script>
+             ></script>
  
          <!-- Scene Manager -->
          <script

+ 1 - 26
Playground/js/index.js

@@ -20,29 +20,4 @@
         this.main.initialize();
     }
 }
-index = new Index();
-
-// defeinsive, in case there was an error loading babylon.js
-// This is done so that search bots will still be able to render the page, even when babylon had a problem while downloading
-if (!window.BABYLON) {
-    window.BABYLON = {
-        Vector3: function () {},
-        Vector2: function () {},
-        Mesh: function () {},
-        Matrix: function () {},
-        GLTF2: {
-            GLTFLoader: {
-                RegisterExtension: function () {}
-            }
-        },
-        SceneLoader: {
-            OnPluginActivatedObservable: {
-                add: function () {}
-            }
-        }
-    }
-    BABYLON.Vector3.Up = function () {};
-    BABYLON.Vector3.Zero = function () {};
-    BABYLON.Vector2.Zero = function () {};
-    BABYLON.Matrix.Zero = function () {};
-}
+index = new Index();

+ 14 - 0
Playground/js/monacoCreator.js

@@ -65,10 +65,24 @@ class MonacoCreator {
 
     // FUNCTIONS
 
+    waitForDefine() {
+        return new Promise(function (resolve, reject) {
+            function timeout() {
+                if (!window.define) {
+                    setTimeout(timeout, 200);
+                } else {
+                    resolve();
+                }
+            }
+            timeout();
+        });
+    }
+
     /**
      * Load the Monaco Node module.
      */
     async loadMonaco(typings) {
+        await this.waitForDefine();
         let response = await fetch(typings || "https://preview.babylonjs.com/babylon.d.ts");
         if (!response.ok) {
             return;

+ 44 - 32
Playground/js/settingsPG.js

@@ -37,8 +37,7 @@ class SettingsPG {
         if (this.scriptLanguage == "JS") {
             this.defaultScene = "scripts/basic scene.js";
             this.parent.monacoCreator.monacoMode = "javascript";
-        }
-        else if (this.scriptLanguage == "TS") {
+        } else if (this.scriptLanguage == "TS") {
             this.defaultScene = "scripts/basic scene.txt";
             this.parent.monacoCreator.monacoMode = "typescript";
         }
@@ -62,7 +61,9 @@ class SettingsPG {
     setFontSize(size) {
         localStorage.setItem("bjs-playground-font", size);
         this.fontSize = size;
-        this.parent.monacoCreator.jsEditor.updateOptions({ fontSize: size });
+        this.parent.monacoCreator.jsEditor.updateOptions({
+            fontSize: size
+        });
         var array = document.getElementsByClassName("displayFontSize");
         for (var i = 0; i < array.length; i++) {
             var subArray = array[i].children;
@@ -96,8 +97,7 @@ class SettingsPG {
             this.parent.utils.setToMultipleID("toJSbutton", "addClass", "selectedLanguage");
             this.parent.utils.setToMultipleID("toJSbutton", "innerHTML", "Javascript");
             this.parent.utils.setToMultipleID("toTSbutton", "title", "Switch to TypeScript");
-        }
-        else if (this.scriptLanguage == "TS") {
+        } else if (this.scriptLanguage == "TS") {
             this.parent.utils.setToMultipleID("toJSbutton", "addClass", "floatLeft");
             this.parent.utils.setToMultipleID("toTSbutton", "addClass", "selectedLanguage");
             this.parent.utils.setToMultipleID("toTSbutton", "innerHTML", "Typescript");
@@ -117,8 +117,7 @@ class SettingsPG {
         if (theme == 'dark') {
             this.vsTheme = 'vs-dark';
             this.parent.utils.setToMultipleID("darkTheme", "addClass", "selected");
-        }
-        else {
+        } else {
             this.vsTheme = 'vs';
             this.parent.utils.setToMultipleID("lightTheme", "addClass", "selected");
         }
@@ -157,6 +156,9 @@ class SettingsPG {
         if (this.mustModifyBJSversion()) {
             this.parent.menuPG.displayWaitDiv();
 
+            window.def = window.define;
+            window.define = undefined;
+
             var apiVersion = localStorage.getItem("bjs-playground-apiversion");
             BABYLON = null;
 
@@ -168,34 +170,44 @@ class SettingsPG {
                 }
             }
 
-            var count = CONFIG_last_versions[position][1].length;
-            for (var i = 0; i < CONFIG_last_versions[position][1].length; i++) {
-                var newBJSscript = document.createElement('script');
-                newBJSscript.src = CONFIG_last_versions[position][1][i];
-                newBJSscript.onload = function () {
-                    count--;
-                    if (count == 0) {
-                        if (BABYLON.Engine.Version.search('-') != -1) this.parent.menuPG.displayVersionNumber("Latest");
-                        else this.parent.menuPG.displayVersionNumber(BABYLON.Engine.Version);
-                        this.parent.utils.setToMultipleID("mainTitle", "innerHTML", "v" + BABYLON.Engine.Version);
-
-                        this.parent.monacoCreator.setCode(localStorage.getItem("bjs-playground-apiversion-tempcode"));
-
-                        localStorage.removeItem("bjs-playground-apiversion");
-                        localStorage.removeItem("bjs-playground-apiversion-tempcode");
-
-                        this.parent.main.compileAndRunFromOutside();
-                    }
-                }.bind(this);
-
-                document.head.appendChild(newBJSscript);
-            }
-        }
-        else return false;
+            var count = CONFIG_last_versions[position][1].length - 1;
+            var newBJSscript = document.createElement('script');
+            newBJSscript.src = CONFIG_last_versions[position][1][0];
+            newBJSscript.onload = function () {
+                for (var i = 1; i < CONFIG_last_versions[position][1].length; i++) {
+                    var newBJSscript = document.createElement('script');
+                    newBJSscript.src = CONFIG_last_versions[position][1][i];
+                    newBJSscript.onload = function () {
+                        count--;
+                        if (count == 0) {
+                            if (BABYLON.Engine.Version.search('-') != -1) this.parent.menuPG.displayVersionNumber("Latest");
+                            else this.parent.menuPG.displayVersionNumber(BABYLON.Engine.Version);
+                            this.parent.utils.setToMultipleID("mainTitle", "innerHTML", "v" + BABYLON.Engine.Version);
+                            this.parent.monacoCreator.addOnMonacoLoadedCallback(() => {
+                                this.parent.monacoCreator.setCode(localStorage.getItem("bjs-playground-apiversion-tempcode"));
+
+
+                                localStorage.removeItem("bjs-playground-apiversion");
+                                localStorage.removeItem("bjs-playground-apiversion-tempcode");
+                                this.parent.main.compileAndRunFromOutside();
+                            });
+
+                            if (window.def) {
+                                window.define = window.def;
+                            }
+
+                        }
+                    }.bind(this);
+
+                    document.head.appendChild(newBJSscript);
+                }
+            }.bind(this);
+            document.head.appendChild(newBJSscript);
+        } else return false;
     };
 
     mustModifyBJSversion() {
         if (localStorage.getItem("bjs-playground-apiversion") && localStorage.getItem("bjs-playground-apiversion") != null && localStorage.getItem("bjs-playground-apiversion") != "Latest") return true;
         else return false;
     };
-};
+};