Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/choppedstudio/bevy_ecs_markers
🏷️ Markers for Bevy ECS Entities
https://github.com/choppedstudio/bevy_ecs_markers
bevy
Last synced: 3 months ago
JSON representation
🏷️ Markers for Bevy ECS Entities
- Host: GitHub
- URL: https://github.com/choppedstudio/bevy_ecs_markers
- Owner: ChoppedStudio
- License: apache-2.0
- Created: 2022-12-18T12:55:16.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-17T18:51:55.000Z (10 months ago)
- Last Synced: 2024-09-22T11:32:28.795Z (4 months ago)
- Topics: bevy
- Language: Rust
- Homepage: https://crates.io/crates/bevy_ecs_markers
- Size: 48.8 KB
- Stars: 11
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Bevy ECS Markers
[![Crates.io](https://img.shields.io/crates/v/bevy_ecs_markers.svg)](https://crates.io/crates/bevy_ecs_markers)
[![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](https://github.com/ChoppedStudio/bevy_ecs_markers#license)Adds the support for marking entites and fetching them in queries
## Example
View more examples [here](examples/)
```rust
#[derive(EntityMarker)]
enum Players {
Red,
Blue,
Green,
Yellow,
}#[derive(Component)]
struct Player {
field: usize,
}fn main() {
App::new()
.add_plugins(LogPlugin::default())
.init_marker::()
.add_systems(Startup, (setup, move_red_player).chain())
.run();
}fn setup(mut commands: Commands, mut players: MarkerMut) {
players[Players::Red].assign(commands.spawn(Player { field: 2 }).id());
players[Players::Blue].assign(commands.spawn(Player { field: 5 }).id());
players[Players::Green].assign(commands.spawn(Player { field: 7 }).id());
players[Players::Yellow].assign(commands.spawn(Player { field: 1 }).id());
}fn move_red_player(mut query: Query<&mut Player>, current: Marker) {
let Ok(mut player) = query.get_mut(current[Players::Red].id()) else {
warn!("Red Player not set yet!");
return;
};let old = player.field;
player.field += 2;
let new = player.field;info!("Player moved from field {old} to field {new}");
}
```## License
- MIT License ([LICENSE-MIT](LICENSE-MIT) or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT))
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0))at your option.