import { createVector, type Vector } from "#/lib/Vector.ts"; export type Indirect = never; export type Entity = { name: string; position: Vector; } & 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( meta: { url: string }, state: T, ): { animate: (fn: Animate) => void; process: (fn: Process) => void; } { const name = meta.url.match(/entities\/(.+)\/entity\.ts$/)![1]; entityMap.set(name, { name, position: createVector(), ...state, }); return { animate(fn) { entityAnimateMap.set(name, fn); }, process(fn) { entityProcessMap.set(name, fn); }, }; }