Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comments

Typesafe API for defining Components and creating Entities#72

Open
anderoonies wants to merge 5 commits intofritzy:masterfrom
anderoonies:typesafe-api
Open

Typesafe API for defining Components and creating Entities#72
anderoonies wants to merge 5 commits intofritzy:masterfrom
anderoonies:typesafe-api

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