-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!
Description
What problem does this solve or what need does it fill?
Selecting random elements is a common gameplay tasks. We can quickly and ergonomically generate possible lists of
What solution would you like?
Implement the SliceRandom trait for Query.
Nope, this is not publically implementable. We have to use the alternative, implementing it for our associated iterator type.
Create an example.
What alternative(s) have you considered?
- Users could manually implement this functionality each time. This is tedious, error prone and probably slower.
- We could create our own methods that do this. This breaks from the ecosystem standard for no good reason.
- We could implement the
IteratorRandomtrait instead. Taking a look, our ability to mutate the elements of the query + desire to be able to shuffle the order probably makesSliceRandommore fitting. More importantly,Queryisn't itself an iterator (nor should it be): being able to operate directly on a query rather thanquery.iter()is more natural and convenient.
Additional context
Related to #1470.
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!