浏览代码

audio circular dependencies

sebavan 6 年之前
父节点
当前提交
57ddd744f1

+ 1 - 7
Tools/Config/tempCircularValidation/core.json

@@ -10,12 +10,6 @@
     "../../src/Animations/runtimeAnimation.ts": [
         "../../src/Animations/animation.ts"
     ],
-    "../../src/Audio/audioSceneComponent.ts": [
-        "../../src/Audio/sound.ts"
-    ],
-    "../../src/Audio/sound.ts": [
-        "../../src/Audio/audioSceneComponent.ts"
-    ],
     "../../src/Behaviors/Meshes/pointerDragBehavior.ts": [
         "../../src/Gizmos/boundingBoxGizmo.ts"
     ],
@@ -241,5 +235,5 @@
         "../../src/Misc/tools.ts",
         "../../src/PostProcesses/postProcessManager.ts"
     ],
-    "errorCount": 120
+    "errorCount": 118
 }

+ 3 - 3
src/Animations/animation.ts

@@ -1,7 +1,4 @@
-import { Animatable } from "./animatable";
 import { IEasingFunction, EasingFunction } from "./easing";
-import { RuntimeAnimation } from "./runtimeAnimation";
-
 import { Path2, Vector3, Quaternion, Vector2, Color3, Size, Matrix } from "../Maths/math";
 import { Scalar } from "../Maths/math.scalar";
 
@@ -12,6 +9,9 @@ import { Node } from "../node";
 import { Texture } from "../Materials/Textures/texture";
 import { SerializationHelper } from "../Misc/decorators";
 
+declare type Animatable = import("./animatable").Animatable;
+declare type RuntimeAnimation = import("./runtimeAnimation").RuntimeAnimation;
+
     /**
      * Represents the range of an animation
      */

+ 2 - 1
src/Animations/runtimeAnimation.ts

@@ -1,8 +1,9 @@
 import { DeepImmutable } from "../types";
 import { Quaternion, Vector3, Vector2, Size, Color3, Matrix } from "../Maths/math";
-import { Animatable } from "./animatable";
 import { Animation, AnimationEvent } from "./animation";
 
+declare type Animatable = import("./animatable").Animatable;
+
 import { Scene } from "../scene";
 
     // Static values to help the garbage collector

+ 8 - 0
src/Audio/audioSceneComponent.ts

@@ -427,3 +427,11 @@ declare module "../scene" {
             }
         }
     }
+
+    Sound._SceneComponentInitialization = (scene: Scene) => {
+        let compo = scene._getComponent(SceneComponentConstants.NAME_AUDIO);
+        if (!compo) {
+            compo = new AudioSceneComponent(scene);
+            scene._addComponent(compo);
+        }
+    };

+ 6 - 7
src/Audio/sound.ts

@@ -4,10 +4,8 @@ import { Vector3, Tmp } from "../Maths/math";
 import { Nullable } from "../types";
 import { Scene } from "../scene";
 import { Engine } from "../Engines/engine";
-import { AudioSceneComponent } from "../Audio/audioSceneComponent";
 import { AbstractMesh } from "../Meshes/abstractMesh";
 import { TransformNode } from "../Meshes/transformNode";
-import { SceneComponentConstants } from "../sceneComponent";
 import { Logger } from "../Misc/logger";
 
     /**
@@ -115,6 +113,11 @@ import { Logger } from "../Misc/logger";
         private _htmlAudioElement: HTMLAudioElement;
         private _urlType: 'Unknown' | 'String' | 'Array' | 'ArrayBuffer' | 'MediaStream' = "Unknown";
 
+        /** @hidden */
+        public static _SceneComponentInitialization: (scene: Scene) => void = (_) => {
+            throw "Import AudioSceneComponent before creating sound.";
+        }
+
         /**
         * Create a sound and attach it to a scene
         * @param name Name of your sound
@@ -125,11 +128,7 @@ import { Logger } from "../Misc/logger";
         constructor(name: string, urlOrArrayBuffer: any, scene: Scene, readyToPlayCallback: Nullable<() => void> = null, options?: any) {
             this.name = name;
             this._scene = scene;
-            let compo = scene._getComponent(SceneComponentConstants.NAME_AUDIO);
-            if (!compo) {
-                compo = new AudioSceneComponent(scene);
-                scene._addComponent(compo);
-            }
+            Sound._SceneComponentInitialization(scene);
 
             this._readyToPlayCallback = readyToPlayCallback;
             // Default custom attenuation function is a linear attenuation