WIP
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
export const componentMap = new Map();
|
||||||
|
|
||||||
|
export function defineComponent<T>(key: string): Map<string, T> {
|
||||||
|
if (!componentMap.has(key)) {
|
||||||
|
componentMap.set(key, new Map());
|
||||||
|
}
|
||||||
|
|
||||||
|
return componentMap.get(key)!;
|
||||||
|
}
|
||||||
+17
-1
@@ -1,4 +1,4 @@
|
|||||||
import type { Box } from "#/engine/Box.ts";
|
import { type Box, box } from "#/engine/Box.ts";
|
||||||
import { type Drawable, draw, isDrawable } from "#/engine/Drawable.ts";
|
import { type Drawable, draw, isDrawable } from "#/engine/Drawable.ts";
|
||||||
import {
|
import {
|
||||||
entityMap,
|
entityMap,
|
||||||
@@ -8,6 +8,8 @@ import {
|
|||||||
import { type Graph, getNeighbours } from "#/engine/Graph.ts";
|
import { type Graph, getNeighbours } from "#/engine/Graph.ts";
|
||||||
import { useWithAsyncCache } from "#/engine/lib/cache.ts";
|
import { useWithAsyncCache } from "#/engine/lib/cache.ts";
|
||||||
import { animateSprite, type SpriteAnimation } from "#/engine/Sprite.ts";
|
import { animateSprite, type SpriteAnimation } from "#/engine/Sprite.ts";
|
||||||
|
import { componentMap, defineComponent } from "./Component";
|
||||||
|
import { mulberry32 } from "./lib/mulberry32";
|
||||||
|
|
||||||
export type EntityData = {
|
export type EntityData = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -229,3 +231,17 @@ export async function setScene(name: string): Promise<void> {
|
|||||||
handler(data, currentScene.data);
|
handler(data, currentScene.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const next = mulberry32(54850268);
|
||||||
|
|
||||||
|
export function def(name: string): <T>(key: string, value: T) => void {
|
||||||
|
const id = next().toString(16).slice(2);
|
||||||
|
defineComponent<string>("name").set(id, name);
|
||||||
|
|
||||||
|
return (key, value) => {
|
||||||
|
const components = defineComponent(key);
|
||||||
|
components.set(id, value);
|
||||||
|
|
||||||
|
console.log(componentMap);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { type Box, box } from "#/engine/Box.ts";
|
import { type Box, box } from "#/engine/Box.ts";
|
||||||
import { type Circle, createCircle } from "#/engine/Circle.ts";
|
import { type Circle, createCircle } from "#/engine/Circle.ts";
|
||||||
import { moveAndCollide } from "#/engine/Collision.ts";
|
import { moveAndCollide } from "#/engine/Collision.ts";
|
||||||
import { defineEntity } from "#/engine/Entity.ts";
|
import { defineEntity, type Process } from "#/engine/Entity.ts";
|
||||||
import { keyboardInput } from "#/engine/Keyboard.ts";
|
import { keyboardInput } from "#/engine/Keyboard.ts";
|
||||||
import { pointer } from "#/engine/Pointer.ts";
|
import { pointer } from "#/engine/Pointer.ts";
|
||||||
|
import { def } from "#/engine/Scene.ts";
|
||||||
import {
|
import {
|
||||||
createSpriteAnimation,
|
createSpriteAnimation,
|
||||||
type Sprite,
|
type Sprite,
|
||||||
@@ -39,6 +40,10 @@ const state: Hero = {
|
|||||||
animation: box(createSpriteAnimation(sprite, 500, 2)),
|
animation: box(createSpriteAnimation(sprite, 500, 2)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const $ = def("hero");
|
||||||
|
$<Vector>("position", createVector());
|
||||||
|
$<Process>("process", (_id, _delta) => {});
|
||||||
|
|
||||||
const process = defineEntity("hero", state);
|
const process = defineEntity("hero", state);
|
||||||
|
|
||||||
process((entity, delta) => {
|
process((entity, delta) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user