-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
344 additions
and
448 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
import Entity from "./Entity"; | ||
import QuerySystem from "./lib/QuerySystem"; | ||
|
||
export default interface System { | ||
components: Array<Function>; | ||
update(dt: number, entities: Entity[]): void; | ||
destroy(): void; | ||
export default abstract class BaseSystem { | ||
querySystem: QuerySystem; | ||
|
||
requiredComponents: Array<Function> = []; | ||
|
||
constructor(querySystem: QuerySystem) { | ||
this.querySystem = querySystem; | ||
} | ||
|
||
abstract update(dt: number, entities: Entity[]): void; | ||
abstract destroy(): void; | ||
} |
4 changes: 2 additions & 2 deletions
4
src/lib/ecs/components/FovComponent.ts → src/lib/ecs/components/CameraComponent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Component } from "src/lib/ecs/Component"; | ||
|
||
export default class HealthComponent implements Component { | ||
public maximum: number; | ||
public current: number; | ||
|
||
constructor(maximum: number, current: number) { | ||
this.maximum = maximum; | ||
this.current = current; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Entity from "../Entity"; | ||
|
||
export default class PositionMap { | ||
map: (Entity | undefined)[][]; | ||
|
||
constructor(rows: number, cols: number) { | ||
this.map = Array.from({ length: rows }, () => Array.from({ length: cols }, () => undefined)); | ||
} | ||
|
||
public set(x: number, y: number, entity: Entity) { | ||
this.map[y][x] = entity; | ||
} | ||
|
||
public get(x: number, y: number) { | ||
return this.has(x,y) ? this.map[y][x] : undefined; | ||
} | ||
|
||
public has(x: number, y: number) { | ||
return Boolean(this.map[y] && this.map[y][x]); | ||
} | ||
|
||
public clear() { | ||
this.map = [[]]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Entity from "../Entity"; | ||
|
||
export default class QuerySystem { | ||
|
||
private entitiesByQuery: Map<string, Entity[]> = new Map(); | ||
|
||
constructor(private entities: Entity[]) {} | ||
|
||
protected generateKey(componentTypes: Function[]) { | ||
return componentTypes.map(type => type.name).sort().join(','); | ||
} | ||
|
||
query(componentTypes: Function[]): Entity[] { | ||
const key = this.generateKey(componentTypes); | ||
|
||
if (!this.entitiesByQuery.has(key)) { | ||
const matchingEntities = this.entities.filter((entity) => | ||
componentTypes.every((type) => entity.components.has(type)) | ||
); | ||
this.entitiesByQuery.set(key, matchingEntities); | ||
} | ||
|
||
return this.entitiesByQuery.get(key)!; | ||
} | ||
} |
Oops, something went wrong.