Skip to content

Commit d8ef657

Browse files
authored
Check the isPlaying flag of the component when calling component behaviors (#5516)
Co-authored-by: Noeri Huisman <mrxz@users.noreply.github.com>
1 parent 416ac7d commit d8ef657

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/core/scene/a-scene.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ class AScene extends AEntity {
796796

797797
behaviorSet.inUse = true;
798798
for (i = 0; i < behaviorSet.array.length; i++) {
799-
if (!behaviorSet.array[i].el.isPlaying) { continue; }
799+
if (!behaviorSet.array[i].isPlaying) { continue; }
800800
behaviorSet.array[i][behavior](time, timeDelta);
801801
}
802802
behaviorSet.inUse = false;

tests/core/scene/a-scene.test.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ suite('a-scene (without renderer) - WebXR', function () {
343343
AFRAME.registerComponent('test', {
344344
tick: function () { spy(); }
345345
});
346+
el.sceneEl = sceneEl;
347+
el.hasLoaded = true;
346348
el.isPlaying = true;
347349
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
348350
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
@@ -372,6 +374,8 @@ suite('a-scene (without renderer) - WebXR', function () {
372374
AFRAME.registerComponent('test', {
373375
tock: function () { spy(); }
374376
});
377+
el.sceneEl = sceneEl;
378+
el.hasLoaded = true;
375379
el.isPlaying = true;
376380
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
377381
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
@@ -400,14 +404,12 @@ suite('a-scene (without renderer) - WebXR', function () {
400404

401405
setup(function () {
402406
sceneEl = this.el;
403-
var el = document.createElement('a-entity');
404-
el.isPlaying = true;
405407
AFRAME.registerComponent('test', {});
406408
spy = this.sinon.spy();
407409

408-
behaviorOne = { name: 'test', el: el, tick: () => spy(1), tock: () => spy(1) };
409-
behaviorTwo = { name: 'test', el: el, tick: () => spy(2), tock: () => spy(2) };
410-
behaviorThree = { name: 'test', el: el, tick: () => spy(3), tock: () => spy(3) };
410+
behaviorOne = { name: 'test', isPlaying: true, tick: () => spy(1), tock: () => spy(1) };
411+
behaviorTwo = { name: 'test', isPlaying: true, tick: () => spy(2), tock: () => spy(2) };
412+
behaviorThree = { name: 'test', isPlaying: true, tick: () => spy(3), tock: () => spy(3) };
411413
sceneEl.addBehavior(behaviorOne);
412414
sceneEl.addBehavior(behaviorTwo);
413415
sceneEl.addBehavior(behaviorThree);
@@ -960,6 +962,8 @@ suite('a-scene (without renderer) - WebVR', function () {
960962
AFRAME.registerComponent('test', {
961963
tick: function () { spy(); }
962964
});
965+
el.sceneEl = sceneEl;
966+
el.hasLoaded = true;
963967
el.isPlaying = true;
964968
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
965969
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
@@ -989,6 +993,8 @@ suite('a-scene (without renderer) - WebVR', function () {
989993
AFRAME.registerComponent('test', {
990994
tock: function () { spy(); }
991995
});
996+
el.sceneEl = sceneEl;
997+
el.hasLoaded = true;
992998
el.isPlaying = true;
993999
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
9941000
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
@@ -1295,10 +1301,10 @@ helpers.getSkipCISuite()('a-scene (with renderer)', function () {
12951301
test('calls tick behaviors', function () {
12961302
var scene = this.el;
12971303
registerComponent('test', {});
1298-
var Component = {name: 'test', el: {isPlaying: true}, tick: function () {}};
1304+
var Component = {name: 'test', isPlaying: true, tick: function () {}};
12991305
this.sinon.spy(Component, 'tick');
13001306
scene.addBehavior(Component);
1301-
scene.addBehavior({name: 'dummy', el: {isPlaying: true}});
1307+
scene.addBehavior({name: 'dummy', isPlaying: true});
13021308
scene.render();
13031309
sinon.assert.called(Component.tick);
13041310
sinon.assert.calledWith(Component.tick, scene.time);
@@ -1307,14 +1313,14 @@ helpers.getSkipCISuite()('a-scene (with renderer)', function () {
13071313
test('calls tock behaviors', function () {
13081314
var scene = this.el;
13091315
registerComponent('test', {});
1310-
var Component = {name: 'test', el: {isPlaying: true}, tock: function () {}};
1316+
var Component = {name: 'test', isPlaying: true, tock: function () {}};
13111317
this.sinon.spy(Component, 'tock');
13121318
scene.render = function () {
13131319
scene.time = 1;
13141320
if (scene.isPlaying) { scene.tock(1); }
13151321
};
13161322
scene.addBehavior(Component);
1317-
scene.addBehavior({el: {isPlaying: true}});
1323+
scene.addBehavior({isPlaying: true});
13181324
scene.render();
13191325
sinon.assert.called(Component.tock);
13201326
sinon.assert.calledWith(Component.tock, scene.time);

0 commit comments

Comments
 (0)