I need to write a component for the scene/entity access >.<

This commit is contained in:
kolaflash
2025-12-28 17:00:54 +01:00
parent 1701c38e22
commit 323b7fbd33
7 changed files with 89 additions and 51 deletions
+6 -6
View File
@@ -3,7 +3,7 @@ import { createVector, type Vector } from "#/lib/Vector.ts";
export type Indirect = never;
export type Entity<T> = {
id: string;
name: string;
position: Vector;
} & T;
@@ -20,24 +20,24 @@ export const entityAnimateMap = new Map<string, Animate<Indirect>>();
export const entityProcessMap = new Map<string, Process<Indirect>>();
export function useEntity<T extends object>(
id: string,
name: string,
data: T,
): {
animate: (fn: Animate<T>) => void;
process: (fn: Process<T>) => void;
} {
entityMap.set(id, {
id,
entityMap.set(name, {
name,
position: createVector(),
...data,
});
return {
animate(fn) {
entityAnimateMap.set(id, fn);
entityAnimateMap.set(name, fn);
},
process(fn) {
entityProcessMap.set(id, fn);
entityProcessMap.set(name, fn);
},
};
}