소스 검색

Remove old animations with same target property as a new one

noalak 5 년 전
부모
커밋
bd48adfd1f
1개의 변경된 파일15개의 추가작업 그리고 0개의 파일을 삭제
  1. 15 0
      src/Loading/sceneLoader.ts

+ 15 - 0
src/Loading/sceneLoader.ts

@@ -1117,6 +1117,21 @@ export class SceneLoader {
         animatableObjectsInAC.forEach(animatableObjectInAC => {
             let objectInScene = _targetConverter(animatableObjectInAC);
             if (objectInScene != null) {
+                // Remove old animations with same target property as a new one
+                animatableObjectInAC.animations.forEach((animationInAC: Animation) => {
+                    // Doing treatment on an array for safety measure
+                    let animationsWithSameProperty = objectInScene.animations.filter((animationInScene: Animation) => {
+                        return animationInScene.targetProperty === animationInAC.targetProperty
+                    })
+                    animationsWithSameProperty.forEach((animationWithSameProperty: Animation) => {
+                        const index = objectInScene.animations.indexOf(animationWithSameProperty, 0);
+                        if (index > -1) {
+                            objectInScene.animations.splice(index, 1);
+                        }
+                    })
+                });
+
+                // Append new animations
                 objectInScene.animations = objectInScene.animations.concat(animatableObjectInAC.animations);
             }
         });