Add more test coverage

This commit is contained in:
Peter Stockings
2026-01-05 14:03:25 +11:00
parent ce68470ab1
commit f86daac9ac
5 changed files with 260 additions and 189 deletions

View File

@@ -5,13 +5,16 @@ export class EntityManager {
private grid: Map<number, EntityId[]> = new Map();
private actors: Map<EntityId, Actor>;
private world: World;
private lastId: number = 0;
constructor(world: World) {
this.world = world;
this.actors = world.actors;
this.lastId = Math.max(0, ...this.actors.keys());
this.rebuildGrid();
}
rebuildGrid() {
this.grid.clear();
for (const actor of this.actors.values()) {
@@ -77,6 +80,8 @@ export class EntityManager {
}
}
getActorsAt(x: number, y: number): Actor[] {
const i = idx(this.world, x, y);
const ids = this.grid.get(i);
@@ -93,6 +98,8 @@ export class EntityManager {
}
getNextId(): EntityId {
return Math.max(0, ...this.actors.keys()) + 1;
this.lastId++;
return this.lastId;
}
}