30 lines
792 B
TypeScript
30 lines
792 B
TypeScript
import { ComponentType, TrailingPositionComponent } from "./component";
|
|
import { Game } from "./game";
|
|
import { System, SystemType } from "./system";
|
|
|
|
interface Point {
|
|
x: number;
|
|
y: number;
|
|
time: number;
|
|
}
|
|
|
|
export class TrailingPositionSystem extends System {
|
|
constructor(
|
|
private readonly point_filter: (trail_point: Array<Point>) => Array<Point>
|
|
) {
|
|
super(SystemType.TRAILING_POSITION);
|
|
}
|
|
|
|
public update(_dt: number, game: Game) {
|
|
game.for_each_entity_with_component(
|
|
ComponentType.TRAILING_POSITION,
|
|
(entity) => {
|
|
const trailing_position = entity.components[
|
|
ComponentType.TRAILING_POSITION
|
|
] as TrailingPositionComponent;
|
|
trailing_position.trails = this.point_filter(trailing_position.trails);
|
|
}
|
|
);
|
|
}
|
|
}
|