fix querying multiple components in entity_by

This commit is contained in:
mat 2023-07-26 00:45:06 -05:00
parent 22ea8c60fe
commit 39943447f6
4 changed files with 9 additions and 6 deletions

View file

@ -58,7 +58,7 @@ impl TranslatableComponent {
while i < template.chars().count() {
if template.chars().nth(i).unwrap() == '%' {
let Some(char_after) = template.chars().nth(i + 1) else {
built_text.push(template.chars().nth(i).unwrap());
built_text.push('%');
break;
};
i += 1;
@ -161,7 +161,6 @@ impl From<StringOrComponent> for TextComponent {
}
}
// tests
#[cfg(test)]
mod tests {
use super::*;

View file

@ -43,7 +43,7 @@ impl Client {
///
/// # fn example(mut bot: Client, sender_name: String) {
/// let entity = bot.entity_by::<With<Player>, (&GameProfileComponent,)>(
/// |profile: &&GameProfileComponent| profile.name == sender_name,
/// |(profile,): &(&GameProfileComponent,)| profile.name == sender_name,
/// );
/// if let Some(entity) = entity {
/// let position = bot.entity_component::<Position>(entity);
@ -76,7 +76,7 @@ impl Client {
pub trait EntityPredicate<Q: ReadOnlyWorldQuery, Filter: ReadOnlyWorldQuery> {
fn find(&self, ecs_lock: Arc<Mutex<World>>) -> Option<Entity>;
}
impl<F, Q, Filter> EntityPredicate<(Q,), Filter> for F
impl<F, Q, Filter> EntityPredicate<Q, Filter> for F
where
F: Fn(&ROQueryItem<Q>) -> bool,
Q: ReadOnlyWorldQuery,

View file

@ -147,7 +147,11 @@ pub fn generate(input: &DeclareMenus) -> TokenStream {
///
/// The indexes in this will match up with [`Menu::slot_mut`].
///
/// If you don't want to include the player's inventory, use [`Menu::contents`] instead.
/// If you don't want to include the player's inventory, use [`Menu::contents`]
/// instead.
///
/// If you *only* want to include the players inventory, then you can filter by only
/// using the slots in [`Self::player_slots_range`].
pub fn slots(&self) -> Vec<ItemSlot> {
match self {
#slots_match_variants

View file

@ -99,7 +99,7 @@ async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result<
// .find(|e| e.name() == Some(sender));
// let entity = bot.entity_by::<With<Player>>(|name: &Name| name == sender);
let entity = bot.entity_by::<With<Player>, (&GameProfileComponent,)>(
|profile: &&GameProfileComponent| {
|(profile,): &(&GameProfileComponent,)| {
println!("entity {profile:?}");
profile.name == sender
},