refactor: move world concepts into engine
This commit is contained in:
parent
eeedcb8e48
commit
2d15c7ab8d
52 changed files with 3298 additions and 1558 deletions
38
tests/actors.test.ts
Normal file
38
tests/actors.test.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { expect, test } from "bun:test"
|
||||
import { Actor, type Actor as RuntimeActor, type ActorDefinition } from "../engine/scene/Actor"
|
||||
|
||||
type World = { updates: string[] }
|
||||
|
||||
const numberDefinition: ActorDefinition<{ value: number }, World> = {
|
||||
prototype: { groups: [], radius: 1, minY: 0, maxY: 1 },
|
||||
update: (state, _dt, world) => {
|
||||
state.value++
|
||||
world.updates.push(String(state.value))
|
||||
},
|
||||
transform: (state) => ({ x: state.value, y: 0, z: 0, heading: 0, scale: 1 }),
|
||||
}
|
||||
|
||||
const textDefinition: ActorDefinition<{ value: string }, World> = {
|
||||
prototype: { groups: [], radius: 1, minY: 0, maxY: 1 },
|
||||
update: (state, _dt, world) => {
|
||||
state.value += "!"
|
||||
world.updates.push(state.value)
|
||||
},
|
||||
transform: (state) => ({ x: state.value.length, y: 0, z: 0, heading: 0, scale: 1 }),
|
||||
}
|
||||
|
||||
test("one actor collection safely erases unrelated state types", () => {
|
||||
const actors: RuntimeActor<World>[] = [
|
||||
Actor.create(numberDefinition, { value: 1 }),
|
||||
Actor.create(textDefinition, { value: "a" }),
|
||||
]
|
||||
const world: World = { updates: [] }
|
||||
|
||||
for (const actor of actors) {
|
||||
Actor.update(actor, 1, world)
|
||||
}
|
||||
|
||||
expect(world.updates).toEqual(["2", "a!"])
|
||||
expect(Actor.transform(actors[0]).x).toBe(2)
|
||||
expect(Actor.transform(actors[1]).x).toBe(2)
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue