Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dekirisu/bevy_cell
Attach Bevy's Handles/Entities statically to Types.
https://github.com/dekirisu/bevy_cell
bevy lazy macro rustlang
Last synced: 3 months ago
JSON representation
Attach Bevy's Handles/Entities statically to Types.
- Host: GitHub
- URL: https://github.com/dekirisu/bevy_cell
- Owner: dekirisu
- License: apache-2.0
- Created: 2023-08-31T08:42:21.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-10T11:14:16.000Z (9 months ago)
- Last Synced: 2024-09-29T21:02:33.446Z (4 months ago)
- Topics: bevy, lazy, macro, rustlang
- Language: Rust
- Homepage:
- Size: 39.1 KB
- Stars: 33
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
🦊 Easily attach bevy's Handles/Entities statically to types
🐑 Get them in any system, without using Resources.
🦄 See type_cell for any other use case!
```toml
[dependencies]
bevy_cell = "0.13"
```
```rust
use bevy_cell::*;
```
---I. There are 2 valid syntaxes:
🐰 `{Type} [name1] [name2] [name3]`
🦝 `Type: [name1] [name2] [name3];`
II. The syntax inside the `[]` will change the attached type:
🐈 **Entity** - Just choose a name: `[camera]`
🦥 **Handle** - Its type separated by a `|`: `[Image|cat]`
🐹 **Raw** - Its type separated by a `:`: `[Image:cat]`
🐒 If no type is set, the parent type is used: `[|cat]` `[:cat]`
III. Setting the collection type is also done inside `[]`:
🦄 **Single** - Using the syntax as in **II.**
🐔 **Vec** - add a `<>` after the name: `[cameras<>]`
🐲 **HashMap** - add a `` after the name: `[cameras]`
```rust
// Macro Examples
bycell! {
Camera: [main] [secondary];
AudioSource: [|hit] [|shots<>];
Player: [main] [Scene|models];
}
```
IV. Setting Values:
🐑 Use `Type::set_..(value)` **ONCE** on (pre-)startup
🦌 The value can be anything implementing its type!
```rust
// Setter Examples
Camera::set_main(commands.spawn(..).id());
AudioSource::set_shots([
assets.load("shot0.ogg"),
assets.load("shot1.ogg"),
assets.load("shot3.ogg"),
]);
Player::set_models([
(5, assets.load("player5.glb")),
(7, assets.load("player7.glb")),
]);
```
V. Getting Values:
🐏 Different getters are provided, depending on the collection type!
```rust
// Single Getter
Camera::main(); // Cloned
Camera::main_ref(); // Static Reference
// Vec Getters
AudioSource::shots(1); // Cloned
AudioSource::shots_ref(1); // Static Reference
AudioSource::shots_vec(); // Static Reference to Vec
// HashMap Getters
Player::models(&5); // Cloned
Player::models_ref(&5); // Static Reference
Player::models_map(); // Static Reference to HashMap
```VI. Mutability:
🐝 You can make any of those mutable by adding a `mut` before the name
🦞 Only use this if you can avoid race conditions
🦧 One idea is to mutate something on state change!
```rust
// Macro Examples
bycell! {
Camera: [mut main] [mut secondary];
AudioSource: [|mut hit] [|mut shots<>];
Player: [mut main] [Scene|mut models];
}
```
---
### License
Licensed under either of Apache License, Version
2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.