-
Notifications
You must be signed in to change notification settings - Fork 145
High-Level Entity Methods (WIP) #397
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I feel like this hides which components you are querying, could we maybe create the QueryFrom
struct via a query!
macro.
let query = query! {
_: &PlayerMarker,
health: &mut Health,
position: &mut Position,
gamemode: &Gamemode,
_: MessageReciver,
}
impl crate::entity::FromQuery for $wrapper_struct { | ||
type Item = Self; | ||
|
||
fn add_component_types(components: &mut impl Extend<crate::HostComponent>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, $wrapper_struct
can only contain a single component or are $marker
going to become $($marker:ident),*
?
@@ -106,7 +19,7 @@ pub struct QueryIter<Q> { | |||
|
|||
impl<Q> QueryIter<Q> | |||
where | |||
Q: Query, | |||
Q: FromQuery, | |||
{ | |||
pub(crate) fn new() -> Self { | |||
let mut component_types = Vec::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this maybe not be a set, since FromQuery
can have overlapping components?
This PR aims to create a framework for high-level entity methods like "get item in main hand," "deal damage," "send message," etc. These methods require access to multiple components, so they cannot be implemented as methods on a single component struct. The approach taken by this PR is to provide entity wrapper structs for each entity. These wrapper structs implement traits providing the high-level methods.
For example, the
Player
struct implements theSendMessage
trait providing thesend_message()
method.Entity wrappers can be used in queries in the same way components are used right now. For example, to send a message to all players using Quill:
All marker components have been suffixed with
Marker
(e.g.PlayerMarker
) to make them distinct from the new wrapper structs, and to indicate their purpose is secondary to that of wrapper structs.I also intend to add wrappers for abstract entities like
LivingEntity
, which would implement theDamageable
,HasInventory
, etc. traits.This PR is incomplete. I still need to figure out how we can provide entity wrappers in Feather internally as well as Quill without duplicating code. Also, I haven't actually implemented the traits yet.
This might act as an alternative to #388.