Skip to content

Commit

Permalink
added support for find with no args
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoieh committed Nov 28, 2021
1 parent 88552cd commit 1f57c1a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ecs/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class Query {
this._entityManager = entityManager;
}

public find(entities: IEntity[]): IEntity | undefined {
public find(entities: IEntity[] = this._entityManager.entities): IEntity | undefined {
return entities.find(this._filter);
}

Expand Down
11 changes: 10 additions & 1 deletion tests/ecs/Query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,19 @@ describe('>>> Query', () => {

expect(entitie).toBeDefined();
// will always just return first found entity
expect(entitie?.id).toBe(1);
expect(entitie).not.toBeInstanceOf(Array);
});
});

it('should find with out inputing entities', () => {
const query = new Query((entity: IEntity) => entity.has(C1));
const entitie = query.find();

expect(entitie).toBeDefined();
// will always just return first found entity
expect(entitie).not.toBeInstanceOf(Array);
});

describe('>>> Query filter', () => {
it('should filter all entities with a componet C1', () => {
const query = new Query((entity: IEntity) => entity.has(C1));
Expand Down

0 comments on commit 1f57c1a

Please sign in to comment.