import { createVector, type Vector } from "#/lib/Vector.ts"; export type Entity = { id: string; position: Vector; state: T; }; export type Animate = ( entity: Entity, ctx: CanvasRenderingContext2D, delta: number, ) => void; export type Process = (entity: Entity, delta: number) => void; export const entityMap = new Map>(); export const entityAnimateMap = new Map>(); export const entityProcessMap = new Map>(); export function useEntity( id: string, state: T, ): { animate: (fn: Animate) => void; process: (fn: Process) => void; } { entityMap.set(id, { id, position: createVector(), state, }); return { animate(fn: Animate): void { entityAnimateMap.set(id, fn); }, process(fn: Process): void { entityProcessMap.set(id, fn); }, }; }