diff --git a/dev/main.tsx b/dev/main.tsx index c877080..e77a7d6 100644 --- a/dev/main.tsx +++ b/dev/main.tsx @@ -30,7 +30,7 @@ import { GraphBrowser } from "./GraphBrowser.tsx"; async function fetchScenes(): Promise { const indexRef: string[] = await (await fetch(`/api/scenes`)).json(); - const items = indexRef.filter((value) => value.includes("index")); + const items = indexRef.filter((value) => value.includes("scene")); return items.map((i) => i.substring(1).split("/")[0]); } diff --git a/engine/Entity.ts b/engine/Entity.ts index 55fab38..5a0bbe5 100644 --- a/engine/Entity.ts +++ b/engine/Entity.ts @@ -20,16 +20,17 @@ export const entityAnimateMap = new Map>(); export const entityProcessMap = new Map>(); export function useEntity( - name: string, - data: T, + 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(), - ...data, + ...state, }); return { diff --git a/engine/Scene.ts b/engine/Scene.ts index aecb4ad..9a43f62 100644 --- a/engine/Scene.ts +++ b/engine/Scene.ts @@ -48,7 +48,7 @@ export const sceneGraph: Graph = new Map(); export const [loadScene, sceneCache] = useWithAsyncCache( async (name: string) => { - await import(`#/scenes/${name}/index.ts`); + await import(`#/scenes/${name}/scene.ts`); const data = sceneDataMap.get(name)!; const entityInstanceMap = sceneEntiyMap.get(name)!; @@ -56,7 +56,7 @@ export const [loadScene, sceneCache] = useWithAsyncCache( await Promise.all( data.entities.map(async (entity: Entity) => { - await import(`#/entities/${entity.name}/index.ts`); + await import(`#/entities/${entity.name}/entity.ts`); if (!entityInstanceMap.has(entity.name)) { entityInstanceMap.set(entity.name, { diff --git a/entities/barEntity/index.ts b/entities/barEntity/entity.ts similarity index 92% rename from entities/barEntity/index.ts rename to entities/barEntity/entity.ts index f77ee2a..ce4cfb2 100644 --- a/entities/barEntity/index.ts +++ b/entities/barEntity/entity.ts @@ -4,7 +4,7 @@ import { fromSrc, type Sprite } from "#/lib/Sprite.ts"; const idle: Sprite = await fromSrc("/assets/hero/idle.png", 5, 4); -const { animate, process } = useEntity("barEntity", { +const { animate, process } = useEntity(import.meta, { animation: createAnimation(0, 200), stuff: 1, }); diff --git a/entities/fooEntity/index.ts b/entities/fooEntity/entity.ts similarity index 90% rename from entities/fooEntity/index.ts rename to entities/fooEntity/entity.ts index d5efa94..269aa27 100644 --- a/entities/fooEntity/index.ts +++ b/entities/fooEntity/entity.ts @@ -5,7 +5,7 @@ import { fromSrc, type Sprite } from "#/lib/Sprite.ts"; const idle: Sprite = await fromSrc(charIdle, 2, 4); -const { animate, process } = useEntity("fooEntity", { +const { animate, process } = useEntity(import.meta, { animation: createAnimation(2, 500), }); diff --git a/entities/testEntity/index.ts b/entities/testEntity/entity.ts similarity index 98% rename from entities/testEntity/index.ts rename to entities/testEntity/entity.ts index 19b8251..c5a3730 100644 --- a/entities/testEntity/index.ts +++ b/entities/testEntity/entity.ts @@ -22,7 +22,7 @@ const { animate, process } = useEntity<{ }; currentAnimation: "idle" | "walk"; stuff: number; -}>("testEntity", { +}>(import.meta, { animations: { idle: createAnimation(2, 500), walk: createAnimation(2, 250), diff --git a/scenes/barScene/index.ts b/scenes/barScene/scene.ts similarity index 100% rename from scenes/barScene/index.ts rename to scenes/barScene/scene.ts diff --git a/scenes/fooScene/index.ts b/scenes/fooScene/scene.ts similarity index 100% rename from scenes/fooScene/index.ts rename to scenes/fooScene/scene.ts diff --git a/scenes/fuzzScene/index.ts b/scenes/fuzzScene/scene.ts similarity index 100% rename from scenes/fuzzScene/index.ts rename to scenes/fuzzScene/scene.ts diff --git a/scenes/testScene/index.ts b/scenes/testScene/scene.ts similarity index 100% rename from scenes/testScene/index.ts rename to scenes/testScene/scene.ts