JaimeGensler / thyseus

An archetypal Entity Component System, built entirely in Typescript
MIT License
74 stars 3 forks source link

[FEAT] `Query.p.single()` #66

Closed JaimeGensler closed 9 months ago

JaimeGensler commented 11 months ago

Describe the problem this feature solves

Similar to the query.get() proposal, a query.single() API might be a nice addition for unique entities.

Describe the solution you'd like to see

Query.p.single()method that returns the requested data for the entity that matches. Probably we just throw if 0 or multiple entities matches the query

function mySystem(query: Query<Position, With<IsPlayer>>) {
  const position = query.single();
}