Crates.io | bevy_cell |
lib.rs | bevy_cell |
version | 0.13.3 |
source | src |
created_at | 2023-08-31 08:56:37.573218 |
updated_at | 2024-01-01 00:33:58.739274 |
description | Attach Bevy's Handles/Entities statically to Types. |
homepage | |
repository | https://github.com/dekirisu/bevy_cell |
max_upload_size | |
id | 959709 |
size | 116,424 |
🦊 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!
[dependencies]
bevy_cell = "0.13"
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 <KeyType>
after the name: [cameras<usize>]
// Macro Examples
bycell! {
Camera: [main] [secondary];
AudioSource: [|hit] [|shots<>];
Player: [main] [Scene|models<u8>];
}
IV. Setting Values:
🐑 Use Type::set_..(value)
ONCE on (pre-)startup
🦌 The value can be anything implementing its type!
// 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!
// 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!
// Macro Examples
bycell! {
Camera: [mut main] [mut secondary];
AudioSource: [|mut hit] [|mut shots<>];
Player: [mut main] [Scene|mut models<u8>];
}