瀏覽代碼

Replace code in PG when saving particle editor

David Catuhe 5 年之前
父節點
當前提交
34107a67dd

+ 12 - 0
Playground/js/monacoCreator.js

@@ -27,6 +27,18 @@ class MonacoCreator {
         this.addOnMonacoLoadedCallback(
             function () {
                 this.parent.main.run();
+
+                // Register a global observable for inspector to request code changes
+                window.Playground = {
+                    onRequestCodeChangeObservable: new BABYLON.Observable()
+                }
+
+                window.Playground.onRequestCodeChangeObservable.add((options) => {
+                    let code = this.getCode();
+                    code = code.replace(options.regex, options.replace);
+
+                    this.setCode(code);
+                });
             },
             this
         );

+ 11 - 1
inspector/src/components/actionTabs/tabs/propertyGrids/particleSystems/particleSystemPropertyGridComponent.tsx

@@ -209,6 +209,7 @@ export class ParticleSystemPropertyGridComponent extends React.Component<IPartic
             if (xmlHttp.readyState == 4) {
                 if (xmlHttp.status == 200) {
                     var snippet = JSON.parse(xmlHttp.responseText);
+                    const oldId = system.snippetId ;
                     system.snippetId = snippet.id;
                     if (snippet.version && snippet.version != "0") {
                         system.snippetId += "#" + snippet.version;
@@ -217,8 +218,17 @@ export class ParticleSystemPropertyGridComponent extends React.Component<IPartic
                     if (navigator.clipboard) {
                         navigator.clipboard.writeText(system.snippetId);
                     }
-                    alert("Particle system saved with ID: " + system.snippetId + " (please note that the id was also saved to your clipboard)");
 
+                    let windowAsAny = window as any;
+
+                    if (windowAsAny.Playground) {
+                        windowAsAny.Playground.onRequestCodeChangeObservable.notifyObservers({
+                            regex: new RegExp(oldId, "g"),
+                            replace: system.snippetId
+                        });
+                    }
+
+                    alert("Particle system saved with ID: " + system.snippetId + " (please note that the id was also saved to your clipboard)");
                 }
                 else {
                     alert("Unable to save your particle system");