bevy_cell

Crates.iobevy_cell
lib.rsbevy_cell
version0.13.3
sourcesrc
created_at2023-08-31 08:56:37.573218
updated_at2024-01-01 00:33:58.739274
descriptionAttach Bevy's Handles/Entities statically to Types.
homepage
repositoryhttps://github.com/dekirisu/bevy_cell
max_upload_size
id959709
size116,424
Dekirisu (dekirisu)

documentation

https://docs.rs/bevy_cell

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!

[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>];
}

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.
Commit count: 10

cargo fmt