ape-ecs
ape-ecs copied to clipboard
Typesafe API for defining Components and creating Entities
Looking for any feedback on this! I'm using it locally for developing a game, and thought it might be useful to others. Similar to #48 Fixes #71
The docs should explain the usage, but basically it allows for:
class Position extends TypedComponent<{x: number, y?: number}>({x: 0, y: 0}) {};
class Texture extends TypedComponent({filePath: "defaultAsset.png"}) {};
const playerEntity = world.createEntityTypesafe({
c: [
{
type: Position,
x: 15
},
{
type: Texture,
filePath: "/assets/img.png",
}
}
});
It also gives safety in world.createEntityTypesafe
, where the initial properties are type checked.
i can refactor the type of createEntity to support both interfaces in the one function if preferred, let me know!