mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 15:14:50 +00:00
694c06f3d0
# Objective Currently the `missing_docs` lint is allowed-by-default and enabled at crate level when their documentations is complete (see #3492). This PR proposes to inverse this logic by making `missing_docs` warn-by-default and mark crates with imcomplete docs allowed. ## Solution Makes `missing_docs` warn at workspace level and allowed at crate level when the docs is imcomplete.
47 lines
1.2 KiB
Rust
47 lines
1.2 KiB
Rust
//! This example creates a custom [`SystemParam`] struct that counts the number of players.
|
|
|
|
use bevy::{ecs::system::SystemParam, prelude::*};
|
|
|
|
fn main() {
|
|
App::new()
|
|
.insert_resource(PlayerCount(0))
|
|
.add_systems(Startup, spawn)
|
|
.add_systems(Update, count_players)
|
|
.run();
|
|
}
|
|
|
|
#[derive(Component)]
|
|
struct Player;
|
|
|
|
#[derive(Resource)]
|
|
struct PlayerCount(usize);
|
|
|
|
/// The [`SystemParam`] struct can contain any types that can also be included in a
|
|
/// system function signature.
|
|
///
|
|
/// In this example, it includes a query and a mutable resource.
|
|
#[derive(SystemParam)]
|
|
struct PlayerCounter<'w, 's> {
|
|
players: Query<'w, 's, &'static Player>,
|
|
count: ResMut<'w, PlayerCount>,
|
|
}
|
|
|
|
impl<'w, 's> PlayerCounter<'w, 's> {
|
|
fn count(&mut self) {
|
|
self.count.0 = self.players.iter().len();
|
|
}
|
|
}
|
|
|
|
/// Spawn some players to count
|
|
fn spawn(mut commands: Commands) {
|
|
commands.spawn(Player);
|
|
commands.spawn(Player);
|
|
commands.spawn(Player);
|
|
}
|
|
|
|
/// The [`SystemParam`] can be used directly in a system argument.
|
|
fn count_players(mut counter: PlayerCounter) {
|
|
counter.count();
|
|
|
|
println!("{} players in the game", counter.count.0);
|
|
}
|