From fa817e3072e269624f45dccf59a47a99f954f62f Mon Sep 17 00:00:00 2001 From: cha0s Date: Mon, 22 Jul 2024 01:12:17 -0500 Subject: [PATCH] fix: query deindexing --- app/ecs/ecs.test.js | 12 ++++++++++-- app/ecs/query.js | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/ecs/ecs.test.js b/app/ecs/ecs.test.js index 808b031..fec954b 100644 --- a/app/ecs/ecs.test.js +++ b/app/ecs/ecs.test.js @@ -170,10 +170,16 @@ test('ticks systems', async () => { .to.deep.equal(JSON.stringify({y: 128 + 30})); }); -test('schedules entities to be deleted when ticking systems', () => { +test('schedules entities to be deleted when ticking systems', async () => { const ecs = new Ecs({ + Components: {Empty}, Systems: { Despawn: class extends System { + static queries() { + return { + default: ['Empty'], + }; + } tick() { this.ecs.destroy(1); expect(ecs.get(1)) @@ -183,8 +189,10 @@ test('schedules entities to be deleted when ticking systems', () => { }, }); ecs.system('Despawn').active = true; - ecs.create(); + await ecs.create({Empty: {}}); ecs.tick(1); + expect(Array.from(ecs.system('Despawn').select('default'))) + .to.have.lengthOf(0); expect(ecs.get(1)) .to.be.undefined; }); diff --git a/app/ecs/query.js b/app/ecs/query.js index be8aa2d..ec5ed2b 100644 --- a/app/ecs/query.js +++ b/app/ecs/query.js @@ -24,8 +24,8 @@ export default class Query { } deindex(entityIds) { - for (let i = 0; i < entityIds.length; ++i) { - this.$$index.delete(entityIds[i]); + for (const entityId of entityIds) { + this.$$index.delete(entityId); } }