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

Feature Request: Support passing component class instead of string component names #67

Open
jeremygiberson opened this issue Mar 11, 2021 · 2 comments

Comments

@jeremygiberson
Copy link

I'm not fond of hard coded string usage--especially in reference to code components because editors don't link the two. And code helpers like autocomplete, find references etc don't work w/ the string references.

I'm finding myself using the following to pass component references:

  const game = world.createEntity({
    id: 'game',
    components: [
      {type: Components.GameInfo.type()}
    ]
  });

Which I can make do with, but obviously I'd prefer if the library accepted either form (string or class) and got the type itself. Ie,

  const entity = world.createEntity({
    id: 'game',
    components: [
      {type: Components.GameInfo},
      {type: 'OtherComponent'}
    ]
  });

const gameInfo = entity.getOne(Components.GameInfo); // optionally support class reference
const otherComp = entity.getOne('OtherComponent'); // still support string name
@anderoonies
Copy link

anderoonies commented Jul 1, 2021

@jeremygiberson you can accomplish this using .name, which exists on classes. this could be moved into ape itself, so the queries will extract a .name if the filter isn't type string, but you should be able to do getOne(Components.GameInfo.name)

update: just tested and it works!

@anderoonies
Copy link

second update: looks like this was already implemented~!
https://github.com/fritzy/ape-ecs/blob/master/src/query.js#L90

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

No branches or pull requests

2 participants