Crates.io | micro_games_macros |
lib.rs | micro_games_macros |
version | 0.6.0 |
source | src |
created_at | 2023-10-22 01:36:17.239841 |
updated_at | 2024-09-02 21:44:14.900084 |
description | Utility macros to make it easier to build complex systems with Bevy |
homepage | |
repository | |
max_upload_size | |
id | 1010333 |
size | 67,332 |
A collection of utility macros for building games. While this library should theoretically work with
any version of Bevy that includes the required traits and structs for a given macro, it is worth checking the
version of bevy listed as a dev dependency in Cargo.toml
, as that will be the version tested against.
This works because the library does not directly depend on bevy, but instead just generates fully qualified paths to derives, traits, and structs that will resolve to the version of Bevy used in your downstream project
Current Version Support: 0.6.x -> Bevy 0.14
For executable examples, visit the rustdoc and/or read the doctests in src/lib.rs
Generate a Bevy asset loader for a given asset, supporting JSON files that define a single instance of that asset type, or a list of that asset type. Instances of an asset need to be identifiable, though the property that is used to identify a particular asset is customisable
#[derive(JsonLoader, TypePath, TypeUuid, Serialize, Deserialize, Asset)]
#[loader(
extension = "asset.json", uuid = "00000000-0000-0000-0000-000000000000",
storage = inner_module::SimpleAssetLocator,
asset_name = some_asset_prop, index_name = set_of_assets
)]
#[uuid = "00000000-0000-0000-0000-000000000001"]
pub struct MyAsset {
/// The asset identifier needs to implement [std::fmt::Display]
#[asset_id]
uniq_ident: usize,
}
Generate a set of structs and systems for managed loading in a Bevy game
use bevy::prelude::{Image, Res, Resource};
use micro_games_macros::asset_system;
#[asset_system]
pub struct AssetHandles {
my_asset: Image,
}
pub fn loading_system(mut loader: AssetHandlesLoader) {
loader.load_my_asset("path/to/asset.png", "Asset");
}
pub fn use_asset_system(assets: Res<AssetHandles>) {
let handle = assets.my_asset("Asset");
}
Derive an impl of From<T>
for structs that wrap a single inner type (Tuple and Named Property structs are supported)
use micro_game_macros::FromInner;
#[derive(FromInner)]
struct MyType(usize);
fn example() {
let value = MyType::from(123usize);
}
A simple derive for Kayak UI's "Widget" trait
use micro_game_macros::Widget;
#[derive(Widget)]
struct MyComponent;
// ... Other Kayak Setup ...
Create a system param for checking whether an entity has one of a specified number of tags. The tag finder will also create the tag components, which can use either table or sparse storage
use micro_games_macros::tag_finder;
#[tag_finder]
pub struct TagFinder {
player: Player,
item: Item,
#[sparse]
hover: Hover,
}