Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typesafe API for defining Components and creating Entities #72

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

anderoonies
Copy link

@anderoonies anderoonies commented Jul 8, 2021

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
Copy link
Author

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

@anderoonies anderoonies force-pushed the typesafe-api branch 6 times, most recently from 16bf49c to b24f84f Compare August 10, 2021 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better type support for Components
1 participant