fix: query deindexing

This commit is contained in:
cha0s 2024-07-22 01:12:17 -05:00
parent c224445345
commit fa817e3072
2 changed files with 12 additions and 4 deletions

View File

@ -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;
});

View File

@ -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);
}
}