Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the isPlaying flag of the component when calling component behaviors #5516

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/scene/a-scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ class AScene extends AEntity {

behaviorSet.inUse = true;
for (i = 0; i < behaviorSet.array.length; i++) {
if (!behaviorSet.array[i].el.isPlaying) { continue; }
if (!behaviorSet.array[i].isPlaying) { continue; }
behaviorSet.array[i][behavior](time, timeDelta);
}
behaviorSet.inUse = false;
Expand Down
24 changes: 15 additions & 9 deletions tests/core/scene/a-scene.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ suite('a-scene (without renderer) - WebXR', function () {
AFRAME.registerComponent('test', {
tick: function () { spy(); }
});
el.sceneEl = sceneEl;
el.hasLoaded = true;
el.isPlaying = true;
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
Expand Down Expand Up @@ -372,6 +374,8 @@ suite('a-scene (without renderer) - WebXR', function () {
AFRAME.registerComponent('test', {
tock: function () { spy(); }
});
el.sceneEl = sceneEl;
el.hasLoaded = true;
el.isPlaying = true;
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
Expand Down Expand Up @@ -400,14 +404,12 @@ suite('a-scene (without renderer) - WebXR', function () {

setup(function () {
sceneEl = this.el;
var el = document.createElement('a-entity');
el.isPlaying = true;
AFRAME.registerComponent('test', {});
spy = this.sinon.spy();

behaviorOne = { name: 'test', el: el, tick: () => spy(1), tock: () => spy(1) };
behaviorTwo = { name: 'test', el: el, tick: () => spy(2), tock: () => spy(2) };
behaviorThree = { name: 'test', el: el, tick: () => spy(3), tock: () => spy(3) };
behaviorOne = { name: 'test', isPlaying: true, tick: () => spy(1), tock: () => spy(1) };
behaviorTwo = { name: 'test', isPlaying: true, tick: () => spy(2), tock: () => spy(2) };
behaviorThree = { name: 'test', isPlaying: true, tick: () => spy(3), tock: () => spy(3) };
sceneEl.addBehavior(behaviorOne);
sceneEl.addBehavior(behaviorTwo);
sceneEl.addBehavior(behaviorThree);
Expand Down Expand Up @@ -960,6 +962,8 @@ suite('a-scene (without renderer) - WebVR', function () {
AFRAME.registerComponent('test', {
tick: function () { spy(); }
});
el.sceneEl = sceneEl;
el.hasLoaded = true;
el.isPlaying = true;
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
Expand Down Expand Up @@ -989,6 +993,8 @@ suite('a-scene (without renderer) - WebVR', function () {
AFRAME.registerComponent('test', {
tock: function () { spy(); }
});
el.sceneEl = sceneEl;
el.hasLoaded = true;
el.isPlaying = true;
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
sceneEl.addBehavior(new AFRAME.components.test.Component(el));
Expand Down Expand Up @@ -1295,10 +1301,10 @@ helpers.getSkipCISuite()('a-scene (with renderer)', function () {
test('calls tick behaviors', function () {
var scene = this.el;
registerComponent('test', {});
var Component = {name: 'test', el: {isPlaying: true}, tick: function () {}};
var Component = {name: 'test', isPlaying: true, tick: function () {}};
this.sinon.spy(Component, 'tick');
scene.addBehavior(Component);
scene.addBehavior({name: 'dummy', el: {isPlaying: true}});
scene.addBehavior({name: 'dummy', isPlaying: true});
scene.render();
sinon.assert.called(Component.tick);
sinon.assert.calledWith(Component.tick, scene.time);
Expand All @@ -1307,14 +1313,14 @@ helpers.getSkipCISuite()('a-scene (with renderer)', function () {
test('calls tock behaviors', function () {
var scene = this.el;
registerComponent('test', {});
var Component = {name: 'test', el: {isPlaying: true}, tock: function () {}};
var Component = {name: 'test', isPlaying: true, tock: function () {}};
this.sinon.spy(Component, 'tock');
scene.render = function () {
scene.time = 1;
if (scene.isPlaying) { scene.tock(1); }
};
scene.addBehavior(Component);
scene.addBehavior({el: {isPlaying: true}});
scene.addBehavior({isPlaying: true});
scene.render();
sinon.assert.called(Component.tock);
sinon.assert.calledWith(Component.tock, scene.time);
Expand Down