Skip to content

Conversation

@Ecsodikas
Copy link

I wrote some documentation for the methods on Commands that I find myself using often. And as I started learning bevy those are methods I would have liked to just have a small example directly in the docs, so I made them. Let me know if something is not correct or if something could be written better. Maybe I wrote it too beginner friendly and lost some of the use cases of the methods that I have not encountered yet.

If someone tells me what the undocumented methods do, I'm happy to add those doc strings aswell. :)

@karroffel karroffel added C-Docs An addition or correction to our documentation A-ECS Entities, components, systems, and events labels Sep 6, 2020
Copy link
Member

@cart cart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for docs! This will definitely help new people learn how to use commands (which is a common issue)

}

impl Commands {
/// Creates a new entity with a given component in the current [World].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. This doesn't create an entity with a given component, but rather with a given DynamicBundle (which is a "set" of components).

It is worth showing two examples here: a spawn example using tuples:

commands.spawn((MyComponentA, MyComponentB))

And an example using a derived Bundle

#[derive(Bundle)]
struct MyBundle {
  a: MyComponentA,
  b: MyComponentB,
}

commands.spawn(MyBundle {
  a: MyComponentA,
  b: MyComponentB,
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And lets call out that the two examples are equivalent.

self.write_world(Despawn { entity })
}

/// Describes an entity with an additional component.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets rephrase this to "Adds the given component to the current entity"

self
}

/// Adds components to a already existing entity.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Adds a component bundle to an already existing entity"

self.write_world(Insert { entity, components })
}

/// Adds a single component to a already existing entity.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "an already"

…bundle doc, rewrote insert doc, rewrote insert_one doc
@Ecsodikas Ecsodikas requested a review from cart September 7, 2020 16:26
/// # Example
/// ```
/// // An example with only one component
/// commands.spawn(MyComponent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can't spawn single components like this. it must be a tuple. Can we replace it with:

commands.spawn((MyComponent,));

Lets fix this in the other examples too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, damn. I was deceived by 'SpriteComponents' but it is a Bundle. I always wondered why there was a trailing 's'. Now I know. Should be fine now. (hopefully)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you arent the first person. I'm thinking about replacing the "_Components" suffix with "_Bundle" for clarity.

Copy link
Member

@cart cart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome lets merge this!

@cart
Copy link
Member

cart commented Sep 12, 2020

Ah first we need to resolve the formatting conflicts (you can see the suggested fixes in the build logs)

Looks like you just need to remove the extra newlines from the docs.

@Ecsodikas
Copy link
Author

I believe it is not in my power to fix the remaining 5 build actions. Looks like the nightly version of rust is not installed successfully.

@CleanCut
Copy link
Member

I bet CI would succeed now. It's been a month of nightlies. 😄

@Ecsodikas Ecsodikas closed this Oct 12, 2020
@Ecsodikas Ecsodikas reopened this Oct 12, 2020
@cart
Copy link
Member

cart commented Oct 15, 2020

Its interesting that norun still caused doctest failures. I'm thinking we should probably just add unit structs and hide them from the docs using this approach: https://doc.rust-lang.org/rustdoc/documentation-tests.html#hiding-portions-of-the-example

That way we still get protection against breakage.

@memoryruins
Copy link
Contributor

memoryruins commented Oct 15, 2020

The examples will need to be wrapped in some boilerplate since the code is still fully built with no_run and doc tests are treated as external to the current crate, e.g.

/// Despawns only the specified entity, ignoring any other consideration.
/// # Example
/// ```no_run
/// # use bevy_ecs::{Commands, Entity};
/// # fn system(mut commands: Commands) {
/// # let entity_to_despawn = Entity::new(0);
/// commands.despawn(entity_to_despawn);
/// # }
/// ```
pub fn despawn(&mut self, entity: Entity) -> &mut Self {

Another option is to use ignore, but that has no protection from breakage and shows a warning on each example in the docs, so it's usually not preferable.

@cart
Copy link
Member

cart commented Oct 21, 2020

Cool then no-run w/ the additional boilerplate hidden seems like the right call

@Ecsodikas
Copy link
Author

Aye, I'm going to build some boilerplate then. I hope I get some spare time on my sunday.

@DJMcNab
Copy link
Member

DJMcNab commented Jan 22, 2021

Is there a status update on this @eXodiquas?

@cart
Copy link
Member

cart commented Mar 6, 2021

Closed in favor of #976

@cart cart closed this Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Docs An addition or correction to our documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants