ape-ecs icon indicating copy to clipboard operation
ape-ecs copied to clipboard

Typesafe API for defining Components and creating Entities

Open anderoonies opened this issue 3 years ago • 1 comments

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.

anderoonies avatar Jul 08 '21 19:07 anderoonies

i can refactor the type of createEntity to support both interfaces in the one function if preferred, let me know!

anderoonies avatar Jul 11 '21 21:07 anderoonies